Using music21 in python, I need to select all the notes that are red so I can change them to black but I cannot seem to find a way to select notes by their color... Does anyone have an idea ?
Using music21 in python, I need to select all the notes that are red so I can change them to black but I cannot seem to find a way to select notes by their color... Does anyone have an idea ?
there is no direct function to search for notes by color. However, you could write a Custom Filter to do what you want:
from music21 import *
def redFilter(n: note.Note):
if n.style.color == 'red':
return True
else:
return False
# assuming sc is your score:
for n in sc[note.GeneralNote].addFilter(redFilter):
n.style.color = 'black'
This uses music21 v7 syntax for calling recurse().getElementsByClass(note.GeneralNote) -- if you're not on v7.3 be sure to upgrade. (if you're more advanced in Python, you could write the parameter to addFilter as a lambda function).