Transport

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. Pass that time value to the object you're scheduling.

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

The transport emits the events: "start", "stop", "pause", and "loop" which are called with the time of that event as the argument. The Transport object belonging to the global Tone.js Context. See Transport


const osc = new Tone.Oscillator().toDestination();
// repeated event every 8th note
Tone.Transport.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.Transport.start();

Hierarchy

Constructor

new Transport (
options?:Partial<TransportOptions >
) => Transport

Properties

blockTime #

readonly Seconds

The number of seconds of 1 processing block (128 samples)


console.log(Tone.Destination.blockTime);

bpm #

TickParam<"bpm" >

The Beats Per Minute of the Transport.


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

context #

BaseContext

The context belonging to the node.

debug #

boolean

Set this debug flag to log all events that happen in this class.

disposed #

readonly boolean

Indicates if the instance was disposed. 'Disposing' an instance means that all of the Web Audio nodes that were created for the instance are disconnected and freed for garbage collection.

emit #

(event,args) => this

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.

off #

(event,callback) => this

on #

(event,callback) => this

once #

(event,callback) => this

position #

BarsBeatsSixteenths | 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.

progress #

readonly NormalRange

The Transport's loop position as a normalized value. Always returns 0 if the transport if loop is not true.

sampleTime #

readonly Seconds

The duration in seconds of one sample.


console.log(Tone.Transport.sampleTime);

seconds #

Seconds

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

state #

readonly PlaybackState

Returns the playback state of the source, either "started", "stopped", or "paused"

swing #

NormalRange

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 #

Ticks

The transports 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.Transport.timeSignature = 4;
// 7/8
Tone.Transport.timeSignature = [7, 8];
// this will be reduced to a single number
Tone.Transport.timeSignature; // returns 3.5

static version #

string

The version number semver

Methods

cancel #

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

cancel (
after= 0:TransportTime

Clear all events after this time.

) => this

clear #

Clear the passed in event id from the timeline

clear (
eventId:number

The id of the event.

) => this

dispose #

Clean up.

dispose ( ) => this

get #

Get the object's attributes.


const osc = new Tone.Oscillator();
console.log(osc.get());
get ( ) => TransportOptions

static getDefaults #

Returns all of the default options belonging to the class.

getDefaults ( ) => TransportOptions

getSecondsAtTime #

Return the elapsed seconds at the given time.

getSecondsAtTime (
time:Time

When to get the elapsed seconds

) => Seconds
The number of elapsed seconds

getTicksAtTime #

Get the clock's ticks at the given time.

getTicksAtTime (
time?:Time

When to get the tick value

) => Ticks
The tick value at the given time.

immediate #

Return the current time of the Context clock without any lookAhead.


setInterval(() => {
	console.log(Tone.immediate());
}, 100);
immediate ( ) => Seconds

nextSubdivision #

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.Transport.start();
Tone.Transport.nextSubdivision("4n");
nextSubdivision (
subdivision?:Time

The subdivision to quantize to

) => Seconds
The context time of the next subdivision.

now #

Return the current time of the Context clock plus the lookAhead.


setInterval(() => {
	console.log(Tone.now());
}, 100);
now ( ) => Seconds

pause #

Pause the transport and all sources synced to the transport.

pause (
time?:Time
) => this

schedule #

Schedule an event along the timeline.


// schedule an event on the 16th measure
Tone.Transport.schedule((time) => {
	// invoked on measure 16
	console.log("measure 16!");
}, "16:0:0");
schedule (
callback:TransportCallback ,

The callback to be invoked at the time.

time:TransportTime | TransportTimeClass

The time to invoke the callback at.

) => number
The id of the event which can be used for canceling the event.

scheduleOnce #

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

scheduleOnce (
callback:TransportCallback ,

The callback to invoke once.

time:TransportTime | TransportTimeClass

The time the callback should be invoked.

) => number
The ID of the scheduled event.

scheduleRepeat #

Schedule a repeated event along the timeline. 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.Transport.scheduleRepeat((time) => {
	osc.start(time).stop(time + 0.1);
}, "8n", "1m");
scheduleRepeat (
callback:TransportCallback ,

The callback to invoke.

interval:Time | TimeClass ,

The duration between successive callbacks. Must be a positive number.

startTime?:TransportTime | TransportTimeClass ,

When along the timeline the events should start being invoked.

duration= Infinity:Time

How long the event should repeat.

) => number
The ID of the scheduled event. Use this to cancel the event.

set #

Set multiple properties at once with an object.


const filter = new Tone.Filter();
// set values using an object
filter.set({
	frequency: 300,
	type: "highpass"
});
set ( ) => this

setLoopPoints #

Set the loop start and stop at the same time.


// loop over the first measure
Tone.Transport.setLoopPoints(0, "1m");
Tone.Transport.loop = true;
setLoopPoints (
startPosition:TransportTime ,
endPosition:TransportTime
) => this

start #

Start the transport and all sources synced to the transport.


// start the transport in one second starting at beginning of the 5th measure.
Tone.Transport.start("+1", "4:0:0");
start (
time?:Time ,

The time when the transport should start.

offset?:TransportTime

The timeline offset to start the transport.

) => this

stop #

Stop the transport and all sources synced to the transport.


Tone.Transport.stop();
stop (
time?:Time

The time when the transport should stop.

) => this

syncSignal #

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

syncSignal (
signal:Signal<any > ,
ratio?:undefined | number

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

) => this

toFrequency #

Convert the input to a frequency number


const gain = new Tone.Gain();
console.log(gain.toFrequency("4n"));
toFrequency (
freq:Frequency
) => Hertz

toggle #

Toggle the current state of the transport. If it is started, it will stop it, otherwise it will start the Transport.

toggle (
time?:Time

The time of the event

) => this

toSeconds #

Convert the incoming time to seconds


const gain = new Tone.Gain();
console.log(gain.toSeconds("4n"));
toSeconds (
time?:Time
) => Seconds

toString #

Convert the class to a string


const osc = new Tone.Oscillator();
console.log(osc.toString());
toString ( ) => string

toTicks #

Convert the input time into ticks


const gain = new Tone.Gain();
console.log(gain.toTicks("4n"));
toTicks (
time?:Time | TimeClass
) => Ticks

unsyncSignal #

Unsyncs a previously synced signal from the transport's control. See Transport.syncSignal.

unsyncSignal (
signal:Signal<any >
) => this