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. Draw is used to synchronize the draw frame with the Transport's callbacks. See Draw
import { Draw, Transport } from "tone";
Transport.schedule((time) => {
// use the time argument to schedule a callback with Draw
Draw.schedule(() => {
// do drawing or DOM manipulation here
}, time);
}, "+0.5");
Pass in a constructor as the first argument
Pass in a constructor as the first argument
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).
The number of seconds of 1 processing block (128 samples)
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.
The duration in seconds of one sample.
The version number semver
Cancel events scheduled after the given time
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 current time of the Context clock without any lookAhead.
Return the current time of the Context clock plus the lookAhead.
Schedule a function at the given time to be invoked on the nearest animation frame.
Callback is invoked at the given time.
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"
});
Convert the input to a frequency number
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