Skip to content
Tone.js

DrawClass

internal class Core ↳ extends ToneWithContext<ToneWithContextOptions>

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();
anticipation: number

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

Default: 0.008

expiration: number

The duration after which events are not invoked.

Default: 0.25

read-only

name: string

The name of the class

Default: "Draw"

cancel(after?: Time): this

Cancel events scheduled after the given time

Parameters

  • after Time optional

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

Returns this

dispose(): this

disconnect and dispose.

Returns this

schedule(callback: () => void, time: Time): this

Schedule a function at the given time to be invoked on the nearest animation frame.

Tone.Transport.scheduleRepeat(time => {
	Tone.Draw.schedule(() => console.log(time), time);
}, 1);
Tone.Transport.start();

Parameters

  • callback () => void

    Callback is invoked at the given time.

  • time Time

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

Returns this