Tone.Part

↳ EXTENDS Tone.Event

Tone.Part is a collection Tone.Events which can be started/stopped and looped as a single unit.

CONSTRUCTOR

new Tone.Part (
callback
,
events
)
callback

The callback to invoke on each event

events

the array of events

type: Array

DEFAULTS

{
callback : Tone.noOp ,
loop : false ,
loopEnd : 1m ,
loopStart : 0 ,
playbackRate : 1 ,
probability : 1 ,
humanize : false ,
mute : false ,
events : []
}

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

.playbackRate

Positive #

The playback rate of the part

</>

.probability

NormalRange #

The probability of the notes being triggered.

</>

.length

Positive READONLY #

The number of scheduled notes in the part.

</>

.loop

Boolean or Positive #

If the part should loop or not between Tone.Part.loopStart and Tone.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.

EXAMPLE

//loop the part 8 times
part.loop = 8;
</>

.loopEnd

Time #

The loopEnd point determines when it will loop if Tone.Part.loop is true.

</>

.loopStart

Time #

The loopStart point determines when it will loop if Tone.Part.loop is true.

</>

.humanize

Boolean or Time #

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.

EXAMPLE

event.humanize = true;
 
</>
inherited from Tone.Event

.state

String READONLY #

Returns the playback state of the note, either “started” or “stopped”.

</>
inherited from Tone.Event

.mute

Boolean #

If mute is true, the callback won’t be invoked.

</>
inherited from Tone.Event

.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.

</>
inherited from Tone.Event

.callback

function #

The callback to invoke.

</>

Methods

.stop ( )

#
time

When to stop the part.

↪ returns Tone.Part

this

Stop the part at the given time.

</>

.at ( )

#
time

The time of the event to get or set.

value

If a value is passed in, the value of the event at the given time will be set to it.

type: *
optional
↪ returns Tone.Event

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

#
after

The time after which to cancel the scheduled events.

↪ returns Tone.Part

this

Cancel scheduled state change events: i.e. “start” and “stop”.

</>

.dispose ( )

#
↪ returns Tone.Part

this

Clean up

</>

.remove ( )

#
time

The time of the event

type: Time
value

Optionally select only a specific event value

type: *
↪ returns Tone.Part

this

Remove an event from the part. If the event at that time is a Tone.Part, it will remove the entire part.

</>

.removeAll ( )

#
↪ returns Tone.Part

this

Remove all of the notes from the group.

</>

.start ( )

#
time

When to start the part.

offset

The offset from the start of the part to begin playing at.

type: Time
optional
↪ returns Tone.Part

this

Start the part at the given time.

</>

.add ( )

#
time

The time the note should start. If an object is passed in, it should have a ‘time’ attribute and the rest of the object will be used as the ‘value’.

type: Time
value
type: Tone.Event or *
↪ returns Tone.Part

this

Add a an event to the part.

EXAMPLE

part.add("1m", "C#+11");
</>
docs generated Sep 15 2019