midi.translate improvements #1778
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Followup from #1769 gave me an opportunity to find places to improve midi translate. Pinging @oxygen-dioxide since some changes took place since then
Change
getNotesFromEvents()from potentially O(n^2) to O(n) while retaining sort order.Pass encoding to parsing of instrument names in addition to lyrics (renamed "encoding_type" to "encoding" -- missed in prior review)
create TimingNoteEvent which is a typed NamedTuple that keeps track of when a MidiEvent NoteOn started, stopped, and what the NoteOn event was. Replaced the old tuple of tuples.
Faster gathering of Chords (remove potential O(n^2) search).
Remove unused special case for single-note streams.
opFrac many offsets and durations in MIDI for absolutely correct tuplets, etc.
Misc: Update braille.translate SegmentKey to typing.NamedTuple
Misc: Search code for places where we were still casting to float for Python 2 division!
Misc: Add typing to text/Trigram and some layout things
This is part of the non-backwards compatible MIDI.translate guts rewrite discussed on the music21 list.
Coverage % is expected to drop because the amount of code has been reduced a lot.