Skip to content
Tone.js

Sampler

class Instrument ↳ extends Instrument<SamplerOptions>

Pass in an object which maps the note’s pitch or midi value to the url, then you can trigger the attack and release of that note like other instruments. By automatically repitching the samples, it is possible to play pitches which were not explicitly included which can save loading time.

For sample or buffer playback where repitching is not necessary, use Player.

const sampler = new Tone.Sampler({
	urls: {
		A1: "A1.mp3",
		A2: "A2.mp3",
	},
	baseUrl: "https://tonejs.github.io/audio/casio/",
	onload: () => {
		sampler.triggerAttackRelease(["C1", "E1", "G1", "B1"], 0.5);
	}
}).toDestination();
new Sampler(samples?: SamplesMap, onload?: () => void, baseUrl?: string)

Parameters

  • samples SamplesMap optional

    An object of samples mapping either Midi Note Numbers or Scientific Pitch Notation to the url of that sample.

  • onload () => void optional

    The callback to invoke when all of the samples are loaded.

  • baseUrl string optional

    The root URL of all of the samples, which is prepended to all the URLs.

new Sampler(samples?: SamplesMap, options?: Partial<Omit<SamplerOptions, "urls">>)

Parameters

  • samples SamplesMap optional

    An object of samples mapping either Midi Note Numbers or Scientific Pitch Notation to the url of that sample.

  • options Partial<Omit<SamplerOptions, "urls">> optional

    The remaining options associated with the sampler

new Sampler(options?: Partial<SamplerOptions>)

Parameters

attack: Time

The envelope applied to the beginning of the sample.

Range: 0 to 1

The shape of the attack/release curve. Either “linear” or “exponential”

↳ inherited from Instrument

input: undefined

The instrument only has an output

read-only

name: string

The name of the class

Default: "Sampler"

↳ inherited from Instrument

output: OutputNode

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

release: Time

The envelope applied to the end of the envelope.

Range: 0 to 1

↳ inherited from Instrument

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

read-only

loaded: boolean

If the buffers are loaded or not

loop: boolean

If the buffers should loop once they are over.

const sampler = new Tone.Sampler({
     urls: {
          A4: "https://tonejs.github.io/audio/berklee/femalevoice_aa_A4.mp3",
     },
}).toDestination();
sampler.loop = true;
loopEnd: Time

If loop is true, the loop will end at this position.

loopStart: Time

If loop is true, the loop will start at this position.

add(note: 0 | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 3 | 5 | 6 | 7 | 9 | 10 | 11 | "C0" | "C1" | "C2" | "C4" | "C8" | "C-4" | "C3" | "C-3" | "C-2" | "C-1" | "C5" | "C6" | "C7" | "C9" | "C10" | "C11" | "Cbb0" | "Cbb1" | "Cbb2" | "Cbb4" | "Cbb8" | "Cbb-4" | "Cbb3" | "Cbb-3" | "Cbb-2" | "Cbb-1" | "Cbb5" | "Cbb6" | "Cbb7" | "Cbb9" | "Cbb10" | "Cbb11" | "Cb0" | "Cb1" | "Cb2" | "Cb4" | "Cb8" | "Cb-4" | "Cb3" | "Cb-3" | "Cb-2" | "Cb-1" | "Cb5" | "Cb6" | "Cb7" | "Cb9" | "Cb10" | "Cb11" | "C#0" | "C#1" | "C#2" | "C#4" | "C#8" | "C#-4" | "C#3" | "C#-3" | "C#-2" | "C#-1" | "C#5" | "C#6" | "C#7" | "C#9" | "C#10" | "C#11" | "Cx0" | "Cx1" | "Cx2" | "Cx4" | "Cx8" | "Cx-4" | "Cx3" | "Cx-3" | "Cx-2" | "Cx-1" | "Cx5" | "Cx6" | "Cx7" | "Cx9" | "Cx10" | "Cx11" | "D0" | "D1" | "D2" | "D4" | "D8" | "D-4" | "D3" | "D-3" | "D-2" | "D-1" | "D5" | "D6" | "D7" | "D9" | "D10" | "D11" | "Dbb0" | "Dbb1" | "Dbb2" | "Dbb4" | "Dbb8" | "Dbb-4" | "Dbb3" | "Dbb-3" | "Dbb-2" | "Dbb-1" | "Dbb5" | "Dbb6" | "Dbb7" | "Dbb9" | "Dbb10" | "Dbb11" | "Db0" | "Db1" | "Db2" | "Db4" | "Db8" | "Db-4" | "Db3" | "Db-3" | "Db-2" | "Db-1" | "Db5" | "Db6" | "Db7" | "Db9" | "Db10" | "Db11" | "D#0" | "D#1" | "D#2" | "D#4" | "D#8" | "D#-4" | "D#3" | "D#-3" | "D#-2" | "D#-1" | "D#5" | "D#6" | "D#7" | "D#9" | "D#10" | "D#11" | "Dx0" | "Dx1" | "Dx2" | "Dx4" | "Dx8" | "Dx-4" | "Dx3" | "Dx-3" | "Dx-2" | "Dx-1" | "Dx5" | "Dx6" | "Dx7" | "Dx9" | "Dx10" | "Dx11" | "E0" | "E1" | "E2" | "E4" | "E8" | "E-4" | "E3" | "E-3" | "E-2" | "E-1" | "E5" | "E6" | "E7" | "E9" | "E10" | "E11" | "Ebb0" | "Ebb1" | "Ebb2" | "Ebb4" | "Ebb8" | "Ebb-4" | "Ebb3" | "Ebb-3" | "Ebb-2" | "Ebb-1" | "Ebb5" | "Ebb6" | "Ebb7" | "Ebb9" | "Ebb10" | "Ebb11" | "Eb0" | "Eb1" | "Eb2" | "Eb4" | "Eb8" | "Eb-4" | "Eb3" | "Eb-3" | "Eb-2" | "Eb-1" | "Eb5" | "Eb6" | "Eb7" | "Eb9" | "Eb10" | "Eb11" | "E#0" | "E#1" | "E#2" | "E#4" | "E#8" | "E#-4" | "E#3" | "E#-3" | "E#-2" | "E#-1" | "E#5" | "E#6" | "E#7" | "E#9" | "E#10" | "E#11" | "Ex0" | "Ex1" | "Ex2" | "Ex4" | "Ex8" | "Ex-4" | "Ex3" | "Ex-3" | "Ex-2" | "Ex-1" | "Ex5" | "Ex6" | "Ex7" | "Ex9" | "Ex10" | "Ex11" | "F0" | "F1" | "F2" | "F4" | "F8" | "F-4" | "F3" | "F-3" | "F-2" | "F-1" | "F5" | "F6" | "F7" | "F9" | "F10" | "F11" | "Fbb0" | "Fbb1" | "Fbb2" | "Fbb4" | "Fbb8" | "Fbb-4" | "Fbb3" | "Fbb-3" | "Fbb-2" | "Fbb-1" | "Fbb5" | "Fbb6" | "Fbb7" | "Fbb9" | "Fbb10" | "Fbb11" | "Fb0" | "Fb1" | "Fb2" | "Fb4" | "Fb8" | "Fb-4" | "Fb3" | "Fb-3" | "Fb-2" | "Fb-1" | "Fb5" | "Fb6" | "Fb7" | "Fb9" | "Fb10" | "Fb11" | "F#0" | "F#1" | "F#2" | "F#4" | "F#8" | "F#-4" | "F#3" | "F#-3" | "F#-2" | "F#-1" | "F#5" | "F#6" | "F#7" | "F#9" | "F#10" | "F#11" | "Fx0" | "Fx1" | "Fx2" | "Fx4" | "Fx8" | "Fx-4" | "Fx3" | "Fx-3" | "Fx-2" | "Fx-1" | "Fx5" | "Fx6" | "Fx7" | "Fx9" | "Fx10" | "Fx11" | "G0" | "G1" | "G2" | "G4" | "G8" | "G-4" | "G3" | "G-3" | "G-2" | "G-1" | "G5" | "G6" | "G7" | "G9" | "G10" | "G11" | "Gbb0" | "Gbb1" | "Gbb2" | "Gbb4" | "Gbb8" | "Gbb-4" | "Gbb3" | "Gbb-3" | "Gbb-2" | "Gbb-1" | "Gbb5" | "Gbb6" | "Gbb7" | "Gbb9" | "Gbb10" | "Gbb11" | "Gb0" | "Gb1" | "Gb2" | "Gb4" | "Gb8" | "Gb-4" | "Gb3" | "Gb-3" | "Gb-2" | "Gb-1" | "Gb5" | "Gb6" | "Gb7" | "Gb9" | "Gb10" | "Gb11" | "G#0" | "G#1" | "G#2" | "G#4" | "G#8" | "G#-4" | "G#3" | "G#-3" | "G#-2" | "G#-1" | "G#5" | "G#6" | "G#7" | "G#9" | "G#10" | "G#11" | "Gx0" | "Gx1" | "Gx2" | "Gx4" | "Gx8" | "Gx-4" | "Gx3" | "Gx-3" | "Gx-2" | "Gx-1" | "Gx5" | "Gx6" | "Gx7" | "Gx9" | "Gx10" | "Gx11" | "A0" | "A1" | "A2" | "A4" | "A8" | "A-4" | "A3" | "A-3" | "A-2" | "A-1" | "A5" | "A6" | "A7" | "A9" | "A10" | "A11" | "Abb0" | "Abb1" | "Abb2" | "Abb4" | "Abb8" | "Abb-4" | "Abb3" | "Abb-3" | "Abb-2" | "Abb-1" | "Abb5" | "Abb6" | "Abb7" | "Abb9" | "Abb10" | "Abb11" | "Ab0" | "Ab1" | "Ab2" | "Ab4" | "Ab8" | "Ab-4" | "Ab3" | "Ab-3" | "Ab-2" | "Ab-1" | "Ab5" | "Ab6" | "Ab7" | "Ab9" | "Ab10" | "Ab11" | "A#0" | "A#1" | "A#2" | "A#4" | "A#8" | "A#-4" | "A#3" | "A#-3" | "A#-2" | "A#-1" | "A#5" | "A#6" | "A#7" | "A#9" | "A#10" | "A#11" | "Ax0" | "Ax1" | "Ax2" | "Ax4" | "Ax8" | "Ax-4" | "Ax3" | "Ax-3" | "Ax-2" | "Ax-1" | "Ax5" | "Ax6" | "Ax7" | "Ax9" | "Ax10" | "Ax11" | "B0" | "B1" | "B2" | "B4" | "B8" | "B-4" | "B3" | "B-3" | "B-2" | "B-1" | "B5" | "B6" | "B7" | "B9" | "B10" | "B11" | "Bbb0" | "Bbb1" | "Bbb2" | "Bbb4" | "Bbb8" | "Bbb-4" | "Bbb3" | "Bbb-3" | "Bbb-2" | "Bbb-1" | "Bbb5" | "Bbb6" | "Bbb7" | "Bbb9" | "Bbb10" | "Bbb11" | "Bb0" | "Bb1" | "Bb2" | "Bb4" | "Bb8" | "Bb-4" | "Bb3" | "Bb-3" | "Bb-2" | "Bb-1" | "Bb5" | "Bb6" | "Bb7" | "Bb9" | "Bb10" | "Bb11" | "B#0" | "B#1" | "B#2" | "B#4" | "B#8" | "B#-4" | "B#3" | "B#-3" | "B#-2" | "B#-1" | "B#5" | "B#6" | "B#7" | "B#9" | "B#10" | "B#11" | "Bx0" | "Bx1" | "Bx2" | "Bx4" | "Bx8" | "Bx-4" | "Bx3" | "Bx-3" | "Bx-2" | "Bx-1" | "Bx5" | "Bx6" | "Bx7" | "Bx9" | "Bx10" | "Bx11" | 12 | 24 | 48 | 96 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127, url: string | ToneAudioBuffer | AudioBuffer, callback?: () => void): this

Add a note to the sampler.

Parameters

  • note 0 | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 3 | 5 | 6 | 7 | 9 | 10 | 11 | "C0" | "C1" | "C2" | "C4" | "C8" | "C-4" | "C3" | "C-3" | "C-2" | "C-1" | "C5" | "C6" | "C7" | "C9" | "C10" | "C11" | "Cbb0" | "Cbb1" | "Cbb2" | "Cbb4" | "Cbb8" | "Cbb-4" | "Cbb3" | "Cbb-3" | "Cbb-2" | "Cbb-1" | "Cbb5" | "Cbb6" | "Cbb7" | "Cbb9" | "Cbb10" | "Cbb11" | "Cb0" | "Cb1" | "Cb2" | "Cb4" | "Cb8" | "Cb-4" | "Cb3" | "Cb-3" | "Cb-2" | "Cb-1" | "Cb5" | "Cb6" | "Cb7" | "Cb9" | "Cb10" | "Cb11" | "C#0" | "C#1" | "C#2" | "C#4" | "C#8" | "C#-4" | "C#3" | "C#-3" | "C#-2" | "C#-1" | "C#5" | "C#6" | "C#7" | "C#9" | "C#10" | "C#11" | "Cx0" | "Cx1" | "Cx2" | "Cx4" | "Cx8" | "Cx-4" | "Cx3" | "Cx-3" | "Cx-2" | "Cx-1" | "Cx5" | "Cx6" | "Cx7" | "Cx9" | "Cx10" | "Cx11" | "D0" | "D1" | "D2" | "D4" | "D8" | "D-4" | "D3" | "D-3" | "D-2" | "D-1" | "D5" | "D6" | "D7" | "D9" | "D10" | "D11" | "Dbb0" | "Dbb1" | "Dbb2" | "Dbb4" | "Dbb8" | "Dbb-4" | "Dbb3" | "Dbb-3" | "Dbb-2" | "Dbb-1" | "Dbb5" | "Dbb6" | "Dbb7" | "Dbb9" | "Dbb10" | "Dbb11" | "Db0" | "Db1" | "Db2" | "Db4" | "Db8" | "Db-4" | "Db3" | "Db-3" | "Db-2" | "Db-1" | "Db5" | "Db6" | "Db7" | "Db9" | "Db10" | "Db11" | "D#0" | "D#1" | "D#2" | "D#4" | "D#8" | "D#-4" | "D#3" | "D#-3" | "D#-2" | "D#-1" | "D#5" | "D#6" | "D#7" | "D#9" | "D#10" | "D#11" | "Dx0" | "Dx1" | "Dx2" | "Dx4" | "Dx8" | "Dx-4" | "Dx3" | "Dx-3" | "Dx-2" | "Dx-1" | "Dx5" | "Dx6" | "Dx7" | "Dx9" | "Dx10" | "Dx11" | "E0" | "E1" | "E2" | "E4" | "E8" | "E-4" | "E3" | "E-3" | "E-2" | "E-1" | "E5" | "E6" | "E7" | "E9" | "E10" | "E11" | "Ebb0" | "Ebb1" | "Ebb2" | "Ebb4" | "Ebb8" | "Ebb-4" | "Ebb3" | "Ebb-3" | "Ebb-2" | "Ebb-1" | "Ebb5" | "Ebb6" | "Ebb7" | "Ebb9" | "Ebb10" | "Ebb11" | "Eb0" | "Eb1" | "Eb2" | "Eb4" | "Eb8" | "Eb-4" | "Eb3" | "Eb-3" | "Eb-2" | "Eb-1" | "Eb5" | "Eb6" | "Eb7" | "Eb9" | "Eb10" | "Eb11" | "E#0" | "E#1" | "E#2" | "E#4" | "E#8" | "E#-4" | "E#3" | "E#-3" | "E#-2" | "E#-1" | "E#5" | "E#6" | "E#7" | "E#9" | "E#10" | "E#11" | "Ex0" | "Ex1" | "Ex2" | "Ex4" | "Ex8" | "Ex-4" | "Ex3" | "Ex-3" | "Ex-2" | "Ex-1" | "Ex5" | "Ex6" | "Ex7" | "Ex9" | "Ex10" | "Ex11" | "F0" | "F1" | "F2" | "F4" | "F8" | "F-4" | "F3" | "F-3" | "F-2" | "F-1" | "F5" | "F6" | "F7" | "F9" | "F10" | "F11" | "Fbb0" | "Fbb1" | "Fbb2" | "Fbb4" | "Fbb8" | "Fbb-4" | "Fbb3" | "Fbb-3" | "Fbb-2" | "Fbb-1" | "Fbb5" | "Fbb6" | "Fbb7" | "Fbb9" | "Fbb10" | "Fbb11" | "Fb0" | "Fb1" | "Fb2" | "Fb4" | "Fb8" | "Fb-4" | "Fb3" | "Fb-3" | "Fb-2" | "Fb-1" | "Fb5" | "Fb6" | "Fb7" | "Fb9" | "Fb10" | "Fb11" | "F#0" | "F#1" | "F#2" | "F#4" | "F#8" | "F#-4" | "F#3" | "F#-3" | "F#-2" | "F#-1" | "F#5" | "F#6" | "F#7" | "F#9" | "F#10" | "F#11" | "Fx0" | "Fx1" | "Fx2" | "Fx4" | "Fx8" | "Fx-4" | "Fx3" | "Fx-3" | "Fx-2" | "Fx-1" | "Fx5" | "Fx6" | "Fx7" | "Fx9" | "Fx10" | "Fx11" | "G0" | "G1" | "G2" | "G4" | "G8" | "G-4" | "G3" | "G-3" | "G-2" | "G-1" | "G5" | "G6" | "G7" | "G9" | "G10" | "G11" | "Gbb0" | "Gbb1" | "Gbb2" | "Gbb4" | "Gbb8" | "Gbb-4" | "Gbb3" | "Gbb-3" | "Gbb-2" | "Gbb-1" | "Gbb5" | "Gbb6" | "Gbb7" | "Gbb9" | "Gbb10" | "Gbb11" | "Gb0" | "Gb1" | "Gb2" | "Gb4" | "Gb8" | "Gb-4" | "Gb3" | "Gb-3" | "Gb-2" | "Gb-1" | "Gb5" | "Gb6" | "Gb7" | "Gb9" | "Gb10" | "Gb11" | "G#0" | "G#1" | "G#2" | "G#4" | "G#8" | "G#-4" | "G#3" | "G#-3" | "G#-2" | "G#-1" | "G#5" | "G#6" | "G#7" | "G#9" | "G#10" | "G#11" | "Gx0" | "Gx1" | "Gx2" | "Gx4" | "Gx8" | "Gx-4" | "Gx3" | "Gx-3" | "Gx-2" | "Gx-1" | "Gx5" | "Gx6" | "Gx7" | "Gx9" | "Gx10" | "Gx11" | "A0" | "A1" | "A2" | "A4" | "A8" | "A-4" | "A3" | "A-3" | "A-2" | "A-1" | "A5" | "A6" | "A7" | "A9" | "A10" | "A11" | "Abb0" | "Abb1" | "Abb2" | "Abb4" | "Abb8" | "Abb-4" | "Abb3" | "Abb-3" | "Abb-2" | "Abb-1" | "Abb5" | "Abb6" | "Abb7" | "Abb9" | "Abb10" | "Abb11" | "Ab0" | "Ab1" | "Ab2" | "Ab4" | "Ab8" | "Ab-4" | "Ab3" | "Ab-3" | "Ab-2" | "Ab-1" | "Ab5" | "Ab6" | "Ab7" | "Ab9" | "Ab10" | "Ab11" | "A#0" | "A#1" | "A#2" | "A#4" | "A#8" | "A#-4" | "A#3" | "A#-3" | "A#-2" | "A#-1" | "A#5" | "A#6" | "A#7" | "A#9" | "A#10" | "A#11" | "Ax0" | "Ax1" | "Ax2" | "Ax4" | "Ax8" | "Ax-4" | "Ax3" | "Ax-3" | "Ax-2" | "Ax-1" | "Ax5" | "Ax6" | "Ax7" | "Ax9" | "Ax10" | "Ax11" | "B0" | "B1" | "B2" | "B4" | "B8" | "B-4" | "B3" | "B-3" | "B-2" | "B-1" | "B5" | "B6" | "B7" | "B9" | "B10" | "B11" | "Bbb0" | "Bbb1" | "Bbb2" | "Bbb4" | "Bbb8" | "Bbb-4" | "Bbb3" | "Bbb-3" | "Bbb-2" | "Bbb-1" | "Bbb5" | "Bbb6" | "Bbb7" | "Bbb9" | "Bbb10" | "Bbb11" | "Bb0" | "Bb1" | "Bb2" | "Bb4" | "Bb8" | "Bb-4" | "Bb3" | "Bb-3" | "Bb-2" | "Bb-1" | "Bb5" | "Bb6" | "Bb7" | "Bb9" | "Bb10" | "Bb11" | "B#0" | "B#1" | "B#2" | "B#4" | "B#8" | "B#-4" | "B#3" | "B#-3" | "B#-2" | "B#-1" | "B#5" | "B#6" | "B#7" | "B#9" | "B#10" | "B#11" | "Bx0" | "Bx1" | "Bx2" | "Bx4" | "Bx8" | "Bx-4" | "Bx3" | "Bx-3" | "Bx-2" | "Bx-1" | "Bx5" | "Bx6" | "Bx7" | "Bx9" | "Bx10" | "Bx11" | 12 | 24 | 48 | 96 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127

    The buffer’s pitch.

  • url string | ToneAudioBuffer | AudioBuffer

    Either the url of the buffer, or a buffer which will be added with the given name.

  • callback () => void optional

    The callback to invoke when the url is loaded.

Returns this

dispose(): this

Clean up

Returns this

urls, baseUrl, onload and onerror aren’t stored as regular class properties (unlike attack/release/curve), so the base implementation can’t find them via Reflect.has and they’d be silently missing here.

Returns SamplerOptions

releaseAll(time?: Time): this

Release all currently active notes.

Parameters

  • time Time optional

    When to release the notes.

Returns this

setLoopPoints(loopStart: Time, loopEnd: Time): this

Set the loop start and end. Will only loop if loop is set to true.

const sampler = new Tone.Sampler({
     urls: {
          A1: "https://tonejs.github.io/audio/berklee/guitar_chord4.mp3",
     },
}).toDestination();
// loop between the given points
sampler.setLoopPoints(0.2, 0.3);
sampler.loop = true;

Parameters

  • loopStart Time

    The loop start time

  • loopEnd Time

    The loop end time

Returns 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(notes: Frequency | Frequency[], time?: Time, velocity?: number): this

Parameters

  • notes Frequency | Frequency[]

    The note to play, or an array of notes.

  • time Time optional

    When to play the note

  • velocity number optional default 1

    The velocity to play the sample back.

Returns this

triggerAttackRelease(notes: Frequency | Frequency[], duration: Time | Time[], time?: Time, velocity?: number): this

Invoke the attack phase, then after the duration, invoke the release.

Parameters

  • notes Frequency | Frequency[]

    The note to play and release, or an array of notes.

  • duration Time | Time[]

    The time the note should be held

  • time Time optional

    When to start the attack

  • velocity number optional default 1

    The velocity of the attack

Returns this

triggerRelease(notes: Frequency | Frequency[], time?: Time): this

Parameters

  • notes Frequency | Frequency[]

    The note to release, or an array of notes.

  • time Time optional

    When to release the note.

Returns this

↳ inherited from Instrument

unsync(): this

Unsync the instrument from the Transport

Returns this

static

getDefaults(): SamplerOptions

Returns all of the default options belonging to the class.

Returns SamplerOptions