ToneEvent
class Event ↳ extends ToneWithContext<ToneEventOptions<ValueType>>
ToneEvent abstracts away this.context.transport.schedule and provides a schedulable callback for a single or repeatable events along the timeline.
const synth = new Tone.PolySynth().toDestination();
const chordEvent = new Tone.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";Constructor
Section titled “Constructor”new ToneEvent(callback?: ToneEventCallback<ValueType>, value?: ValueType)Parameters
-
callback
ToneEventCallback<ValueType>optionalThe callback to invoke at the time.
-
value
ValueTypeoptionalThe value or values which should be passed to the callback function on invocation.
new ToneEvent(options?: Partial<ToneEventOptions<ValueType>>)Parameters
- options
Partial<ToneEventOptions<ValueType>>optional
Properties
Section titled “Properties”humanize
Section titled “humanize”humanize: boolean | TimeIf 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.
const event = new Tone.ToneEvent(); event.humanize = true;
loop: number | booleanIf 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.
loopEnd
Section titled “loopEnd”loopEnd: TimeThe loopEnd point is the time the event will loop if ToneEvent.loop is true.
playbackRate
Section titled “playbackRate”playbackRate: numberThe playback rate of the event. Defaults to 1.
const note = new Tone.ToneEvent(); note.loop = true; // repeat the note twice as fast note.playbackRate = 2;
probability
Section titled “probability”probability: numberThe probability of the notes being triggered.
progress
Section titled “progress”read-only
progress: numberThe current progress of the loop interval. Returns 0 if the event is not started yet or it is not set to loop.
startOffset
Section titled “startOffset”startOffset: numberThe start from the scheduled start time.
read-only
state: BasicPlaybackStateReturns the playback state of the note, either “started” or “stopped”.
Methods
Section titled “Methods”cancel()
Section titled “cancel()”cancel(time?: Time | TransportTimeClass<number>): thisCancel all scheduled events greater than or equal to the given time
Parameters
-
time
Time | TransportTimeClass<number>optionalThe time after which events will be cancel.
Returns this
start()
Section titled “start()”start(time?: Time | TransportTimeClass<number>): thisStart the note at the given time.
Parameters
-
time
Time | TransportTimeClass<number>optionalWhen the event should start.
Returns this
stop()
Section titled “stop()”stop(time?: Time | TransportTimeClass<number>): thisStop the Event at the given time.
Parameters
-
time
Time | TransportTimeClass<number>optionalWhen the event should stop.
Returns this
getDefaults()
Section titled “getDefaults()”static
getDefaults(): ToneEventOptions<any>Returns all of the default options belonging to the class.
Returns ToneEventOptions<any>
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString()