Class ToneEvent<ValueType>

ToneEvent abstracts away this.context.transport.schedule and provides a schedulable callback for a single or repeatable events along the timeline.

Example

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

Type Parameters

  • ValueType = any

Hierarchy (view full)

Constructors

Properties

The callback to invoke.

context: BaseContext

The context belonging to the node.

debug: boolean = false

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

mute: boolean

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

name: string = "ToneEvent"
value: ValueType

The value which is passed to the callback function.

version: string = version

The version number semver

Accessors

  • get blockTime(): number
  • The number of seconds of 1 processing block (128 samples)

    Returns number

    Example

    console.log(Tone.Destination.blockTime);
    
  • get disposed(): 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.

    Returns boolean

  • get humanize(): boolean | Unit.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.

    Returns boolean | Unit.Time

    Example

    const event = new Tone.ToneEvent();
    event.humanize = true;
  • set humanize(variation): void
  • Parameters

    Returns void

  • get 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.

    Returns number | boolean

  • set loop(loop): void
  • Parameters

    • loop: number | boolean

    Returns void

  • get playbackRate(): number
  • The playback rate of the event. Defaults to 1.

    Returns number

    Example

    const note = new Tone.ToneEvent();
    note.loop = true;
    // repeat the note twice as fast
    note.playbackRate = 2;
  • set playbackRate(rate): void
  • Parameters

    • rate: number

    Returns void

  • get 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.

    Returns number

Methods

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

    Returns number

    Example

    setInterval(() => {
    console.log(Tone.immediate());
    }, 100);
  • Return the current time of the Context clock plus the lookAhead.

    Returns number

    Example

    setInterval(() => {
    console.log(Tone.now());
    }, 100);
  • Set multiple properties at once with an object.

    Parameters

    Returns this

    Example

    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;
  • Convert the input to a frequency number

    Parameters

    Returns number

    Example

    const gain = new Tone.Gain();
    console.log(gain.toFrequency("4n"));
  • Convert the incoming time to seconds. This is calculated against the current TransportClass bpm

    Parameters

    Returns number

    Example

    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);
  • Convert the class to a string

    Returns string

    Example

    const osc = new Tone.Oscillator();
    console.log(osc.toString());
  • Convert the input time into ticks

    Parameters

    Returns number

    Example

    const gain = new Tone.Gain();
    console.log(gain.toTicks("4n"));