Tone.js
    Preparing search index...

    Interface DrawInstance

    Draw is useful for synchronizing visuals and audio events. Callbacks from Tone.Transport or any of the Tone.Event classes always happen before the scheduled time and are not synchronized to the animation frame so they are not good for triggering tightly synchronized visuals and sound. Draw makes it easy to schedule callbacks using the AudioContext time and uses requestAnimationFrame.

    Tone.Transport.schedule((time) => {
    // use the time argument to schedule a callback with Draw
    Tone.Draw.schedule(() => {
    // do drawing or DOM manipulation here
    console.log(time);
    }, time);
    }, "+0.5");
    Tone.Transport.start();
    interface DrawInstance {
        anticipation: number;
        context: BaseContext;
        debug: boolean;
        expiration: number;
        name: string;
        get blockTime(): number;
        get disposed(): boolean;
        get sampleTime(): number;
        cancel(after?: Unit.Time): this;
        dispose(): this;
        get(): ToneWithContextOptions;
        immediate(): number;
        now(): number;
        schedule(callback: () => void, time: Unit.Time): this;
        set(props: RecursivePartial<Options>): this;
        toFrequency(freq: Unit.Frequency): number;
        toSeconds(time?: Unit.Time): number;
        toString(): string;
        toTicks(time?: Unit.Time | TimeClass<number, TimeBaseUnit>): number;
    }

    Hierarchy

    • ToneWithContext<ToneWithContextOptions>
      • DrawInstance
    Index

    Properties

    anticipation: number = 0.008

    The amount of time before the scheduled time that the callback can be invoked. Default is half the time of an animation frame (0.008 seconds).

    context: BaseContext

    The context belonging to the node.

    debug: boolean = false

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

    expiration: number = 0.25

    The duration after which events are not invoked.

    name: string = "Draw"

    The name of the class

    Accessors

    • 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

    Methods

    • Cancel events scheduled after the given time

      Parameters

      • Optionalafter: Unit.Time

        Time after which scheduled events will be removed from the scheduling timeline.

      Returns this

    • Get the object's attributes.

      Returns ToneWithContextOptions

      const osc = new Tone.Oscillator();
      console.log(osc.get());
    • Return the current time of the Context clock without any lookAhead.

      Returns number

      setInterval(() => {
      console.log(Tone.immediate());
      }, 100);
    • Return the current time of the Context clock plus the lookAhead.

      Returns number

      setInterval(() => {
      console.log(Tone.now());
      }, 100);
    • Schedule a function at the given time to be invoked on the nearest animation frame.

      Parameters

      • callback: () => void

        Callback is invoked at the given time.

      • time: Unit.Time

        The time relative to the AudioContext time to invoke the callback.

      Returns this

      Tone.Transport.scheduleRepeat(time => {
      Tone.Draw.schedule(() => console.log(time), time);
      }, 1);
      Tone.Transport.start();
    • Set multiple properties at once with an object.

      Parameters

      • props: RecursivePartial<Options>

      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;
    • Convert the incoming time to seconds. This is calculated against the current TransportInstance 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());