New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix xml serialization of fingering articulations #323
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the right track. Needs tests, docs, and some changes in variable names. THANKS!
music21/musicxml/m21ToXml.py
Outdated
@@ -3858,7 +3858,7 @@ def noteheadToXml(self, n): | |||
mxNotehead.set('color', color) | |||
return mxNotehead | |||
|
|||
def noteToNotations(self, n, notFirstNoteOfChord=False, chordParent=None): | |||
def noteToNotations(self, n, pitchNumber, chordParent=None): | |||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a default value for pitchNumber.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and again the name "pitchNumber" could mean too many different things.
music21/musicxml/m21ToXml.py
Outdated
@@ -3099,7 +3099,7 @@ def objectAttachedSpannersToNotations(self, obj, objectSpannerBundle=None): | |||
|
|||
return notations | |||
|
|||
def noteToXml(self, n, addChordTag=False, chordParent=None): | |||
def noteToXml(self, n, pitchNumber=0, chordParent=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pitchNumber is too vague as a variable name -- does it mean C=0, C#=1? is it midi number? it might be "noteIndexInChord" or something like that
music21/musicxml/m21ToXml.py
Outdated
applicableArticulations = [] | ||
fingeringNumber = 0 | ||
for a in chordOrNote.articulations: | ||
if type(a) is Fingering: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not do type(x) checks. use isinstance -- otherwise subclasses fail. But better still is use the music21.base.Music21Object.classes or classSet interface -- it is much faster than isinstance.
music21/musicxml/m21ToXml.py
Outdated
applicableArticulations.append(a) | ||
fingeringNumber += 1 | ||
elif pitchNumber == 0: | ||
applicableArticulations.append(a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if there are more Fingering articulations than pitches? will they be lost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is otherwise really good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes they will be intentionally lost. I added that behavior to doc and test
music21/musicxml/m21ToXml.py
Outdated
|
||
# only apply expressions to notes or the first note of a chord... | ||
if pitchNumber == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still prefer setting up a separate variable that makes more clear what "pitchNumber == 0" means:
if isSingleNoteOrFirstInChord:
even a wordy expression like this is helpful to show what is being tested.
music21/musicxml/m21ToXml.py
Outdated
@@ -3858,7 +3858,7 @@ def noteheadToXml(self, n): | |||
mxNotehead.set('color', color) | |||
return mxNotehead | |||
|
|||
def noteToNotations(self, n, notFirstNoteOfChord=False, chordParent=None): | |||
def noteToNotations(self, n, pitchNumber, chordParent=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need tests to show that this works
Do we need corresponding changes in xmlToM21? I hate to have the capabilities of import become unbalanced from export. |
import already works as intended (the articulations of the chord are collected from every note) |
Unlike other articulations, fingers should not only be applied to the first note of a chord. Fingerings must be applied in orderd, one each to one note respectively. This commit fixes this behavior.
A new inspection was created. |
@mscuthbert I updated the pull request and believe I have now addressed all your review comments. |
there's one unused variable in there, but I can fix that. Congrats and THANK YOU! Approved! |
Unlike other articulations, fingers should not only be applied to the first note of a chord. Fingerings must be applied in orderd, one each to one note respectively. This commit fixes this behavior.