Skip to content

Commit

Permalink
Merge pull request #407 from leleogere/patch-1
Browse files Browse the repository at this point in the history
Sort exported notes by step when same `midi_pitch`
  • Loading branch information
fosfrancesco authored Dec 19, 2024
2 parents 598af13 + 03e062b commit f4930b5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions partitura/io/exportmusicxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@ def linearize_segment_contents(part, start, end, state):

for voice in sorted(notes_by_voice.keys()):
voice_notes = notes_by_voice[voice]
# sort by pitch
# sort by pitch (then step in case of enharmonic notes)
voice_notes.sort(
key=lambda n: n.midi_pitch if hasattr(n, "midi_pitch") else -1, reverse=True
key=lambda n: (n.midi_pitch, n.step) if hasattr(n, "midi_pitch") else (-1, ""),
reverse=True,
)
# grace notes should precede other notes at the same onset
voice_notes.sort(key=lambda n: not isinstance(n, score.GraceNote))
Expand Down

0 comments on commit f4930b5

Please sign in to comment.