Optional
callback: ToneEventCallback<CallbackType<ValueType>>The callback to invoke on each event
Optional
value: ValueType[]the array of events
Optional
options: Partial<PartOptions<ValueType>>The callback to invoke.
Readonly
contextThe context belonging to the node.
Set this debug flag to log all events that happen in this class.
If mute is true, the callback won't be invoked.
Readonly
nameThe value which is passed to the callback function.
Static
versionThe version number semver
The number of seconds of 1 processing block (128 samples)
console.log(Tone.Destination.blockTime);
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.
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.
const event = new Tone.ToneEvent();
event.humanize = true;
The number of scheduled notes in the part.
If the part should loop or not between Part.loopStart and Part.loopEnd. If set to true, the part 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.
const part = new Tone.Part();
// loop the part 8 times
part.loop = 8;
The playback rate of the part
The probability of the notes being triggered.
The current progress of the loop interval. Returns 0 if the event is not started yet or it is not set to loop.
The duration in seconds of one sample.
The start from the scheduled start time.
Returns the playback state of the note, either "started" or "stopped".
Get/Set an Event's value at the given time. If a value is passed in and no event exists at the given time, one will be created with that value. If two events are at the same time, the first one will be returned.
const part = new Tone.Part();
part.at("1m"); // returns the part at the first measure
part.at("2m", "C2"); // set the value at "2m" to C2.
// if an event didn't exist at that time, it will be created.
Cancel scheduled state change events: i.e. "start" and "stop".
Optional
after: Unit.Time | TransportTimeClass<number>The time after which to cancel the scheduled events.
Get the object's attributes.
const osc = new Tone.Oscillator();
console.log(osc.get());
Set multiple properties at once with an object.
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 incoming time to seconds. This is calculated against the current TransportClass bpm
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);
Static
get
Part is a collection ToneEvents which can be started/stopped and looped as a single unit.
Example
Example