craffel / pretty-midi

Utility functions for handling MIDI data in a nice/intuitive way.
MIT License
873 stars 151 forks source link

Pretty_midi returns negatvie notes positions #173

Closed CNelias closed 5 years ago

CNelias commented 5 years ago

I am trying to process a database of MIDI jazz solos, and I noticed that the package pretty_MIDI returns negative onset times for the following MIDI piece : https://jazzomat.hfm-weimar.de/dbformat/synopsis/solo80.html The problem is also appearing with this one : https://jazzomat.hfm-weimar.de/dbformat/synopsis/solo120.html

My code is the following :

In [69]: test = pretty_midi.PrettyMIDI("..\\data\\MIDI\\ChrisPotter_InASentimentalMood_FINAL.mid")
In [70]: test.instruments[0].notes[0:5]
Out[71]: 
[Note(start=-55.439009, end=-56.204049, pitch=53, velocity=82),
 Note(start=-56.371366, end=-57.487040, pitch=55, velocity=80),
 Note(start=-57.647156, end=-57.927275, pitch=56, velocity=84),
 Note(start=-57.977676, end=-59.400897, pitch=57, velocity=84),
 Note(start=-59.503070, end=-60.857834, pitch=60, velocity=93)]

Do you know what is going on ? It could be that the way they generated their MIDI files was non-standard...

craffel commented 5 years ago

This is because mido reports the file as having a ticks_per_beat of -10096:

t = mido.MidiFile("ChrisPotter_InASentimentalMood_FINAL.mid")
print(t.ticks_per_beat)

gives -10096. The MIDI file probably has a corrupt header. You can either fix the header or see if there's a way to make mido more robust to this issue.

CNelias commented 5 years ago

Ok thanks for you reply !

I guess i'll just delete all the files of the database that are corrupt in this manner because there are not that much anyway.

Best,

Corentin

On Wed, Aug 21, 2019 at 5:13 PM Colin Raffel notifications@github.com wrote:

Closed #173 https://github.com/craffel/pretty-midi/issues/173.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/craffel/pretty-midi/issues/173?email_source=notifications&email_token=AIJFCUA3DPZEJEWJPECGAWTQFVLQPA5CNFSM4IOHG2W2YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTFR76QQ#event-2573467458, or mute the thread https://github.com/notifications/unsubscribe-auth/AIJFCUAG6CKDVN5LOWZZL7LQFVLQPANCNFSM4IOHG2WQ .