Tone.Part
↳ EXTENDS Tone.EventTone.Part is a collection Tone.Events which can be started/stopped and looped as a single unit.
CONSTRUCTOR
new Tone.Part (The callback to invoke on each event
the array of events
DEFAULTS
EXAMPLE
var part = new Tone.Part(function(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"]]);
EXAMPLE
//use an array of objects as long as the object has a "time" attribute
var part = new Tone.Part(function(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);
Members
.loop
↝ Boolean or Positive #If the part should loop or not between Tone.Part.loopStart and Tone.Part.loopEnd. An integer value corresponds to the number of loops the Part does after it starts.
EXAMPLE
//loop the part 8 times
part.loop = 8;
.state
↝ String READONLY #Returns the playback state of the note, either “started” or “stopped”.
.progress
↝ NormalRange READONLY #The current progress of the loop interval. Returns 0 if the event is not started yet or it is not set to loop.
Methods
.stop ( )
#When to stop the part.
this
Stop the part at the given time.
.at ( )
#The time of the event to get or set.
If a value is passed in, the value of the event at the given time will be set to it.
the event at the time
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.
EXAMPLE
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 ( )
#The time after which to cancel the scheduled events.
this
Cancel scheduled state change events: i.e. “start” and “stop”.
.remove ( )
#The time of the event
Optionally select only a specific event value
this
Remove an event from the part. If the event at that time is a Tone.Part, it will remove the entire part.
.start ( )
#When to start the part.
The offset from the start of the part to begin playing at.
this
Start the part at the given time.