1 | import "../core/clock/Transport.js";
|
2 | import { ToneWithContext, ToneWithContextOptions } from "../core/context/ToneWithContext.js";
|
3 | import { TransportTimeClass } from "../core/type/TransportTime.js";
|
4 | import { NormalRange, Positive, Seconds, Ticks, Time, TransportTime } from "../core/type/Units.js";
|
5 | import { BasicPlaybackState, StateTimeline } from "../core/util/StateTimeline.js";
|
6 | export type ToneEventCallback<T> = (time: Seconds, value: T) => void;
|
7 | export interface ToneEventOptions<T> extends ToneWithContextOptions {
|
8 | callback: ToneEventCallback<T>;
|
9 | loop: boolean | number;
|
10 | loopEnd: Time;
|
11 | loopStart: Time;
|
12 | playbackRate: Positive;
|
13 | value?: T;
|
14 | probability: NormalRange;
|
15 | mute: boolean;
|
16 | humanize: boolean | Time;
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | export declare class ToneEvent<ValueType = any> extends ToneWithContext<ToneEventOptions<ValueType>> {
|
37 | readonly name: string;
|
38 | |
39 |
|
40 |
|
41 | protected _loop: boolean | number;
|
42 | |
43 |
|
44 |
|
45 | callback: ToneEventCallback<ValueType>;
|
46 | |
47 |
|
48 |
|
49 |
|
50 | value: ValueType;
|
51 | |
52 |
|
53 |
|
54 | protected _loopStart: Ticks;
|
55 | |
56 |
|
57 |
|
58 | protected _loopEnd: Ticks;
|
59 | |
60 |
|
61 |
|
62 | protected _state: StateTimeline<{
|
63 | id: number;
|
64 | }>;
|
65 | |
66 |
|
67 |
|
68 |
|
69 | protected _playbackRate: Positive;
|
70 | |
71 |
|
72 |
|
73 | protected _startOffset: Ticks;
|
74 | |
75 |
|
76 |
|
77 | protected _probability: NormalRange;
|
78 | |
79 |
|
80 |
|
81 | protected _humanize: boolean | Time;
|
82 | |
83 |
|
84 |
|
85 | mute: boolean;
|
86 | |
87 |
|
88 |
|
89 |
|
90 | constructor(callback?: ToneEventCallback<ValueType>, value?: ValueType);
|
91 | constructor(options?: Partial<ToneEventOptions<ValueType>>);
|
92 | static getDefaults(): ToneEventOptions<any>;
|
93 | /**
|
94 | * Reschedule all of the events along the timeline
|
95 | * with the updated values.
|
96 | * @param after Only reschedules events after the given time.
|
97 | */
|
98 | private _rescheduleEvents;
|
99 | /**
|
100 | * Returns the playback state of the note, either "started" or "stopped".
|
101 | */
|
102 | get state(): BasicPlaybackState;
|
103 | /**
|
104 | * The start from the scheduled start time.
|
105 | */
|
106 | get startOffset(): Ticks;
|
107 | set startOffset(offset: Ticks);
|
108 | /**
|
109 | * The probability of the notes being triggered.
|
110 | */
|
111 | get probability(): NormalRange;
|
112 | set probability(prob: NormalRange);
|
113 | /**
|
114 | * If set to true, will apply small random variation
|
115 | * to the callback time. If the value is given as a time, it will randomize
|
116 | * by that amount.
|
117 | * @example
|
118 | * const event = new Tone.ToneEvent();
|
119 | * event.humanize = true;
|
120 | */
|
121 | get humanize(): Time | boolean;
|
122 | set humanize(variation: Time | boolean);
|
123 | /**
|
124 | * Start the note at the given time.
|
125 | * @param time When the event should start.
|
126 | */
|
127 | start(time?: TransportTime | TransportTimeClass): this;
|
128 | /**
|
129 | * Stop the Event at the given time.
|
130 | * @param time When the event should stop.
|
131 | */
|
132 | stop(time?: TransportTime | TransportTimeClass): this;
|
133 | /**
|
134 | * Cancel all scheduled events greater than or equal to the given time
|
135 | * @param time The time after which events will be cancel.
|
136 | */
|
137 | cancel(time?: TransportTime | TransportTimeClass): this;
|
138 | /**
|
139 | * The callback function invoker. Also
|
140 | * checks if the Event is done playing
|
141 | * @param time The time of the event in seconds
|
142 | */
|
143 | protected _tick(time: Seconds): void;
|
144 | /**
|
145 | * Get the duration of the loop.
|
146 | */
|
147 | protected _getLoopDuration(): Ticks;
|
148 | /**
|
149 | * If the note should loop or not
|
150 | * between ToneEvent.loopStart and
|
151 | * ToneEvent.loopEnd. If set to true,
|
152 | * the event will loop indefinitely,
|
153 | * if set to a number greater than 1
|
154 | * it will play a specific number of
|
155 | * times, if set to false, 0 or 1, the
|
156 | * part will only play once.
|
157 | */
|
158 | get loop(): boolean | number;
|
159 | set loop(loop: boolean | number);
|
160 | /**
|
161 | * The playback rate of the event. Defaults to 1.
|
162 | * @example
|
163 | * const note = new Tone.ToneEvent();
|
164 | * note.loop = true;
|
165 | * // repeat the note twice as fast
|
166 | * note.playbackRate = 2;
|
167 | */
|
168 | get playbackRate(): Positive;
|
169 | set playbackRate(rate: Positive);
|
170 | /**
|
171 | * The loopEnd point is the time the event will loop
|
172 | * if ToneEvent.loop is true.
|
173 | */
|
174 | get loopEnd(): Time;
|
175 | set loopEnd(loopEnd: Time);
|
176 | /**
|
177 | * The time when the loop should start.
|
178 | */
|
179 | get loopStart(): Time;
|
180 | set loopStart(loopStart: Time);
|
181 | /**
|
182 | * The current progress of the loop interval.
|
183 | * Returns 0 if the event is not started yet or
|
184 | * it is not set to loop.
|
185 | */
|
186 | get progress(): NormalRange;
|
187 | dispose(): this;
|
188 | }
|