Skip to content
Tone.js

Loop

class Event ↳ extends ToneWithContext<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();
new Loop(callback?: (time: number) => void, interval?: Time)

Parameters

  • callback (time: number) => void optional

    The callback to invoke at the time.

  • interval Time optional

    The time between successive callback calls.

new Loop(options?: Partial<LoopOptions>)

Parameters

callback: (time: number) => void

The callback to invoke with the next event in the pattern

read-only

name: string

The name of the class

Default: "Loop"

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.

playbackRate: number

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

probability: number

The probably of the callback being invoked.

read-only

progress: number

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

read-only

The state of the Loop, either started or stopped.

cancel(time?: Time): this

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

Parameters

  • time Time optional

    The time after which events will be cancel.

Returns this

dispose(): this

disconnect and dispose.

Returns this

start(time?: Time): this

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

Parameters

  • time Time optional

    When to start the Loop.

Returns this

stop(time?: Time): this

Stop the loop at the given time.

Parameters

  • time Time optional

    When to stop the Loop.

Returns this

static

getDefaults(): LoopOptions

Returns all of the default options belonging to the class.

Returns LoopOptions