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();
The number of seconds of 1 processing block (128 samples)
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);
The context belonging to the node.
Set this debug flag to log all events that happen in this class.
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.
When the Transport.loop = true, this is the ending position of the loop.
When the Transport.loop = true, this is the starting position of the loop.
The Transport's position in Bars:Beats:Sixteenths. Setting the value will jump to that position right away.
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.
The Transport's loop position as a normalized value. Always returns 0 if the transport if loop is not true.
The duration in seconds of one sample.
The Transport's position in seconds Setting the value will jump to that position right away.
Returns the playback state of the source, either "started", "stopped", or "paused"
The swing value. Between 0-1 where 1 equal to the note + half the 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.
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
The version number semver
Remove scheduled events from the timeline after the given time. Repeated events will be removed if their startTime is after the given time
Clear the passed in event id from the timeline
The id of the event.
Get the object's attributes.
import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.get());
// returns {"type" : "sine", "frequency" : 440, ...etc}
Returns all of the default options belonging to the class.
Return the elapsed seconds at the given time.
Return the current time of the Context clock without any lookAhead.
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");
Return the current time of the Context clock plus the lookAhead.
Pause the transport and all sources synced to the transport.
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 an event that will be removed after it is invoked.
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");
When along the timeline the events should start being invoked.
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 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;
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");
Stop the transport and all sources synced to the transport.
import { Transport } from "tone";
Transport.stop();
Attaches the signal to the tempo control signal so that any changes in the tempo will change the signal in the same ratio.
Optionally pass in the ratio between the two signals.Otherwise it will be computed based on their current values.
Convert the input to a frequency number
Toggle the current state of the transport. If it is started, it will stop it, otherwise it will start the Transport.
Convert the incoming time to seconds
Convert the class to a string
import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.toString());
Convert the input time into ticks
Unsyncs a previously synced signal from the transport's control. See Transport.syncSignal.