Skip to content
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

Merged
merged 1 commit into from Aug 22, 2018
Merged

Fix xml serialization of fingering articulations #323

merged 1 commit into from Aug 22, 2018

Conversation

hofst
Copy link
Contributor

@hofst hofst commented Aug 21, 2018

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.

@coveralls
Copy link

coveralls commented Aug 21, 2018

Coverage Status

Coverage increased (+0.001%) to 90.02% when pulling a5b7455 on hofst:master into ca4d4e1 on cuthbertLab:master.

Copy link
Member

@mscuthbert mscuthbert left a 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!

@@ -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):
'''
Copy link
Member

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.

Copy link
Member

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.

@@ -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):
Copy link
Member

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

applicableArticulations = []
fingeringNumber = 0
for a in chordOrNote.articulations:
if type(a) is Fingering:
Copy link
Member

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.

applicableArticulations.append(a)
fingeringNumber += 1
elif pitchNumber == 0:
applicableArticulations.append(a)
Copy link
Member

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?

Copy link
Member

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!

Copy link
Contributor Author

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


# only apply expressions to notes or the first note of a chord...
if pitchNumber == 0:
Copy link
Member

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.

@@ -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):
Copy link
Member

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

@mscuthbert
Copy link
Member

Do we need corresponding changes in xmlToM21? I hate to have the capabilities of import become unbalanced from export.

@hofst
Copy link
Contributor Author

hofst commented Aug 22, 2018

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.
@scrutinizer-notifier
Copy link

A new inspection was created.

@hofst
Copy link
Contributor Author

hofst commented Aug 22, 2018

@mscuthbert I updated the pull request and believe I have now addressed all your review comments.

@mscuthbert mscuthbert merged commit b4c9467 into cuthbertLab:master Aug 22, 2018
@mscuthbert
Copy link
Member

there's one unused variable in there, but I can fix that. Congrats and THANK YOU! Approved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants