Documentation
    Preparing search index...

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

    Hierarchy (View Summary)

    Index
    • Parameters

      • Optionalsamples: SamplesMap

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

      • Optionalonload: () => void

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

      • OptionalbaseUrl: string

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

      Returns Sampler

    • Parameters

      • Optionalsamples: SamplesMap

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

      • Optionaloptions: Partial<Omit<SamplerOptions, "urls">>

        The remaining options associated with the sampler

      Returns Sampler

    • Parameters

      Returns Sampler

    _internalChannels: OutputNode[]

    List all of the node that must be set to match the ChannelProperties

    _syncedRelease: (time: number) => this

    The release which is scheduled to the timeline.

    attack: Time

    The envelope applied to the beginning of the sample.

    0

    1

    context: BaseContext

    The context belonging to the node.

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

    debug: boolean

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

    input: undefined

    The instrument only has an output

    name: string

    The name of the class

    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.

    0

    1

    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);
    version: string

    The version number semver

    • get blockTime(): number

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

      Returns number

      console.log(Tone.Destination.blockTime);
      
    • get channelCount(): number

      channelCount is the number of channels used when up-mixing and down-mixing connections to any inputs to the node. The default value is 2 except for specific nodes where its value is specially determined.

      Returns number

    • set channelCount(channelCount: number): void

      Parameters

      • channelCount: number

      Returns void

    • get channelCountMode(): ChannelCountMode

      channelCountMode determines how channels will be counted when up-mixing and down-mixing connections to any inputs to the node. The default value is "max". This attribute has no effect for nodes with no inputs.

      • "max" - computedNumberOfChannels is the maximum of the number of channels of all connections to an input. In this mode channelCount is ignored.
      • "clamped-max" - computedNumberOfChannels is determined as for "max" and then clamped to a maximum value of the given channelCount.
      • "explicit" - computedNumberOfChannels is the exact value as specified by the channelCount.

      Returns ChannelCountMode

    • set channelCountMode(channelCountMode: ChannelCountMode): void

      Parameters

      Returns void

    • get channelInterpretation(): ChannelInterpretation

      channelInterpretation determines how individual channels will be treated when up-mixing and down-mixing connections to any inputs to the node. The default value is "speakers".

      Returns ChannelInterpretation

    • set channelInterpretation(channelInterpretation: ChannelInterpretation): void

      Parameters

      Returns void

    • 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 loaded(): boolean

      If the buffers are loaded or not

      Returns boolean

    • get numberOfInputs(): number

      The number of inputs feeding into the AudioNode. For source nodes, this will be 0.

      Returns number

      const node = new Tone.Gain();
      console.log(node.numberOfInputs);
    • get numberOfOutputs(): number

      The number of outputs of the AudioNode.

      Returns number

      const node = new Tone.Gain();
      console.log(node.numberOfOutputs);
    • get sampleTime(): number

      The duration in seconds of one sample.

      Returns number

    • Wrap the given method so that it can be synchronized

      Parameters

      • method: string

        Which method to wrap and sync

      • timePosition: number

        What position the time argument appears in

      Returns void

    • set _sync

      Returns boolean

    • Add a note to the sampler.

      Parameters

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

      • Optionalcallback: () => void

        The callback to invoke when the url is loaded.

      Returns this

    • Connect the output of this node to the rest of the nodes in series.

      Parameters

      Returns this

      const player = new Tone.Player("https://tonejs.github.io/audio/drum-samples/handdrum-loop.mp3");
      player.autostart = true;
      const filter = new Tone.AutoFilter(4).start();
      const distortion = new Tone.Distortion(0.5);
      // connect the player to the filter, distortion and then to the master output
      player.chain(filter, distortion, Tone.Destination);
    • connect the output of a ToneAudioNode to an AudioParam, AudioNode, or ToneAudioNode

      Parameters

      • destination: InputNode

        The output to connect to

      • OptionaloutputNum: number

        The output to connect from

      • OptionalinputNum: number

        The input to connect to

      Returns this

    • disconnect the output

      Parameters

      • Optionaldestination: InputNode
      • OptionaloutputNum: number
      • OptionalinputNum: number

      Returns this

    • Clean up

      Returns this

    • connect the output of this node to the rest of the nodes in parallel.

      Parameters

      Returns this

      const player = new Tone.Player("https://tonejs.github.io/audio/drum-samples/conga-rhythm.mp3");
      player.autostart = true;
      const pitchShift = new Tone.PitchShift(4).toDestination();
      const filter = new Tone.Filter("G5").toDestination();
      // connect a node to the pitch shift and filter in parallel
      player.fan(pitchShift, filter);
    • Get the object's attributes.

      Returns SamplerOptions

      const osc = new Tone.Oscillator();
      console.log(osc.get());
    • Return the current time of the Context clock without any lookAhead.

      Returns number

      setInterval(() => {
      console.log(Tone.immediate());
      }, 100);
    • Prints the outputs to the console log for debugging purposes. Prints the contents only if either the object has a property called debug set to true, or a variable called TONE_DEBUG_CLASS is set to the name of the class.

      Parameters

      • ...args: any[]

      Returns void

      const osc = new Tone.Oscillator();
      // prints all logs originating from this oscillator
      osc.debug = true;
      // calls to start/stop will print in the console
      osc.start();
    • Return the current time of the Context clock plus the lookAhead.

      Returns number

      setInterval(() => {
      console.log(Tone.now());
      }, 100);
    • Release all currently active notes.

      Parameters

      • Optionaltime: Time

        When to release the notes.

      Returns this

    • Set multiple properties at once with an object.

      Parameters

      Returns this

      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;
    • Sync the instrument to the Transport. All subsequent calls of triggerAttack and triggerRelease will be scheduled along the transport.

      Returns this

      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();
    • Connect the output to the context's destination node.

      Returns this

      const osc = new Tone.Oscillator("C2").start();
      osc.toDestination();
    • Convert the input to a frequency number

      Parameters

      Returns number

      const gain = new Tone.Gain();
      console.log(gain.toFrequency("4n"));
    • Connect the output to the context's destination node.

      Returns this

    • Convert the incoming time to seconds. This is calculated against the current TransportClass bpm

      Parameters

      Returns number

      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

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

      Parameters

      Returns number

      const gain = new Tone.Gain();
      console.log(gain.toTicks("4n"));
    • Start the instrument's note.

      Parameters

      • notes: Frequency | Frequency[]

        The note to play, or an array of notes.

      • Optionaltime: Time

        When to play the note

      • Optionalvelocity: number

        The velocity to play the sample back.

      Returns 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

      • Optionaltime: Time

        When to start the attack

      • Optionalvelocity: number

        The velocity of the attack

      Returns this

    • Trigger the release phase of the current note.

      Parameters

      • notes: Frequency | Frequency[]

        The note to release, or an array of notes.

      • Optionaltime: Time

        When to release the note.

      Returns this

    • Unsync the instrument from the Transport

      Returns this