Skip to content
Tone.js

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";
new ToneEvent(callback?: ToneEventCallback<ValueType>, value?: ValueType)

Parameters

  • callback ToneEventCallback<ValueType> optional

    The callback to invoke at the time.

  • value ValueType optional

    The value or values which should be passed to the callback function on invocation.

new ToneEvent(options?: Partial<ToneEventOptions<ValueType>>)

Parameters

callback: ToneEventCallback<ValueType>

The callback to invoke.

mute: boolean

If mute is true, the callback won’t be invoked.

read-only

name: string

The name of the class

Default: "ToneEvent"

value: ValueType

The value which is passed to the callback function.

humanize: boolean | Time

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.

const event = new Tone.ToneEvent();
event.humanize = true;
loop: number | boolean

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.

loopEnd: Time

The loopEnd point is the time the event will loop if ToneEvent.loop is true.

loopStart: Time

The time when the loop should start.

playbackRate: number

The 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: number

The probability of the notes being triggered.

read-only

progress: number

The current progress of the loop interval. Returns 0 if the event is not started yet or it is not set to loop.

startOffset: number

The start from the scheduled start time.

read-only

Returns the playback state of the note, either “started” or “stopped”.

cancel(time?: Time | TransportTimeClass<number>): this

Cancel all scheduled events greater than or equal to the given time

Parameters

Returns this

dispose(): this

Dispose and disconnect

Returns this

start(time?: Time | TransportTimeClass<number>): this

Start the note at the given time.

Parameters

Returns this

stop(time?: Time | TransportTimeClass<number>): this

Stop the Event at the given time.

Parameters

Returns this

static

getDefaults(): ToneEventOptions<any>

Returns all of the default options belonging to the class.

Returns ToneEventOptions<any>