UNPKG

3.55 kBTypeScriptView Raw
1import { NormalRange, Positive, Seconds, Time, TransportTime } from "../core/type/Units.js";
2import { ToneWithContext, ToneWithContextOptions } from "../core/context/ToneWithContext.js";
3import { BasicPlaybackState } from "../core/util/StateTimeline.js";
4export interface LoopOptions extends ToneWithContextOptions {
5 callback: (time: Seconds) => void;
6 interval: Time;
7 playbackRate: Positive;
8 iterations: number;
9 probability: NormalRange;
10 mute: boolean;
11 humanize: boolean | Time;
12}
13/**
14 * Loop creates a looped callback at the
15 * specified interval. The callback can be
16 * started, stopped and scheduled along
17 * the Transport's timeline.
18 * @example
19 * const loop = new Tone.Loop((time) => {
20 * // triggered every eighth note.
21 * console.log(time);
22 * }, "8n").start(0);
23 * Tone.Transport.start();
24 * @category Event
25 */
26export declare class Loop<Options extends LoopOptions = LoopOptions> extends ToneWithContext<Options> {
27 readonly name: string;
28 /**
29 * The event which produces the callbacks
30 */
31 private _event;
32 /**
33 * The callback to invoke with the next event in the pattern
34 */
35 callback: (time: Seconds) => void;
36 /**
37 * @param callback The callback to invoke at the time.
38 * @param interval The time between successive callback calls.
39 */
40 constructor(callback?: (time: Seconds) => void, interval?: Time);
41 constructor(options?: Partial<LoopOptions>);
42 static getDefaults(): LoopOptions;
43 /**
44 * Start the loop at the specified time along the Transport's timeline.
45 * @param time When to start the Loop.
46 */
47 start(time?: TransportTime): this;
48 /**
49 * Stop the loop at the given time.
50 * @param time When to stop the Loop.
51 */
52 stop(time?: TransportTime): this;
53 /**
54 * Cancel all scheduled events greater than or equal to the given time
55 * @param time The time after which events will be cancel.
56 */
57 cancel(time?: TransportTime): this;
58 /**
59 * Internal function called when the notes should be called
60 * @param time The time the event occurs
61 */
62 protected _tick(time: Seconds): void;
63 /**
64 * The state of the Loop, either started or stopped.
65 */
66 get state(): BasicPlaybackState;
67 /**
68 * The progress of the loop as a value between 0-1. 0, when the loop is stopped or done iterating.
69 */
70 get progress(): NormalRange;
71 /**
72 * The time between successive callbacks.
73 * @example
74 * const loop = new Tone.Loop();
75 * loop.interval = "8n"; // loop every 8n
76 */
77 get interval(): Time;
78 set interval(interval: Time);
79 /**
80 * The playback rate of the loop. The normal playback rate is 1 (no change).
81 * A `playbackRate` of 2 would be twice as fast.
82 */
83 get playbackRate(): Positive;
84 set playbackRate(rate: Positive);
85 /**
86 * Random variation +/-0.01s to the scheduled time.
87 * Or give it a time value which it will randomize by.
88 */
89 get humanize(): boolean | Time;
90 set humanize(variation: boolean | Time);
91 /**
92 * The probably of the callback being invoked.
93 */
94 get probability(): NormalRange;
95 set probability(prob: NormalRange);
96 /**
97 * Muting the Loop means that no callbacks are invoked.
98 */
99 get mute(): boolean;
100 set mute(mute: boolean);
101 /**
102 * The number of iterations of the loop. The default value is `Infinity` (loop forever).
103 */
104 get iterations(): number;
105 set iterations(iters: number);
106 dispose(): this;
107}