Skip to content
Tone.js

Instrument

internal class ↳ extends ToneAudioNode<Options>

Base-class for all instruments

new Instrument(options?: Partial<InstrumentOptions>)

Parameters

input: undefined

The instrument only has an output

output: OutputNode

The output nodes. If the object is a sink, it does not have any output and this.output is undefined.

volume: Param<"decibels">

The volume of the output in decibels.

const amSynth = new Tone.AMSynth().toDestination();
amSynth.volume.value = -6;
amSynth.triggerAttackRelease("G#3", 0.2);
dispose(): this

clean up

Returns this this

sync(): this

Sync the instrument to the Transport. All subsequent calls of triggerAttack and triggerRelease will be scheduled along the transport.

const fmSynth = new Tone.FMSynth().toDestination();
fmSynth.volume.value = -6;
fmSynth.sync();
// schedule 3 notes when the transport first starts
fmSynth.triggerAttackRelease("C4", "8n", 0);
fmSynth.triggerAttackRelease("E4", "8n", "8n");
fmSynth.triggerAttackRelease("G4", "8n", "4n");
// start the transport to hear the notes
Tone.Transport.start();

Returns this

triggerAttack(note: Frequency, time?: Time, velocity?: number): this

Start the instrument’s note.

Parameters

  • note Frequency

    the note to trigger

  • time Time optional

    the time to trigger the note

  • velocity number optional

    the velocity to trigger the note (between 0-1)

Returns this

triggerAttackRelease(note: Frequency, duration: Time, time?: Time, velocity?: number): this

Trigger the attack and then the release after the duration.

const synth = new Tone.Synth().toDestination();
// trigger "C4" for the duration of an 8th note
synth.triggerAttackRelease("C4", "8n");

Parameters

  • note Frequency

    The note to trigger.

  • duration Time

    How long the note should be held for before triggering the release. This value must be greater than 0.

  • time Time optional

    When the note should be triggered.

  • velocity number optional

    The velocity the note should be triggered at.

Returns this

triggerRelease(...args: any[]): this

Trigger the release phase of the current note.

Parameters

  • args any[]

Returns this

unsync(): this

Unsync the instrument from the Transport

Returns this

static

getDefaults(): InstrumentOptions

Returns all of the default options belonging to the class.

Returns InstrumentOptions