craffel / pretty-midi

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

Setting or changing Tempo of a Midifile #186

Closed soorejmg closed 3 years ago

soorejmg commented 3 years ago

Hi, Is there an option to set or change the tempo of a midi file available?. Could you let know the way for this. Couldnt see anything other than seeing the estimated tempo in the document. Please advice

Thanks Soorej

craffel commented 3 years ago

You can use adjust_times. There is no other way to change the tempo directly and have the event times update automatically.

soorejmg commented 3 years ago

Hi, Is there an example how to do this?. Could not really understand it from the document. Please provide if you have any. Thanks Soorej

craffel commented 3 years ago

The tutorial provides an example: https://nbviewer.jupyter.org/github/craffel/pretty-midi/blob/master/Tutorial.ipynb#Adjusting-timing

soorejmg commented 3 years ago

Hi, Thanks for this details. While trying to change the tempo, noticed some error in the tempo reading. Not sure whether the understandin is right, when i slow down the music , the tempo is increasing, while it should be a low speed music. For example, my intiital tempo was 162 (assuming bps), Then i slowed down using adjust_time to 1.4 times of initial, but then it shows 214. The tempo should have been a lesser value. Please advice Thanks Soorej

craffel commented 3 years ago

Can you post code?

soorejmg commented 3 years ago

image

tempo_final
Out[241]: 214

tempo
Out[242]: 162

craffel commented 3 years ago

Don't use estimate_tempo; it will produce a (possibly incorrect) estimate and is only intended for files that do not have tempo change events annotated. Use get_tempo_changes.

soorejmg commented 3 years ago

Hi, Thanks Craffel. It works. :)

Thanks Soorej