Loop < Options >

Loop creates a looped callback at the specified interval. The callback can be started, stopped and scheduled along the Transport's timeline.


const loop = new Tone.Loop((time) => {
	// triggered every eighth note.
	console.log(time);
}, "8n").start(0);
Tone.Transport.start();

Hierarchy

Constructor

new Loop (
callback?:undefined | (time) => void ,

The callback to invoke at the time.

interval?:Time

The time between successive callback calls.

) => Loop
new Loop (
options?:Partial<LoopOptions >
) => Loop

Properties

blockTime #

readonly Seconds

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


console.log(Tone.Destination.blockTime);

callback #

(time) => void

The callback to invoke with the next event in the pattern

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

Random variation +/-0.01s to the scheduled time. Or give it a time value which it will randomize by.

interval #

Time

The time between successive callbacks.


const loop = new Tone.Loop();
loop.interval = "8n"; // loop every 8n

iterations #

number

The number of iterations of the loop. The default value is Infinity (loop forever).

mute #

boolean

Muting the Loop means that no callbacks are invoked.

name #

string

playbackRate #

Positive

The playback rate of the loop. The normal playback rate is 1 (no change). A playbackRate of 2 would be twice as fast.

probability #

NormalRange

The probably of the callback being invoked.

progress #

readonly NormalRange

The progress of the loop as a value between 0-1. 0, when the loop is stopped or done iterating.

sampleTime #

readonly Seconds

The duration in seconds of one sample.


console.log(Tone.Transport.sampleTime);

state #

readonly BasicPlaybackState

The state of the Loop, either started or stopped.

static version #

string

The version number semver

Methods

cancel #

Cancel all scheduled events greater than or equal to the given time

cancel (
time?:TransportTime

The time after which events will be cancel.

) => this

dispose #

disconnect and dispose.

dispose ( ) => this

get #

Get the object's attributes.


const osc = new Tone.Oscillator();
console.log(osc.get());
get ( ) => Options

static getDefaults #

Returns all of the default options belonging to the class.

getDefaults ( ) => LoopOptions

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

set #

Set multiple properties at once with an object.


const filter = new Tone.Filter();
// set values using an object
filter.set({
	frequency: 300,
	type: "highpass"
});
set (
props:RecursivePartial<Options >
) => this

start #

Start the loop at the specified time along the Transport's timeline.

start (
time?:TransportTime

When to start the Loop.

) => this

stop #

Stop the loop at the given time.

stop (
time?:TransportTime

When to stop the Loop.

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


const gain = new Tone.Gain();
console.log(gain.toSeconds("4n"));
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