tone 15.3.6 → 15.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,14 +22,17 @@ interface ClockOptions extends ToneWithContextOptions {
22
22
  type ClockEvent = "start" | "stop" | "pause";
23
23
 
24
24
  /**
25
- * A sample accurate clock which provides a callback at the given rate.
26
- * While the callback is not sample-accurate (it is still susceptible to
27
- * loose JS timing), the time passed in as the argument to the callback
28
- * is precise. For most applications, it is better to use Tone.Transport
29
- * instead of the Clock by itself since you can synchronize multiple callbacks.
25
+ * A sample-accurate clock that provides a callback at a given rate.
26
+ *
27
+ * While the callback is not sample-accurate (it is susceptible to
28
+ * loose JavaScript timing), the time passed to the callback is precise.
29
+ *
30
+ * For most applications, it is better to use {@link Transport} instead of the
31
+ * Clock by itself, since you can synchronize multiple callbacks.
32
+ *
30
33
  * @example
31
- * // the callback will be invoked approximately once a second
32
- * // and will print the time exactly once a second apart.
34
+ * // The callback will be invoked approximately once a second,
35
+ * // and it will print the time exactly one second apart.
33
36
  * const clock = new Tone.Clock(time => {
34
37
  * console.log(time);
35
38
  * }, 1);
@@ -112,17 +115,16 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
112
115
  }
113
116
 
114
117
  /**
115
- * Returns the playback state of the source, either "started", "stopped" or "paused".
118
+ * The playback state of the clock, either "started", "stopped", or "paused".
116
119
  */
117
120
  get state(): PlaybackState {
118
121
  return this._state.getValueAtTime(this.now());
119
122
  }
120
123
 
121
124
  /**
122
- * Start the clock at the given time. Optionally pass in an offset
123
- * of where to start the tick counter from.
124
- * @param time The time the clock should start
125
- * @param offset Where the tick counter starts counting from.
125
+ * Start the clock at the given time.
126
+ * @param time The time the clock should start.
127
+ * @param offset The number of ticks to start the clock from.
126
128
  */
127
129
  start(time?: Time, offset?: Ticks): this {
128
130
  // make sure the context is running
@@ -148,7 +150,7 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
148
150
  * console.log(time);
149
151
  * }, 1);
150
152
  * clock.start();
151
- * // stop the clock after 10 seconds
153
+ * // Stop the clock after 10 seconds.
152
154
  * clock.stop("+10");
153
155
  */
154
156
  stop(time?: Time): this {
@@ -165,7 +167,7 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
165
167
 
166
168
  /**
167
169
  * Pause the clock. Pausing does not reset the tick counter.
168
- * @param time The time when the clock should stop.
170
+ * @param time The time when the clock should pause.
169
171
  */
170
172
  pause(time?: Time): this {
171
173
  const computedTime = this.toSeconds(time);
@@ -180,8 +182,9 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
180
182
  }
181
183
 
182
184
  /**
183
- * The number of times the callback was invoked. Starts counting at 0
184
- * and increments after the callback was invoked.
185
+ * The number of times the callback has been invoked.
186
+ *
187
+ * Starts counting at 0 and increments after the callback is invoked.
185
188
  */
186
189
  get ticks(): Ticks {
187
190
  return Math.ceil(this.getTicksAtTime(this.now()));
@@ -191,7 +194,9 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
191
194
  }
192
195
 
193
196
  /**
194
- * The time since ticks=0 that the Clock has been running. Accounts for tempo curves
197
+ * The time since ticks=0 that the clock has been running.
198
+ *
199
+ * Accounts for tempo curves.
195
200
  */
196
201
  get seconds(): Seconds {
197
202
  return this._tickSource.seconds;
@@ -202,8 +207,8 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
202
207
 
203
208
  /**
204
209
  * Return the elapsed seconds at the given time.
205
- * @param time When to get the elapsed seconds
206
- * @return The number of elapsed seconds
210
+ * @param time When to get the elapsed seconds.
211
+ * @return The number of elapsed seconds.
207
212
  */
208
213
  getSecondsAtTime(time: Time): Seconds {
209
214
  return this._tickSource.getSecondsAtTime(time);
@@ -211,8 +216,8 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
211
216
 
212
217
  /**
213
218
  * Set the clock's ticks at the given time.
214
- * @param ticks The tick value to set
215
- * @param time When to set the tick value
219
+ * @param ticks The tick value to set.
220
+ * @param time When to set the tick value.
216
221
  */
217
222
  setTicksAtTime(ticks: Ticks, time: Time): this {
218
223
  this._tickSource.setTicksAtTime(ticks, time);
@@ -220,11 +225,14 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
220
225
  }
221
226
 
222
227
  /**
223
- * Get the time of the given tick. The second argument
224
- * is when to test before. Since ticks can be set (with setTicksAtTime)
225
- * there may be multiple times for a given tick value.
226
- * @param tick The tick number.
227
- * @param before When to measure the tick value from.
228
+ * Get the time of the given tick.
229
+ *
230
+ * The second argument is when to test before. Since ticks can be set
231
+ * (with {@link setTicksAtTime}), there may be multiple times for a given
232
+ * tick value.
233
+ *
234
+ * @param tick The tick number.
235
+ * @param before When to measure the tick value from.
228
236
  * @return The time of the tick
229
237
  */
230
238
  getTimeOfTick(tick: Ticks, before = this.now()): Seconds {
@@ -233,7 +241,7 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
233
241
 
234
242
  /**
235
243
  * Get the clock's ticks at the given time.
236
- * @param time When to get the tick value
244
+ * @param time When to get the tick value.
237
245
  * @return The tick value at the given time.
238
246
  */
239
247
  getTicksAtTime(time?: Time): Ticks {
@@ -241,8 +249,8 @@ export class Clock<TypeName extends "bpm" | "hertz" = "hertz">
241
249
  }
242
250
 
243
251
  /**
244
- * Get the time of the next tick
245
- * @param offset The tick number.
252
+ * Get the time of the next tick.
253
+ * @param offset The tick number.
246
254
  */
247
255
  nextTickTime(offset: Ticks, when: Time): Seconds {
248
256
  const computedTime = this.toSeconds(when);
@@ -68,23 +68,25 @@ type TransportCallback = (time: Seconds) => void;
68
68
 
69
69
  /**
70
70
  * Transport for timing musical events.
71
- * Supports tempo curves and time changes. Unlike browser-based timing (setInterval, requestAnimationFrame)
71
+ *
72
+ * Supports tempo curves and time changes.
73
+ *
74
+ * Unlike browser-based timing (setInterval, requestAnimationFrame),
72
75
  * Transport timing events pass in the exact time of the scheduled event
73
- * in the argument of the callback function. Pass that time value to the object
74
- * you're scheduling. <br><br>
76
+ * in the argument of the callback function.
77
+ *
75
78
  * A single transport is created for you when the library is initialized.
76
- * <br><br>
77
- * The transport emits the events: "start", "stop", "pause", and "loop" which are
78
- * called with the time of that event as the argument.
79
+ *
80
+ * The transport emits "start", "stop", "pause", and "loop" events.
79
81
  *
80
82
  * @example
81
83
  * const osc = new Tone.Oscillator().toDestination();
82
- * // repeated event every 8th note
84
+ * // Repeated event every 8th note.
83
85
  * Tone.getTransport().scheduleRepeat((time) => {
84
- * // use the callback time to schedule events
86
+ * // Use the callback time to schedule events.
85
87
  * osc.start(time).stop(time + 0.1);
86
88
  * }, "8n");
87
- * // transport must be started before it starts invoking events
89
+ * // Transport must be started before it starts invoking events.
88
90
  * Tone.getTransport().start();
89
91
  * @category Core
90
92
  */
@@ -276,14 +278,14 @@ export class TransportInstance
276
278
  //-------------------------------------
277
279
 
278
280
  /**
279
- * Schedule an event along the timeline.
280
- * @param callback The callback to be invoked at the time.
281
+ * Schedule an event to be invoked at a specific time.
282
+ * @param callback The callback to invoke at the given time.
281
283
  * @param time The time to invoke the callback at.
282
- * @return The id of the event which can be used for canceling the event.
284
+ * @return The ID of the event, which can be used to cancel the event.
283
285
  * @example
284
- * // schedule an event on the 16th measure
286
+ * // Schedule an event on the 16th measure.
285
287
  * Tone.getTransport().schedule((time) => {
286
- * // invoked on measure 16
288
+ * // Invoked on measure 16.
287
289
  * console.log("measure 16!");
288
290
  * }, "16:0:0");
289
291
  */
@@ -299,17 +301,18 @@ export class TransportInstance
299
301
  }
300
302
 
301
303
  /**
302
- * Schedule a repeated event along the timeline. The event will fire
303
- * at the `interval` starting at the `startTime` and for the specified
304
- * `duration`.
305
- * @param callback The callback to invoke.
306
- * @param interval The duration between successive callbacks. Must be a positive number.
307
- * @param startTime When along the timeline the events should start being invoked.
308
- * @param duration How long the event should repeat.
309
- * @return The ID of the scheduled event. Use this to cancel the event.
304
+ * Schedule a repeated event.
305
+ *
306
+ * The event will fire at the `interval` starting at the `startTime` and for the specified `duration`.
307
+ *
308
+ * @param callback The callback to invoke.
309
+ * @param interval The duration between successive callbacks.
310
+ * @param startTime When the event should start.
311
+ * @param duration How long the event should repeat.
312
+ * @return The ID of the scheduled event. Use this to cancel the event.
310
313
  * @example
311
314
  * const osc = new Tone.Oscillator().toDestination().start();
312
- * // a callback invoked every eighth note after the first measure
315
+ * // A callback invoked every eighth note after the first measure.
313
316
  * Tone.getTransport().scheduleRepeat((time) => {
314
317
  * osc.start(time).stop(time + 0.1);
315
318
  * }, "8n", "1m");
@@ -420,7 +423,7 @@ export class TransportInstance
420
423
  }
421
424
 
422
425
  /**
423
- * Returns the playback state of the source, either "started", "stopped", or "paused"
426
+ * The playback state of the transport, either "started", "stopped", or "paused".
424
427
  */
425
428
  get state(): PlaybackState {
426
429
  return this._clock.getStateAtTime(this.now());
@@ -428,10 +431,10 @@ export class TransportInstance
428
431
 
429
432
  /**
430
433
  * Start the transport and all sources synced to the transport.
431
- * @param time The time when the transport should start.
432
- * @param offset The timeline offset to start the transport.
434
+ * @param time The time when the transport should start.
435
+ * @param offset The timeline offset to start the transport from.
433
436
  * @example
434
- * // start the transport in one second starting at beginning of the 5th measure.
437
+ * // Start the transport in one second, beginning at the start of the 5th measure.
435
438
  * Tone.getTransport().start("+1", "4:0:0");
436
439
  */
437
440
  start(time?: Time, offset?: TransportTime): this {
@@ -466,9 +469,11 @@ export class TransportInstance
466
469
  }
467
470
 
468
471
  /**
469
- * Toggle the current state of the transport. If it is
470
- * started, it will stop it, otherwise it will start the Transport.
471
- * @param time The time of the event
472
+ * Toggle the current state of the transport.
473
+ *
474
+ * If it is started, it will stop it. If it is stopped, it will start it.
475
+ *
476
+ * @param time The time of the event.
472
477
  */
473
478
  toggle(time?: Time): this {
474
479
  time = this.toSeconds(time);
@@ -33,29 +33,29 @@ export interface ContextTimeoutEvent {
33
33
  }
34
34
 
35
35
  /**
36
- * Wrapper around the native AudioContext.
36
+ * Wraps the native AudioContext.
37
37
  * @category Core
38
38
  */
39
39
  export class Context extends BaseContext {
40
40
  readonly name: string = "Context";
41
41
 
42
42
  /**
43
- * private reference to the BaseAudioContext
43
+ * A private reference to the BaseAudioContext.
44
44
  */
45
45
  protected readonly _context: AnyAudioContext;
46
46
 
47
47
  /**
48
- * A reliable callback method
48
+ * A reliable callback method.
49
49
  */
50
50
  private readonly _ticker: Ticker;
51
51
 
52
52
  /**
53
- * The default latency hint
53
+ * The default latency hint.
54
54
  */
55
55
  private _latencyHint!: ContextLatencyHint | Seconds;
56
56
 
57
57
  /**
58
- * An object containing all of the constants AudioBufferSourceNodes
58
+ * An object containing all of the AudioBufferSourceNodes with constant values.
59
59
  */
60
60
  private _constants = new Map<number, AudioBufferSourceNode>();
61
61
 
@@ -580,11 +580,13 @@ export class Context extends BaseContext {
580
580
  }
581
581
 
582
582
  /**
583
- * A setTimeout which is guaranteed by the clock source.
583
+ * A `setTimeout` which is guaranteed by the clock source.
584
+ *
584
585
  * Also runs in the offline context.
585
- * @param fn The callback to invoke
586
- * @param timeout The timeout in seconds
587
- * @returns ID to use when invoking Context.clearTimeout
586
+ *
587
+ * @param fn The callback to invoke.
588
+ * @param timeout The timeout in seconds.
589
+ * @returns ID to use when invoking {@link clearTimeout}.
588
590
  */
589
591
  setTimeout(fn: (...args: any[]) => void, timeout: Seconds): number {
590
592
  this._timeoutIds++;
@@ -598,8 +600,8 @@ export class Context extends BaseContext {
598
600
  }
599
601
 
600
602
  /**
601
- * Clears a previously scheduled timeout with Tone.context.setTimeout
602
- * @param id The ID returned from setTimeout
603
+ * Clears a previously scheduled timeout with {@link setTimeout}.
604
+ * @param id The ID returned from {@link setTimeout}.
603
605
  */
604
606
  clearTimeout(id: number): this {
605
607
  this._timeouts.forEach((event) => {
@@ -611,14 +613,18 @@ export class Context extends BaseContext {
611
613
  }
612
614
 
613
615
  /**
614
- * Clear the function scheduled by {@link setInterval}
616
+ * Clear the function scheduled by {@link setInterval}.
617
+ * @param id The ID returned from {@link setInterval}.
615
618
  */
616
619
  clearInterval(id: number): this {
617
620
  return this.clearTimeout(id);
618
621
  }
619
622
 
620
623
  /**
621
- * Adds a repeating event to the context's callback clock
624
+ * Adds a repeating event to the context's callback clock.
625
+ * @param fn The callback to invoke.
626
+ * @param interval The timeout in seconds.
627
+ * @returns ID to use when invoking {@link clearInterval}.
622
628
  */
623
629
  setInterval(fn: (...args: any[]) => void, interval: Seconds): number {
624
630
  const id = ++this._timeoutIds;
@@ -16,17 +16,19 @@ interface DestinationOptions extends ToneAudioNodeOptions {
16
16
  }
17
17
 
18
18
  /**
19
- * A single master output which is connected to the
20
- * AudioDestinationNode (aka your speakers).
21
- * It provides useful conveniences such as the ability
19
+ * A single master output that is connected to the
20
+ * AudioDestinationNode (i.e. your speakers).
21
+ *
22
+ * It provides useful conveniences, such as the ability
22
23
  * to set the volume and mute the entire application.
24
+ *
23
25
  * It also gives you the ability to apply master effects to your application.
24
26
  *
25
27
  * @example
26
28
  * const oscillator = new Tone.Oscillator().start();
27
- * // the audio will go from the oscillator to the speakers
29
+ * // The audio will go from the oscillator to the speakers.
28
30
  * oscillator.connect(Tone.getDestination());
29
- * // a convenience for connecting to the master output is also provided:
31
+ * // A convenience for connecting to the master output is also provided:
30
32
  * oscillator.toDestination();
31
33
  * @category Core
32
34
  */
@@ -37,11 +39,14 @@ export class DestinationInstance extends ToneAudioNode<DestinationOptions> {
37
39
  output: Gain = new Gain({ context: this.context });
38
40
 
39
41
  /**
40
- * The volume of the master output in decibels. -Infinity is silent, and 0 is no change.
42
+ * The volume of the master output in decibels.
43
+ *
44
+ * -Infinity is silent, and 0 is no change.
45
+ *
41
46
  * @example
42
47
  * const osc = new Tone.Oscillator().toDestination();
43
48
  * osc.start();
44
- * // ramp the volume down to silent over 10 seconds
49
+ * // Ramp the volume down to silent over 10 seconds.
45
50
  * Tone.getDestination().volume.rampTo(-Infinity, 10);
46
51
  */
47
52
  volume: Param<"decibels"> = this.input.volume;
@@ -80,7 +85,7 @@ export class DestinationInstance extends ToneAudioNode<DestinationOptions> {
80
85
  * @example
81
86
  * const oscillator = new Tone.Oscillator().start().toDestination();
82
87
  * setTimeout(() => {
83
- * // mute the output
88
+ * // Mute the output.
84
89
  * Tone.Destination.mute = true;
85
90
  * }, 1000);
86
91
  */
@@ -92,11 +97,13 @@ export class DestinationInstance extends ToneAudioNode<DestinationOptions> {
92
97
  }
93
98
 
94
99
  /**
95
- * Add a master effects chain. NOTE: this will disconnect any nodes which were previously
96
- * chained in the master effects chain.
97
- * @param args All arguments will be connected in a row and the Master will be routed through it.
100
+ * Add a master effects chain.
101
+ *
102
+ * NOTE: This will disconnect any nodes that were previously chained in the master effects chain.
103
+ *
104
+ * @param args All arguments will be connected in a row, and the master output will be routed through it.
98
105
  * @example
99
- * // route all audio through a filter and compressor
106
+ * // Route all audio through a filter and compressor.
100
107
  * const lowpass = new Tone.Filter(800, "lowpass");
101
108
  * const compressor = new Tone.Compressor(-18);
102
109
  * Tone.Destination.chain(lowpass, compressor);
@@ -110,7 +117,7 @@ export class DestinationInstance extends ToneAudioNode<DestinationOptions> {
110
117
  }
111
118
 
112
119
  /**
113
- * The maximum number of channels the system can output
120
+ * The maximum number of channels the system can output.
114
121
  * @example
115
122
  * console.log(Tone.Destination.maxChannelCount);
116
123
  */
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.3.6";
1
+ export const version: string = "15.3.8";