Schedule events with the Transport
devTone.getTransport() returns the main timekeeper, similar to an arrangement view in a DAW. It can be started, stopped, looped, and adjusted independently of the AudioContext clock.
To ensure sample-accurate timing, always use the time value passed into a Tone.Loop callback to schedule your events.
// create two monophonic synths
const synthA = new Tone.FMSynth().toDestination();
const synthB = new Tone.AMSynth().toDestination();
//play a note every quarter-note
const loopA = new Tone.Loop((time) => {
synthA.triggerAttackRelease("C2", "8n", time);
}, "4n").start(0);
//play another note every off quarter-note, by starting it "8n"
const loopB = new Tone.Loop((time) => {
synthB.triggerAttackRelease("C4", "8n", time);
}, "4n").start("8n");
// all loops start when the Transport is started
Tone.getTransport().start();
// ramp up to 800 bpm over 10 seconds
Tone.getTransport().bpm.rampTo(800, 10);