craffel / pretty-midi

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

Wrong tempo #209

Closed page200 closed 2 years ago

page200 commented 2 years ago

This video is a visualization of this MIDI file (linked in the video description).

Both according to the video and to my MIDI players, the duration of the file is 257 seconds. Therefore, pretty_midi.PrettyMIDI('Yann Tiersen - Sur Le Fil (Clean version).mid').get_piano_roll(fs=1).shape[1] should yield 257 (due to fs=1). However, it yields 186 (the piano roll is about 1.4 times too fast) and the following warning:

pretty_midi\pretty_midi.py:97: RuntimeWarning: Tempo, Key or Time signature change events found on non-zero tracks. This is not a valid type 0 or type 1 MIDI file. Tempo, Key or Time Signature may be wrong.

I recall similar problems with other MIDI files.

What software can I use to inspect and fix the validity of the MIDI file? How do normal media players recognize the correct tempo, and might pretty_midi use the same recognition method?

craffel commented 2 years ago

The error message means that there are timing events on some track other than 0. You should edit the MIDI file to put those events on track 0. You can do this with mido, for example. Most media players are more forgiving than pretty_midi and obey timing events on any track.