-
Notifications
You must be signed in to change notification settings - Fork 405
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
Work on noteworthy 1 75 binary reader #1247
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.
Thank you for working on this improved converter! The adjusted doctest showing the better results is great.
Let me know if you have any questions or if I misunderstood something (since I don't know this format).
@jacobtylerwalls , thanks for your review, here is a new version improved with your comments |
Great, thanks for the changes. I expect Myke will want to weigh in with his review. At that point please avoid force-pushing, as whoever merges has the option to squash the commits, and in the meantime it prevents people from assessing what changed between reviews. Thanks! |
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 need to review from l. 558 of nw/translate onwards, but looking very good. Some changes requested, but nothing fundamental, and this will move to acceptance as soon as they're made and I'm able to verify that my collections of nwc and nwctxt files still parse.
instruName = self.instrumentName if self.instrumentName else 'NoName' | ||
label = self.label.decode('utf-8') if self.label else instruName | ||
|
||
staffString = '|AddStaff|Name:' + label | ||
dumpObjects.append(staffString) | ||
|
||
staffInstruString = '|StaffInstrument|Name:' + instruName | ||
if instruName in constants.MidiInstruments: | ||
staffInstruString += '|Patch:' | ||
staffInstruString += str(constants.MidiInstruments.index(self.instrumentName)) | ||
|
||
staffInstruString += '|Trans:' + str(self.transposition) |
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.
move all added sections to separate method and test this.
'NoName' doesn't seem right for this -- must it have a name or are these lines able to be omitted?
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.
Indeed, I think falling back to the first midi instru ( Acoustic Grand Piano
) is a better choice.
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.
Also, I'm not sure to see what do you mean by "all added sections" ?
music21/noteworthy/translate.py
Outdated
self.getCurrentVoice().append(n) | ||
|
||
# current voice has shorter duration. If no voices, return current measure | ||
def getCurrentVoice(self): |
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.
needs docs, and return typing.
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.
Especially since it doesn't necessarily return a stream.Voice object as the name implies.
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.
as this is now called for every note, it needs to be optimized as much as possible. I'm seeing most optimized version as:
if self.currentMeasure.isFlat:
# O(1) in most cases.
return self.currentMeasure
# O(n) only if voices already exist.
return min(
self.currentMeasure.getElementsByClass(stream.Voice),
key=lambda v: v.quarterLength
)
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.
Far better, thanks for the suggestion!
music21/noteworthy/translate.py
Outdated
# current voice has shorter duration. If no voices, return current measure | ||
def getCurrentVoice(self): | ||
voice = None | ||
shorter = 999 |
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 should be a float so that typing works for it. And typed as OffsetQL
since it can also be a Fraction. float('inf')
would be the best way of implying that any voice is shorter than this.
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 rename as shortestQL
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.
Resolved by using your implementation
music21/noteworthy/translate.py
Outdated
for item in self.currentMeasure: | ||
if isinstance(item, stream.Voice): |
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.
iterate as for v in self.currentMeasure.getElementsByClass(stream.Voice):
that way you're not setting activeSite etc. for non-matching elements.
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.
Resolved by using your implementation
Hi @mscuthbert , thanks for the review! I'm a bit busy in july but I should come back on this during august. |
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.
FYI still seeing fromDisplayPitch
(nonexistent method) called in latest commit, so unresolving the relevant comment.
* Improve support for many nwc objects: * alterations * grace notes * tempo mark * triplets * text position * chords / multiple pitches * repeat brackets * Readibility: * put constants in their own file * Use exception to print error infos on music21 objects creation * Update documentation * Update tests
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 just came back on it, sorry for the delay. I rebased on master but I created a new commit for the changes related to the review
def timeSig(self): | ||
def timeSignature(self): |
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.
No reason indeed. I'll keep the timeSig
as it is consistent with the nwctxt keyword used below.
music21/noteworthy/translate.py
Outdated
self.getCurrentVoice().append(n) | ||
|
||
# current voice has shorter duration. If no voices, return current measure | ||
def getCurrentVoice(self): |
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.
Far better, thanks for the suggestion!
music21/noteworthy/translate.py
Outdated
for item in self.currentMeasure: | ||
if isinstance(item, stream.Voice): |
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.
Resolved by using your implementation
music21/noteworthy/translate.py
Outdated
# current voice has shorter duration. If no voices, return current measure | ||
def getCurrentVoice(self): | ||
voice = None | ||
shorter = 999 |
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.
Resolved by using your implementation
instruName = self.instrumentName if self.instrumentName else 'NoName' | ||
label = self.label.decode('utf-8') if self.label else instruName | ||
|
||
staffString = '|AddStaff|Name:' + label | ||
dumpObjects.append(staffString) | ||
|
||
staffInstruString = '|StaffInstrument|Name:' + instruName | ||
if instruName in constants.MidiInstruments: | ||
staffInstruString += '|Patch:' | ||
staffInstruString += str(constants.MidiInstruments.index(self.instrumentName)) | ||
|
||
staffInstruString += '|Trans:' + str(self.transposition) |
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.
Also, I'm not sure to see what do you mean by "all added sections" ?
Sorry that I forgot to merge this. Looks like it's good to go |
Obviously I also forgot this one ... Thanks a lot for the integration ! |
Improve support for many nwc objects:
Readibility:
Use exception to print error infos on music21 objects creation
Update documentation
Update tests
refeers to #1123