-
Notifications
You must be signed in to change notification settings - Fork 151
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
Reading duplicate note-off events results in zero-duration notes #131
Comments
In particular when there are two adjacent notes and at the same tick there's first note-on and then note-off, the library incorrectly closes both notes, even though the second note should be still open. Such a MIDI is probably a bit malformed, but the library should not fail on that if it can resolve the situation. Due to this bug the library incorrectly produces zero-duration events and some long open notes. The solution is to keep the note-on event in the list of open notes if it's at the same tick as the note-off event and we're closing some previous notes. Note that we changed the format of time within values of the last_note_on dict - from real time to integer tick. This is to avoid floating point comparison when we have the original integer values.
In particular when there are two adjacent notes and at the same tick there's first note-on and then note-off, the library incorrectly closes both notes, even though the second note should be still open. Such a MIDI is probably a bit malformed, but the library should not fail on that if it can resolve the situation. Due to this bug the library incorrectly produces zero-duration events and some long open notes. The solution is to keep the note-on event in the list of open notes if it's at the same tick as the note-off event and we're closing some previous notes. Note that we changed the format of time within values of the last_note_on dict - from real time to integer tick. This is to avoid floating point comparison when we have the original integer values.
Thanks for debugging this.
While I can understand why we are creating zero-duration notes, and why this is bad, I don't understand where writing zero-duration notes results in spurious long-running notes. |
When the input MIDI file contains note-off events for already inactive notes (with note-off events given before) pretty-midi still creates note events with zero duration. Writing such notes then results in spurious long-running notes that were not present originally.
Note that in this case there were two overlapping notes: note-on, note-on, note-off, note-off.
Example: bach-js_kunst_der_fuge_01_(c)unknown[2].mid (source: kunstderfuge.com)
If we zoom in the the start of the track 1 (first voice). Original looks like:
And written one:
Mido
print_track()
- original:Mido
print_track()
- written:If we extract the input sequence of two notes of pitch 72:
it seems that the meaning was as follows (two consequent notes of length 192 and 48):
The only problem was that the note-off event preceded the note-on event, even though they occurred at the same time. Instead we created one note of duration 192, then one zero-duration note and one long note that was closed after encountering next note-off for that pitch.
We should fix two bugs here:
The text was updated successfully, but these errors were encountered: