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


import { Oscillator, Transport } from "tone";
const osc = new Oscillator().toDestination();
// repeated event every 8th note
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
Transport.start();

Hierarchy

Constructor

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

Properties

blockTime #

readonly Seconds

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

bpm #

TickParam<"bpm" >

The Beats Per Minute of the Transport.


import { Oscillator, Transport } from "tone";
const osc = new Oscillator().toDestination();
Transport.bpm.value = 80;
// start/stop the oscillator every quarter note
Transport.scheduleRepeat(time => {
	osc.start(time).stop(time + 0.1);
}, "4n");
Transport.start();
// ramp the bpm to 120 over 10 seconds
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.

name #

string

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.

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.


import { Transport } from "tone";
// common time
Transport.timeSignature = 4;
// 7/8
Transport.timeSignature = [7, 8];
// this will be reduced to a single number
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.


import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.get());
// returns {"type" : "sine", "frequency" : 440, ...etc}
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.

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.


import { Transport } from "tone";
// the transport must be started, otherwise returns 0
Transport.start();
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.

now ( ) => Seconds

pause #

Pause the transport and all sources synced to the transport.

pause (
time?:Time
) => this

schedule #

Schedule an event along the timeline.


import { Transport } from "tone";
// schedule an event on the 16th measure
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.


import { Oscillator, Transport } from "tone";
const osc = new Oscillator().toDestination().start();
// a callback invoked every eighth note after the first measure
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.


import { Filter } from "tone";
const filter = new 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.


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

start #

Start the transport and all sources synced to the transport.


import { Transport } from "tone";
// start the transport in one second starting at beginning of the 5th measure.
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.


import { Transport } from "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

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

toSeconds (
time?:Time
) => Seconds

toString #

Convert the class to a string


import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.toString());
toString ( ) => string

toTicks #

Convert the input time into ticks

toTicks (
time?:Time | TimeClass
) => Ticks

unsyncSignal #

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

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