ToneEvent abstracts away this.context.transport.schedule and provides a schedulable callback for a single or repeatable events along the timeline.
import { PolySynth, Sequence, ToneEvent, Transport } from "tone";
const synth = new PolySynth().toDestination();
const chordEvent = new ToneEvent(((time, chord) => {
// the chord as well as the exact time of the event
// are passed in as arguments to the callback function
synth.triggerAttackRelease(chord, 0.5, time);
}), ["D4", "E4", "F4"]);
// start the chord at the beginning of the transport timeline
chordEvent.start();
// loop it every measure for 8 measures
chordEvent.loop = 8;
chordEvent.loopEnd = "1m";
The value or values which should be passed to the callback function on invocation.
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.
If set to true, will apply small random variation to the callback time. If the value is given as a time, it will randomize by that amount.
import { ToneEvent } from "tone";
const event = new ToneEvent();
event.humanize = true;
If the note should loop or not between ToneEvent.loopStart and ToneEvent.loopEnd. If set to true, the event will loop indefinitely, if set to a number greater than 1 it will play a specific number of times, if set to false, 0 or 1, the part will only play once.
The loopEnd point is the time the event will loop if ToneEvent.loop is true.
The playback rate of the note. Defaults to 1.
import { ToneEvent } from "tone";
const note = new ToneEvent();
note.loop = true;
// repeat the note twice as fast
note.playbackRate = 2;
The probability of the notes being triggered.
The current progress of the loop interval. Returns 0 if the event is not started yet or it is not set to loop.
The duration in seconds of one sample.
Returns the playback state of the note, either "started" or "stopped".
The value which is passed to the callback function.
The version number semver
Cancel all scheduled events greater than or equal to 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.
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