Part is a collection ToneEvents which can be started/stopped and looped as a single unit.
import { Part, Synth } from "tone";
const synth = new Synth().toDestination();
const part = new Part(((time, note) => {
// the notes given as the second element in the array
// will be passed in as the second argument
synth.triggerAttackRelease(note, "8n", time);
}), [[0, "C2"], ["0:2", "C3"], ["0:3:2", "G2"]]);
import { Part, Synth } from "tone";
const synth = new Synth().toDestination();
// use an array of objects as long as the object has a "time" attribute
const part = new Part(((time, value) => {
// the value is an object which contains both the note and the velocity
synth.triggerAttackRelease(value.note, "8n", time, value.velocity);
}), [{ time: 0, note: "C3", velocity: 0.9 },
{ time: "0:2", note: "C4", velocity: 0.5 }
]).start(0);
The number of seconds of 1 processing block (128 samples)
The callback to invoke.
The context belonging to the node.
Set this debug flag to log all events that happen in this class.
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 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.
import { Part } from "tone";
const part = new Part();
// loop the part 8 times
part.loop = 8;
The loopEnd point determines when it will loop if Part.loop is true.
The loopStart point determines when it will loop if Part.loop is true.
If mute is true, the callback won't be invoked.
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.
Returns the playback state of the note, either "started" or "stopped".
The value which is passed to the callback function.
The version number semver
Add a an event to the part.
import { Part } from "tone";
const part = new Part();
part.add("1m", "C#+11");
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.
import { Part } from "tone";
const part = new 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.
If a value is passed in, the value of the event at the given time will be set to it.
Cancel scheduled state change events: i.e. "start" and "stop".
Get the object's attributes.
import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.get());
// returns {"type" : "sine", "frequency" : 440, ...etc}
Returns all of the default options belonging to the class.
Return the current time of the Context clock without any lookAhead.
Return the current time of the Context clock plus the lookAhead.
Remove an event from the part. If the event at that time is a Part, it will remove the entire part.
Set multiple properties at once with an object.
import { Filter } from "tone";
const filter = new Filter();
// set values using an object
filter.set({
frequency: 300,
type: "highpass"
});
Convert the input to a frequency number
Convert the incoming time to seconds
Convert the class to a string
import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.toString());
Convert the input time into ticks