grimmdude / MidiWriterJS

♬ A JavaScript library which provides an API for programmatically generating and creating expressive multi-track MIDI files and JSON.
MIT License
547 stars 58 forks source link

How to change tempo throughout track #100

Closed jeremygottfried closed 1 year ago

jeremygottfried commented 1 year ago

Is it possible to speed up halfway through the song with setTempo? I can't tell if setTempo sets the tempo for the entire Midi file or if it's possible to do multiple setTempo at different ticks.

grimmdude commented 1 year ago

Hi @jeremygottfried,

I've just released v2.1.2 which exports the TempoEvent class (along with others) so you should now be able to add a TempoEvent to your track wherever you'd like the tempo to change.

track.addEvent(new MidiWriter.TempoEvent({bpm: 200}));

I think it will depend on the software you're using to play the MIDI file whether or not tempo events mid-track are respected. In my testing with GarageBand, it seems to only read the latest tempo event.