setTempo method
Sets the tempo.
Implementation
void setTempo(double nextTempo) {
// Update engine start frame to remove excess loops
final loopsElapsed = loopState == LoopState.BeforeLoopEnd
? getLoopsElapsed(_getFramesRendered())
: 0;
engineStartFrame += loopsElapsed * getLoopLengthFrames();
// Update engine start frame to adjust to new tempo
final framesRendered = _getFramesRendered();
final nextFramesRendered = (framesRendered * (tempo / nextTempo)).round();
final framesToAdvance = framesRendered - nextFramesRendered;
engineStartFrame += framesToAdvance;
tempo = nextTempo;
getTracks().forEach((track) {
track.syncBuffer();
});
}