Documentation
    Preparing search index...

    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.

    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();

    Hierarchy (View Summary)

    Implements

    Index
    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);
    context: BaseContext

    The context belonging to the node.

    debug: boolean

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

    emit: (event: any, ...args: any[]) => this

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

    Type Declaration

      • (event: any, ...args: any[]): this
      • Parameters

        • event: any

          The name of the event.

        • ...args: any[]

          The arguments to pass to the functions listening.

        Returns this

    name: string

    The name of the class

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

    Remove the event listener.

    Type Declaration

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

        • event: TransportEventNames

          The event to stop listening to.

        • Optionalcallback: (...args: any[]) => void

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

        Returns this

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

    Bind a callback to a specific event.

    Type Declaration

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

        • event: TransportEventNames

          The name of the event to listen for.

        • callback: (...args: any[]) => void

          The callback to invoke when the event is emitted

        Returns this

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

    Bind a callback which is only invoked once

    Type Declaration

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

        • event: TransportEventNames

          The name of the event to listen for.

        • callback: (...args: any[]) => void

          The callback to invoke when the event is emitted

        Returns this

    version: string

    The version number semver

    • get blockTime(): number

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

      Returns number

      console.log(Tone.Destination.blockTime);
      
    • get disposed(): 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.

      Returns boolean

    • get loop(): boolean

      If the transport loops or not.

      Returns boolean

    • set loop(loop: boolean): void

      Parameters

      • loop: boolean

      Returns void

    • get loopEnd(): Time

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

      Returns Time

    • set loopEnd(endPosition: Time): void

      Parameters

      Returns void

    • get loopStart(): Time

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

      Returns Time

    • set loopStart(startPosition: Time): void

      Parameters

      • startPosition: Time

      Returns void

    • get position(): Time

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

      Returns Time

    • set position(progress: Time): void

      Parameters

      Returns void

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

      Returns number

    • set PPQ(ppq: number): void

      Parameters

      • ppq: number

      Returns void

    • get progress(): number

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

      Returns number

    • get sampleTime(): number

      The duration in seconds of one sample.

      Returns number

    • get seconds(): number

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

      Returns number

    • set seconds(s: number): void

      Parameters

      • s: number

      Returns void

    • get state(): PlaybackState

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

      Returns PlaybackState

    • get swing(): number

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

      Returns number

    • set swing(amount: number): void

      Parameters

      • amount: number

      Returns void

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

      Returns Subdivision

    • set swingSubdivision(subdivision: Subdivision): void

      Parameters

      Returns void

    • get ticks(): number

      The Transport's current tick position.

      Returns number

    • set ticks(t: number): void

      Parameters

      • t: number

      Returns void

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

      Returns TimeSignature

      // 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
    • set timeSignature(timeSig: TimeSignature): void

      Parameters

      Returns void

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

      Parameters

      • Optionalafter: Time

        Clear all events after this time.

      Returns this

    • Clear the passed in event id from the timeline

      Parameters

      • eventId: number

        The id of the event.

      Returns this

    • Clean up.

      Returns this

    • Get the object's attributes.

      Returns TransportOptions

      const osc = new Tone.Oscillator();
      console.log(osc.get());
    • Return the elapsed seconds at the given time.

      Parameters

      • time: Time

        When to get the elapsed seconds

      Returns number

      The number of elapsed seconds

    • Get the clock's ticks at the given time.

      Parameters

      • Optionaltime: Time

        When to get the tick value

      Returns number

      The tick value at the given time.

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

      Returns number

      setInterval(() => {
      console.log(Tone.immediate());
      }, 100);
    • Prints the outputs to the console log for debugging purposes. Prints the contents only if either the object has a property called debug set to true, or a variable called TONE_DEBUG_CLASS is set to the name of the class.

      Parameters

      • ...args: any[]

      Returns void

      const osc = new Tone.Oscillator();
      // prints all logs originating from this oscillator
      osc.debug = true;
      // calls to start/stop will print in the console
      osc.start();
    • 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.

      Parameters

      • Optionalsubdivision: Time

        The subdivision to quantize to

      Returns number

      The context time of the next subdivision.

      // the transport must be started, otherwise returns 0
      Tone.getTransport().start();
      Tone.getTransport().nextSubdivision("4n");
    • Return the current time of the Context clock plus the lookAhead.

      Returns number

      setInterval(() => {
      console.log(Tone.now());
      }, 100);
    • Pause the transport and all sources synced to the transport.

      Parameters

      Returns this

    • Schedule an event along the timeline.

      Parameters

      Returns number

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

      // schedule an event on the 16th measure
      Tone.getTransport().schedule((time) => {
      // invoked on measure 16
      console.log("measure 16!");
      }, "16:0:0");
    • Schedule an event that will be removed after it is invoked.

      Parameters

      Returns number

      The ID of the scheduled event.

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

      Parameters

      • callback: TransportCallback

        The callback to invoke.

      • interval: Time | TimeClass<number, TimeBaseUnit>

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

      • OptionalstartTime: Time | TransportTimeClass<number>

        When along the timeline the events should start being invoked.

      • Optionalduration: Time

        How long the event should repeat.

      Returns number

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

      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");
    • Set multiple properties at once with an object.

      Parameters

      Returns this

      const filter = new Tone.Filter().toDestination();
      // set values using an object
      filter.set({
      frequency: "C6",
      type: "highpass"
      });
      const player = new Tone.Player("https://tonejs.github.io/audio/berklee/Analogsynth_octaves_highmid.mp3").connect(filter);
      player.autostart = true;
    • Set the loop start and stop at the same time.

      Parameters

      Returns this

      // loop over the first measure
      Tone.getTransport().setLoopPoints(0, "1m");
      Tone.getTransport().loop = true;
    • Start the transport and all sources synced to the transport.

      Parameters

      • Optionaltime: Time

        The time when the transport should start.

      • Optionaloffset: Time

        The timeline offset to start the transport.

      Returns this

      // start the transport in one second starting at beginning of the 5th measure.
      Tone.getTransport().start("+1", "4:0:0");
    • Stop the transport and all sources synced to the transport.

      Parameters

      • Optionaltime: Time

        The time when the transport should stop.

      Returns this

      Tone.getTransport().stop();
      
    • 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>
      • Optionalratio: number

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

      Returns this

    • Convert the input to a frequency number

      Parameters

      Returns number

      const gain = new Tone.Gain();
      console.log(gain.toFrequency("4n"));
    • Toggle the current state of the transport. If it is started, it will stop it, otherwise it will start the Transport.

      Parameters

      • Optionaltime: Time

        The time of the event

      Returns this

    • Convert the incoming time to seconds. This is calculated against the current TransportClass bpm

      Parameters

      Returns number

      const gain = new Tone.Gain();
      setInterval(() => console.log(gain.toSeconds("4n")), 100);
      // ramp the tempo to 60 bpm over 30 seconds
      Tone.getTransport().bpm.rampTo(60, 30);
    • Convert the class to a string

      Returns string

      const osc = new Tone.Oscillator();
      console.log(osc.toString());
    • Convert the input time into ticks

      Parameters

      Returns number

      const gain = new Tone.Gain();
      console.log(gain.toTicks("4n"));
    • Unsyncs a previously synced signal from the transport's control.

      Parameters

      Returns this