Part < ValueType >

  • ValueType: [object Object]

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


const synth = new Tone.Synth().toDestination();
const part = new Tone.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"]]);
Tone.Transport.start();

const synth = new Tone.Synth().toDestination();
// use an array of objects as long as the object has a "time" attribute
const part = new Tone.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);
Tone.Transport.start();

Hierarchy

Constructor

new Part (
callback?:ToneEventCallback<CallbackType<ValueType > > ,

The callback to invoke on each event

value?:ValueType []
) => Part
new Part (
options?:Partial<PartOptions<ValueType > >
) => Part

Properties

blockTime #

readonly Seconds

The number of seconds of 1 processing block (128 samples)


console.log(Tone.Destination.blockTime);

callback #

ToneEventCallback<ValueType >

The callback to invoke.

context #

BaseContext

The context belonging to the node.

debug #

boolean

Set this debug flag to log all events that happen in this class.

disposed #

readonly boolean

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.

humanize #

boolean | Time

length #

readonly number

The number of scheduled notes in the part.

loop #

boolean | number

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;

loopEnd #

Time

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

loopStart #

Time

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

mute #

boolean

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

name #

string

playbackRate #

Positive

The playback rate of the part

progress #

readonly NormalRange

The current progress of the loop interval. Returns 0 if the event is not started yet or it is not set to loop.

sampleTime #

readonly Seconds

The duration in seconds of one sample.


console.log(Tone.Transport.sampleTime);

state #

readonly BasicPlaybackState

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

value #

ValueType

The value which is passed to the callback function.

static version #

string

The version number semver

Methods

add #

Add a an event to the part.


const part = new Tone.Part();
part.add("1m", "C#+11");
add (
obj:
) => this

add #

add (
time:Time ,
value?:any
) => this

at #

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.
at (
time:Time ,

The time of the event to get or set.

value?:any

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

) => ToneEvent | null

cancel #

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

cancel (
after?:TransportTime | TransportTimeClass

The time after which to cancel the scheduled events.

) => this

clear #

Remove all of the notes from the group.

clear ( ) => this

dispose #

disconnect and dispose.

dispose ( ) => this

get #

Get the object's attributes.


const osc = new Tone.Oscillator();
console.log(osc.get());
get ( ) => ToneEventOptions<ValueType >

static getDefaults #

Returns all of the default options belonging to the class.

getDefaults ( ) => PartOptions<any >

immediate #

Return the current time of the Context clock without any lookAhead.


setInterval(() => {
	console.log(Tone.immediate());
}, 100);
immediate ( ) => Seconds

now #

Return the current time of the Context clock plus the lookAhead.


setInterval(() => {
	console.log(Tone.now());
}, 100);
now ( ) => Seconds

remove #

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

remove (
obj:
) => this

remove #

remove (
time:Time ,
value?:any
) => this

set #

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;
set (
props:RecursivePartial<ToneEventOptions<ValueType > >
) => this

start #

Start the part at the given time.

start (
time?:TransportTime ,

When to start the part.

offset?:Time

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

) => this

stop #

Stop the part at the given time.

stop (
time?:TransportTime

When to stop the part.

) => this

toFrequency #

Convert the input to a frequency number


const gain = new Tone.Gain();
console.log(gain.toFrequency("4n"));
toFrequency (
freq:Frequency
) => Hertz

toSeconds #

Convert the incoming time to seconds. This is calculated against the current Tone.Transport 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);
toSeconds (
time?:Time
) => Seconds

toString #

Convert the class to a string


const osc = new Tone.Oscillator();
console.log(osc.toString());
toString ( ) => string

toTicks #

Convert the input time into ticks


const gain = new Tone.Gain();
console.log(gain.toTicks("4n"));
toTicks (
time?:Time | TimeClass
) => Ticks