Control Tone.Sequence in Tone.js
This article provides a quick and practical guide on how to pause,
resume, and stop a running Tone.Sequence in Tone.js. You
will learn how to manipulate individual sequences as well as how to use
the global Tone.Transport to control playback states
seamlessly.
In Tone.js, a Tone.Sequence relies on the global
Tone.Transport to drive its timing. Because of this
relationship, controlling the playback state of a sequence involves a
mix of sequence-specific methods and global Transport controls.
How to Start a Sequence
Before you can pause, resume, or stop a sequence, it must be scheduled and the Transport must be running.
const synth = new Tone.Synth().toDestination();
const notes = ["C4", "E4", "G4", "B4"];
const sequence = new Tone.Sequence((time, note) => {
synth.triggerAttackRelease(note, "8n", time);
}, notes, "4n");
// Schedule the sequence to start immediately
sequence.start(0);
// Start the audio context and the transport
await Tone.start();
Tone.Transport.start();How to Pause and Resume
To pause and resume a sequence while keeping its current playback
position, you must control the global Tone.Transport.
1. Pause Playback
Pausing the Transport freezes the timeline. The sequence will stop playing but will remember its exact position.
// Pauses the sequence and all other scheduled events
Tone.Transport.pause();2. Resume Playback
To resume the sequence from where it was paused, simply start the Transport again.
// Resumes playback from the paused position
Tone.Transport.start();How to Stop a Sequence
Stopping can be done at either the sequence level (stopping just one loop) or the Transport level (stopping all audio).
1. Stop an Individual Sequence
If you want to stop a specific sequence while letting other elements
in your application continue to play, use the .stop()
method on the sequence itself.
// Stops the sequence from playing
sequence.stop();Note: If you call sequence.start() again after
stopping it, the sequence will restart from the beginning of its
loop.
2. Stop the Global Transport
Stopping the Transport stops all scheduled events and resets the
timeline position back to 0.
// Stops all playback and resets the playhead to the beginning
Tone.Transport.stop();Alternative: Pausing an Individual Sequence (Muting)
If you have multiple sequences running but only want to “pause” one
of them without stopping the entire Transport, the cleanest approach is
to use the mute property. This keeps the sequence running
in the background but silences its output.
// "Pause" the individual sequence by muting it
sequence.mute = true;
// "Resume" the individual sequence by unmuting it
sequence.mute = false;