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();Constructor
Section titled “Constructor”new Loop(callback?: (time: number) => void, interval?: Time)Parameters
-
callback
(time: number) => voidoptionalThe callback to invoke at the time.
-
interval
TimeoptionalThe time between successive callback calls.
new Loop(options?: Partial<LoopOptions>)Parameters
- options
Partial<LoopOptions>optional
Properties
Section titled “Properties”callback
Section titled “callback”callback: (time: number) => voidThe callback to invoke with the next event in the pattern
humanize
Section titled “humanize”humanize: boolean | TimeRandom variation +/-0.01s to the scheduled time. Or give it a time value which it will randomize by.
interval
Section titled “interval”interval: TimeThe time between successive callbacks.
const loop = new Tone.Loop(); loop.interval = "8n"; // loop every 8n
iterations
Section titled “iterations”iterations: numberThe number of iterations of the loop. The default value is Infinity (loop forever).
playbackRate
Section titled “playbackRate”playbackRate: numberThe playback rate of the loop. The normal playback rate is 1 (no change).
A playbackRate of 2 would be twice as fast.
probability
Section titled “probability”probability: numberThe probably of the callback being invoked.
progress
Section titled “progress”read-only
progress: numberThe progress of the loop as a value between 0-1. 0, when the loop is stopped or done iterating.
Methods
Section titled “Methods”cancel()
Section titled “cancel()”cancel(time?: Time): thisCancel all scheduled events greater than or equal to the given time
Parameters
-
time
TimeoptionalThe time after which events will be cancel.
Returns this
start()
Section titled “start()”start(time?: Time): thisStart the loop at the specified time along the Transport’s timeline.
Parameters
-
time
TimeoptionalWhen to start the Loop.
Returns this
stop()
Section titled “stop()”stop(time?: Time): thisStop the loop at the given time.
Parameters
-
time
TimeoptionalWhen to stop the Loop.
Returns this
getDefaults()
Section titled “getDefaults()”static
getDefaults(): LoopOptionsReturns all of the default options belonging to the class.
Returns LoopOptions
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString()