Skip to content
Tone.js

TransportInstance

interface Core ↳ extends ToneWithContext<TransportOptions>

Transport for timing musical events.

Supports tempo curves and time changes.

Unlike browser-based timing (setInterval, requestAnimationFrame), Transport timing events pass in the exact time of the scheduled event in the argument of the callback function.

A single transport is created for you when the library is initialized.

The transport emits “start”, “stop”, “pause”, and “loop” events.

const osc = new Tone.Oscillator().toDestination();
// Repeated event every 8th note.
Tone.getTransport().scheduleRepeat((time) => {
	// Use the callback time to schedule events.
	osc.start(time).stop(time + 0.1);
}, "8n");
// Transport must be started before it starts invoking events.
Tone.getTransport().start();
bpm: TickParam<"bpm">

The Beats Per Minute of the Transport.

const osc = new Tone.Oscillator().toDestination();
Tone.getTransport().bpm.value = 80;
// start/stop the oscillator every quarter note
Tone.getTransport().scheduleRepeat(time => {
	osc.start(time).stop(time + 0.1);
}, "4n");
Tone.getTransport().start();
// ramp the bpm to 120 over 10 seconds
Tone.getTransport().bpm.rampTo(120, 10);
emit: (event: any, ...args: any[]) => this

Invoke all of the callbacks bound to the event with any arguments passed in.

read-only

name: string

The name of the class

Default: "Transport"

off: (event: TransportEventNames, callback?: (...args: any[]) => void) => this

Remove the event listener.

on: (event: TransportEventNames, callback: (...args: any[]) => void) => this

Bind a callback to a specific event.

once: (event: TransportEventNames, callback: (...args: any[]) => void) => this

Bind a callback which is only invoked once

loop: boolean

If the transport loops or not.

loopEnd: Time

When the Transport.loop = true, this is the ending position of the loop.

loopStart: Time

When the Transport.loop = true, this is the starting position of the loop.

position: Time

The Transport’s position in Bars:Beats:Sixteenths. Setting the value will jump to that position right away.

PPQ: number

Pulses Per Quarter note. This is the smallest resolution the Transport timing supports. This should be set once on initialization and not set again. Changing this value after other objects have been created can cause problems.

read-only

progress: number

The Transport’s loop position as a normalized value. Always returns 0 if the Transport.loop = false.

seconds: number

The Transport’s position in seconds. Setting the value will jump to that position right away.

read-only

The playback state of the transport, either “started”, “stopped”, or “paused”.

swing: number

The swing value. Between 0-1 where 1 equal to the note + half the subdivision.

swingSubdivision: Subdivision

Set the subdivision which the swing will be applied to. The default value is an 8th note. Value must be less than a quarter note.

ticks: number

The Transport’s current tick position.

timeSignature: TimeSignature

The time signature as just the numerator over 4. For example 4/4 would be just 4 and 6/8 would be 3.

// common time
Tone.getTransport().timeSignature = 4;
// 7/8
Tone.getTransport().timeSignature = [7, 8];
// this will be reduced to a single number
Tone.getTransport().timeSignature; // returns 3.5
cancel(after?: Time): this

Remove scheduled events from the timeline after the given time. Repeated events will be removed if their startTime is after the given time

Parameters

  • after Time optional default 0

    Clear all events after this time.

Returns this

clear(eventId: number): this

Clear the passed in event id from the timeline

Parameters

  • eventId number

    The id of the event.

Returns this

dispose(): this

Clean up.

Returns this

getSecondsAtTime(time: Time): number

Return the elapsed seconds at the given time.

Parameters

  • time Time

    When to get the elapsed seconds

Returns number The number of elapsed seconds

getTicksAtTime(time?: Time): number

Get the clock’s ticks at the given time.

Parameters

  • time Time optional

    When to get the tick value

Returns number The tick value at the given time.

nextSubdivision(subdivision?: Time): number

Returns the time aligned to the next subdivision of the Transport. If the Transport is not started, it will return 0. Note: this will not work precisely during tempo ramps.

// the transport must be started, otherwise returns 0
Tone.getTransport().start();
Tone.getTransport().nextSubdivision("4n");

Parameters

  • subdivision Time optional

    The subdivision to quantize to

Returns number The context time of the next subdivision.

pause(time?: Time): this

Pause the transport and all sources synced to the transport.

Parameters

  • time Time optional

Returns this

schedule(callback: TransportCallback, time: Time | TransportTimeClass<number>): number

Schedule an event to be invoked at a specific time.

// Schedule an event on the 16th measure.
Tone.getTransport().schedule((time) => {
	// Invoked on measure 16.
	console.log("measure 16!");
}, "16:0:0");

Parameters

Returns number The ID of the event, which can be used to cancel the event.

scheduleOnce(callback: TransportCallback, time: Time | TransportTimeClass<number>): number

Schedule an event that will be removed after it is invoked.

Parameters

Returns number The ID of the scheduled event.

scheduleRepeat(callback: TransportCallback, interval: Time | TimeClass<number, TimeBaseUnit>, startTime?: Time | TransportTimeClass<number>, duration?: Time): number

Schedule a repeated event.

The event will fire at the interval starting at the startTime and for the specified duration.

const osc = new Tone.Oscillator().toDestination().start();
// A callback invoked every eighth note after the first measure.
Tone.getTransport().scheduleRepeat((time) => {
	osc.start(time).stop(time + 0.1);
}, "8n", "1m");

Parameters

Returns number The ID of the scheduled event. Use this to cancel the event.

setLoopPoints(startPosition: Time, endPosition: Time): this

Set the loop start and stop at the same time.

// loop over the first measure
Tone.getTransport().setLoopPoints(0, "1m");
Tone.getTransport().loop = true;

Parameters

Returns this

setSecondsAtTime(seconds: number, time: Time): this

Set the Transport’s seconds value at the given time.

Parameters

  • seconds number

    The seconds value to set

  • time Time

    The Context time at which to set the seconds value

Returns this

setTicksAtTime(ticks: number, time: Time): this

Set the Transport’s ticks value at the given time

Parameters

  • ticks number

    The tick value to set

  • time Time

    The Context time at which to set the seconds value

Returns this

start(time?: Time, offset?: Time): this

Start the transport and all sources synced to the transport.

// Start the transport in one second, beginning at the start of the 5th measure.
Tone.getTransport().start("+1", "4:0:0");

Parameters

  • time Time optional

    The time when the transport should start.

  • offset Time optional

    The timeline offset to start the transport from.

Returns this

stop(time?: Time): this

Stop the transport and all sources synced to the transport.

Tone.getTransport().stop();

Parameters

  • time Time optional

    The time when the transport should stop.

Returns this

syncSignal(signal: Signal<any>, ratio?: number): this

Attaches the signal to the tempo control signal so that any changes in the tempo will change the signal in the same ratio.

Parameters

  • signal Signal<any>

  • ratio number optional

    Optionally pass in the ratio between the two signals. Otherwise it will be computed based on their current values.

Returns this

toggle(time?: Time): this

Toggle the current state of the transport.

If it is started, it will stop it. If it is stopped, it will start it.

Parameters

  • time Time optional

    The time of the event.

Returns this

unsyncSignal(signal: Signal<any>): this

Unsyncs a previously synced signal from the transport’s control.

See also: syncSignal.

Parameters

Returns this