Open cifkao opened 5 years ago
This is caused by pretty_midi
's parsing logic, which intentionally closes all open notes of a given pitch when it sees a note off for that pitch (all on the same channel, of course):
https://github.com/craffel/pretty-midi/blob/master/pretty_midi/pretty_midi.py#L316
This is an issue with the MIDI format, which you are using as intermediate because you are writing it out and then reading back in. There's no way to disambiguate between ending the first note on or second note on in the MIDI format. pretty_midi
's convention is to end all the notes. Another convention could be LIFO, or FIFO, or something, but pretty_midi
does not implement that at this time. It might be useful to have those behaviors as options when parsing MIDI files.
PrettyMIDI should issue a warning when such overlapping notes are encountered.
I am fine with adding a warning but it may get verbose. It's probably better to just make sure this behavior is well-documented.
(a) fix the problem by writing the notes to different channels automatically
I think this could get ugly quickly if there are many overlapping notes at once.
(b) provide a method to add additional instruments to the PrettyMIDI object and split the overlapping notes between them.
I don't like this solution either because it would break the conceptual model -- for example, I'd have to make sure that I run get_piano_roll
on all of the relevant Instruments and sum them together, or something.
When an instrument has notes overlapping in time and pitch,
PrettyMidi.write
puts all of them in one channel, so some of them get clipped. E.g.:This might be surprising, at least to someone without an advanced knowledge of MIDI.
PrettyMIDI
should issue a warning when such overlapping notes are encountered. Even better, it could either (a) fix the problem by writing the notes to different channels automatically, or (b) provide a method to add additional instruments to thePrettyMIDI
object and split the overlapping notes between them.