Tempo / BPM changes while Transport is stopped?
I am currently adding a tempo track in a sequencer-like app - as a quick test I added 2 tempo change: 160bpm at 2 seconds, and 90bpm at 5 seconds. I expect the tempo to change when the song is playing (Transport state is 'started'), instead I see that the tempo is updated even when the transport is 'stopped').
Tone.Transport.bpm.setValueAtTime(160, 2); Tone.Transport.bpm.setValueAtTime(90, 5);
Using Transport Time ('2:0:0') instead of seconds has the same effect.
The expected result is that the tempo changes to 160 BPM 2 seconds after the START of the Transport / Song and to 90BPM 5 seconds after. In this case the tempo changes when the transport is STOPPED.
Any feedback would be really appreciated - it seems to be quite an important bug in my opinion...
Maybe you could try schedule https://tonejs.github.io/docs/14.7.77/Transport#schedule
The problem is that the tempo is changing based on the status of the Audio context, not based on the status of the Transport.
I slightly modified a code sandbox to showcase the problem: when clicking on the 'Start' button, the audio context is initialised (but the Transport is not started anymore) - or the bug occurs, the time is going up and the tempo changes occur (check the logs):
https://codesandbox.io/p/sandbox/tone-js-transport-bpm-setvalueattime-forked-2pgg82?file=%2Fsrc%2FApp.tsx%3A48%2C1
Any help is more than welcome,
thanks in advance,
There's two different clocks going with Tone.js, one is the Transport clock and one is the Web Audio Clock. The time argument of bpm.setValueAtTime is using the Web Audio clock time. You will have to reschedule it relative to the start time of your Transport when you click Transport.start, or alternatively you could synchronize it as @mikezaby suggests with Transport.schedule to keep it synced to the Transport