Tone.Sampler
↳ EXTENDS Tone.InstrumentA sampler instrument which plays an audio buffer through an amplitude envelope and a filter envelope. The sampler takes an Object in the constructor which maps a sample name to the URL of the sample. Nested Objects will be flattened and can be accessed using a dot notation (see the example).
CONSTRUCTOR
new Tone.Sampler (the urls of the audio file
the options object for the synth
DEFAULTS
EXAMPLE
var sampler = new Sampler({
A : {
1 : "./audio/casio/A1.mp3",
2 : "./audio/casio/A2.mp3",
},
"B.1" : "./audio/casio/B1.mp3",
}).toMaster();
//listen for when all the samples have loaded
Tone.Buffer.onload = function(){
sampler.triggerAttack("A.1", time, velocity);
};Members
.pitch
↝ Interval #Repitch the sampled note by some interval (measured in semi-tones).
EXAMPLE
sampler.pitch = -12; //down one octave
sampler.pitch = 7; //up a fifth.sample
↝ number or string #The name of the sample to trigger.
EXAMPLE
//set the sample to "A.2" for next time the sample is triggered
sampler.sample = "A.2";.volume
↝ Decibels #The volume of the output in decibels.
EXAMPLE
source.volume.value = -6;Methods
.triggerAttack ( )
#The name of the sample to trigger, defaults to the last sample used.
The time when the sample should start
The velocity of the note
this
Start the sample and simultaneously trigger the envelopes.
EXAMPLE
sampler.triggerAttack("B.1");.triggerRelease ( )
#The time when the note should release
this
Start the release portion of the sample. Will stop the sample once the envelope has fully released.
EXAMPLE
sampler.triggerRelease();.triggerAttackRelease ( )
#The note to trigger.
How long the note should be held for before triggering the release.
When the note should be triggered.
The velocity the note should be triggered at.
this
Trigger the attack and then the release after the duration.
EXAMPLE
//trigger "C4" for the duration of an 8th note
synth.triggerAttackRelease("C4", "8n");