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

Work on noteworthy 1 75 binary reader #1247

Merged
merged 6 commits into from
Jul 1, 2023

Conversation

nvuaille
Copy link
Contributor

@nvuaille nvuaille commented Mar 6, 2022

  • 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
    • rename some methods (e.g. NWCStaff.parse() -> NWCStaff.parseStaff())
  • Use exception to print error infos on music21 objects creation

  • Update documentation

  • Update tests

refeers to #1123

@jacobtylerwalls jacobtylerwalls linked an issue Mar 6, 2022 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Jul 6, 2022

Coverage Status

Coverage: 93.081% (+0.03%) from 93.053% when pulling 1e8882d on nvuaille:Noteworthy into b474fd4 on cuthbertLab:master.

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a 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).

music21/noteworthy/translate.py Outdated Show resolved Hide resolved
music21/noteworthy/binaryTranslate.py Outdated Show resolved Hide resolved
music21/noteworthy/binaryTranslate.py Outdated Show resolved Hide resolved
music21/noteworthy/binaryTranslate.py Outdated Show resolved Hide resolved
music21/noteworthy/translate.py Outdated Show resolved Hide resolved
music21/noteworthy/translate.py Show resolved Hide resolved
music21/noteworthy/translate.py Outdated Show resolved Hide resolved
music21/noteworthy/translate.py Outdated Show resolved Hide resolved
music21/noteworthy/translate.py Outdated Show resolved Hide resolved
music21/noteworthy/translate.py Outdated Show resolved Hide resolved
@nvuaille
Copy link
Contributor Author

nvuaille commented Jul 9, 2022

@jacobtylerwalls , thanks for your review, here is a new version improved with your comments

@jacobtylerwalls
Copy link
Member

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!

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.

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.

music21/noteworthy/binaryTranslate.py Outdated Show resolved Hide resolved
music21/noteworthy/binaryTranslate.py Show resolved Hide resolved
music21/noteworthy/binaryTranslate.py Outdated Show resolved Hide resolved
Comment on lines 490 to 507
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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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/binaryTranslate.py Outdated Show resolved Hide resolved
self.getCurrentVoice().append(n)

# current voice has shorter duration. If no voices, return current measure
def getCurrentVoice(self):
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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
)

Copy link
Contributor Author

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 Show resolved Hide resolved
# current voice has shorter duration. If no voices, return current measure
def getCurrentVoice(self):
voice = None
shorter = 999
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and rename as shortestQL

Copy link
Contributor Author

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

Comment on lines 514 to 515
for item in self.currentMeasure:
if isinstance(item, stream.Voice):
Copy link
Member

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
@nvuaille
Copy link
Contributor Author

Hi @mscuthbert , thanks for the review!

I'm a bit busy in july but I should come back on this during august.

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a 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.

@mscuthbert mscuthbert closed this Aug 10, 2022
@mscuthbert mscuthbert reopened this Aug 10, 2022
  * 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
Copy link
Contributor Author

@nvuaille nvuaille left a 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

music21/noteworthy/binaryTranslate.py Show resolved Hide resolved
Comment on lines 752 to 820
def timeSig(self):
def timeSignature(self):
Copy link
Contributor Author

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.

self.getCurrentVoice().append(n)

# current voice has shorter duration. If no voices, return current measure
def getCurrentVoice(self):
Copy link
Contributor Author

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!

Comment on lines 514 to 515
for item in self.currentMeasure:
if isinstance(item, stream.Voice):
Copy link
Contributor Author

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

# current voice has shorter duration. If no voices, return current measure
def getCurrentVoice(self):
voice = None
shorter = 999
Copy link
Contributor Author

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

Comment on lines 490 to 507
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)
Copy link
Contributor Author

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" ?

@mscuthbert
Copy link
Member

Sorry that I forgot to merge this. Looks like it's good to go

@mscuthbert mscuthbert dismissed jacobtylerwalls’s stale review July 1, 2023 09:04

Changes made over force push

@mscuthbert mscuthbert merged commit 8be7736 into cuthbertLab:master Jul 1, 2023
@nvuaille
Copy link
Contributor Author

nvuaille commented Jul 2, 2023

Obviously I also forgot this one ... Thanks a lot for the integration !

@nvuaille nvuaille deleted the Noteworthy branch July 2, 2023 20:38
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.

Improving Noteworthy converter support
4 participants