Tone.Transport

↳ EXTENDS Tone.Emitter
SINGLETON

Transport for timing musical events. Supports tempo curves and time changes. Unlike browser-based timing (setInterval, requestAnimationFrame) Tone.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.

CONSTRUCTOR

new Tone.Transport ( )

DEFAULTS

{
bpm : 120 ,
swing : 0 ,
swingSubdivision : 8n ,
timeSignature : 4 ,
loopStart : 0 ,
loopEnd : 4m ,
PPQ : 192
}

EXAMPLE

//repeated event every 8th note
Tone.Transport.scheduleRepeat(function(time){
	//do something with the time
}, "8n");
 

EXAMPLE

//schedule an event on the 16th measure
Tone.Transport.schedule(function(time){
	//do something with the time
}, "16:0:0");

Members

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

</>

.bpm

BPM #

The Beats Per Minute of the Transport.

EXAMPLE

Tone.Transport.bpm.value = 80;
//ramp the bpm to 120 over 10 seconds
Tone.Transport.bpm.rampTo(120, 10);
</>

.isTransport

Boolean #

Is an instanceof Tone.Transport

</>

.loop

boolean #

If the transport loops or not.

</>

.loopEnd

Time #

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

</>

.loopStart

Time #

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

</>

.position

BarsBeatsSixteenths #

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

</>

.progress

NormalRange #

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

</>

.seconds

Seconds #

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

</>

.state

Tone.State READONLY #

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

Time #

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

Number or Array #

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

EXAMPLE

//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
</>

Methods

.cancel ( )

#
after

Clear all events after this time.

default: 0
↪ returns Tone.Transport

this

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

</>

.clear ( )

#
eventId

The id of the event.

type: Number
↪ returns Tone.Transport

this

Clear the passed in event id from the timeline

</>

.getSecondsAtTime ( )

#
time

When to get the elapsed seconds

type: Time
↪ returns Seconds

The number of elapsed seconds

Return the elapsed seconds at the given time.

</>

.getTicksAtTime ( )

#
time

When to get the tick value

type: Time
↪ returns Ticks

The tick value at the given time.

Get the clock’s ticks at the given time.

</>

.nextSubdivision ( )

#
subdivision

The subdivision to quantize to

type: Time
↪ returns Number

The context time of the next subdivision.

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.

EXAMPLE

Tone.Transport.start(); //the transport must be started
Tone.Transport.nextSubdivision("4n");
</>

.pause ( )

#
time
type: Time
default: now
↪ returns Tone.Transport

this

Pause the transport and all sources synced to the transport.

</>

.schedule ( )

#
callback

The callback to be invoked at the time.

time

The time to invoke the callback at.

↪ returns Number

The id of the event which can be used for canceling the event.

Schedule an event along the timeline.

EXAMPLE

//trigger the callback when the Transport reaches the desired time
Tone.Transport.schedule(function(time){
	envelope.triggerAttack(time);
}, "128i");
</>

.scheduleOnce ( )

#
callback

The callback to invoke once.

time

The time the callback should be invoked.

↪ returns Number

The ID of the scheduled event.

Schedule an event that will be removed after it is invoked. Note that if the given time is less than the current transport time, the event will be invoked immediately.

</>

.scheduleRepeat ( )

#
callback

The callback to invoke.

interval

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

type: Time
startTime

When along the timeline the events should start being invoked.

optional
duration

How long the event should repeat.

type: Time
default: Infinity
↪ returns Number

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

Schedule a repeated event along the timeline. The event will fire at the interval starting at the startTime and for the specified duration.

EXAMPLE

//a callback invoked every eighth note after the first measure
Tone.Transport.scheduleRepeat(callback, "8n", "1m");
</>

.setLoopPoints ( )

#
startPosition
endPosition
↪ returns Tone.Transport

this

Set the loop start and stop at the same time.

EXAMPLE

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

.start ( )

#
time

The time when the transport should start.

type: Time
default: now
offset

The timeline offset to start the transport.

optional
↪ returns Tone.Transport

this

Start the transport and all sources synced to the transport.

EXAMPLE

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

.stop ( )

#
time

The time when the transport should stop.

type: Time
default: now
↪ returns Tone.Transport

this

Stop the transport and all sources synced to the transport.

EXAMPLE

Tone.Transport.stop();
</>

.syncSignal ( )

#
signal
type: Tone.Signal
ratio

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

type: number
optional
↪ returns Tone.Transport

this

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

</>

.toggle ( )

#
time

The time of the event

type: Time
optional
↪ returns Tone.Transport

this

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

</>

.unsyncSignal ( )

#
signal
type: Tone.Signal
↪ returns Tone.Transport

this

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

</>
inherited from Tone.Emitter

.emit ( )

#
event

The name of the event.

type: String
args...

The arguments to pass to the functions listening.

type: *
↪ returns Tone.Emitter

this

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

</>
inherited from Tone.Emitter

.off ( )

#
event

The event to stop listening to.

type: String
callback

The callback which was bound to the event with Tone.Emitter.on. If no callback is given, all callbacks events are removed.

optional
↪ returns Tone.Emitter

this

Remove the event listener.

</>
inherited from Tone.Emitter

.on ( )

#
event

The name of the event to listen for.

type: String
callback

The callback to invoke when the event is emitted

↪ returns Tone.Emitter

this

Bind a callback to a specific event.

</>
inherited from Tone.Emitter

.once ( )

#
event

The name of the event to listen for.

type: String
callback

The callback to invoke when the event is emitted

↪ returns Tone.Emitter

this

Bind a callback which is only invoked once

</>
docs generated Dec 17 2018