ToneEvent < ValueType >

  • ValueType: [object Object]

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";

Hierarchy

Constructor

new ToneEvent (
callback?:ToneEventCallback<ValueType > ,

The callback to invoke at the time.

value?:ValueType

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

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

Properties

blockTime #

readonly Seconds

The number of seconds of 1 processing block (128 samples)


console.log(Tone.Destination.blockTime);

callback #

ToneEventCallback<ValueType >

The callback to invoke.

context #

BaseContext

The context belonging to the node.

debug #

boolean

Set this debug flag to log all events that happen in this class.

disposed #

readonly boolean

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.

humanize #

Time | boolean

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 #

boolean | number

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.

mute #

boolean

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

name #

string

playbackRate #

Positive

The playback rate of the note. Defaults to 1.


const note = new Tone.ToneEvent();
note.loop = true;
// repeat the note twice as fast
note.playbackRate = 2;

probability #

NormalRange

The probability of the notes being triggered.

progress #

readonly NormalRange

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

sampleTime #

readonly Seconds

The duration in seconds of one sample.


console.log(Tone.Transport.sampleTime);

startOffset #

Ticks

The start from the scheduled start time.

state #

readonly BasicPlaybackState

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

value #

ValueType

The value which is passed to the callback function.

static version #

string

The version number semver

Methods

cancel #

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

cancel (
time?:TransportTime | TransportTimeClass

The time after which events will be cancel.

) => this

dispose #

disconnect and dispose.

dispose ( ) => this

get #

Get the object's attributes.


const osc = new Tone.Oscillator();
console.log(osc.get());
get ( ) => ToneEventOptions<ValueType >

static getDefaults #

Returns all of the default options belonging to the class.

getDefaults ( ) => ToneEventOptions<any >

immediate #

Return the current time of the Context clock without any lookAhead.


setInterval(() => {
	console.log(Tone.immediate());
}, 100);
immediate ( ) => Seconds

now #

Return the current time of the Context clock plus the lookAhead.


setInterval(() => {
	console.log(Tone.now());
}, 100);
now ( ) => Seconds

set #

Set multiple properties at once with an object.


const filter = new Tone.Filter().toDestination();
// set values using an object
filter.set({
	frequency: "C6",
	type: "highpass"
});
const player = new Tone.Player("https://tonejs.github.io/audio/berklee/Analogsynth_octaves_highmid.mp3").connect(filter);
player.autostart = true;
set (
props:RecursivePartial<ToneEventOptions<ValueType > >
) => this

start #

Start the note at the given time.

start (
time?:TransportTime | TransportTimeClass

When the event should start.

) => this

stop #

Stop the Event at the given time.

stop (
time?:TransportTime | TransportTimeClass

When the event should stop.

) => this

toFrequency #

Convert the input to a frequency number


const gain = new Tone.Gain();
console.log(gain.toFrequency("4n"));
toFrequency (
freq:Frequency
) => Hertz

toSeconds #

Convert the incoming time to seconds. This is calculated against the current Tone.Transport bpm


const gain = new Tone.Gain();
setInterval(() => console.log(gain.toSeconds("4n")), 100);
// ramp the tempo to 60 bpm over 30 seconds
Tone.getTransport().bpm.rampTo(60, 30);
toSeconds (
time?:Time
) => Seconds

toString #

Convert the class to a string


const osc = new Tone.Oscillator();
console.log(osc.toString());
toString ( ) => string

toTicks #

Convert the input time into ticks


const gain = new Tone.Gain();
console.log(gain.toTicks("4n"));
toTicks (
time?:Time | TimeClass
) => Ticks