Changing tempo

Dec 15, 2016 at 8:54 PM
Hey all,

Has anyone had luck changing tempo programmatically with any of these frameworks?

I've tried this with several variations of UnitySynth, CSUnitySynth, CSharpSynth etc and the tempo change doesn't seem to have an impact. I suspect I'm calling something incorrectly. Or perhaps it hasn't come up as a use case yet.

Here's what I have so far:
            float tempo = 20;
            MidiEvent tempoChange = new MidiEvent();
            tempoChange.midiMetaEvent = MidiHelper.MidiMetaEvent.Tempo;
            tempoChange.Parameters[0] = MidiHelper.MicroSecondsPerMinute / tempo;
            tempoChange.Parameters[4] = 3; // magic MIDI format requirement, seems to always be present for tempo events
            midiSequencer.ProcessMidiEvent(tempoChange);
Stepping through the code that is downstream of midiSequencer.ProcessMidiEvent(), the BeatsPerMinute property in the MidiFile instance gets called, but that doesn't seem to get used once playback has begun.

So MidiSequencer.DeltaTimetoSamples() uses _MidiFile.BeatsPerMinute, but only in its LoadMidi() call.

I'm thinking that in response to tempo changes the sequencing data's timing needs to get updated for all remaining events. Perhaps the remaining events in MidiTrack.MidiEvents should get updated.