DrawInstance
interface 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();Properties
Section titled “Properties”anticipation
Section titled “anticipation”anticipation: numberThe 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
Section titled “expiration”expiration: numberThe duration after which events are not invoked.
Default: 0.25
Methods
Section titled “Methods”cancel()
Section titled “cancel()”cancel(after?: Time): thisCancel events scheduled after the given time
Parameters
-
after
TimeoptionalTime after which scheduled events will be removed from the scheduling timeline.
Returns this
schedule()
Section titled “schedule()”schedule(callback: () => void, time: Time): thisSchedule 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
() => voidCallback is invoked at the given time.
-
time
TimeThe time relative to the AudioContext time to invoke the callback.
Returns this
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, disposed, toString()