tone 14.8.34 → 14.8.35
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.
- package/Tone/source/buffer/Player.ts +45 -21
- package/Tone/version.ts +1 -1
- package/build/Tone.js +1 -1
- package/build/Tone.js.map +1 -1
- package/build/esm/source/buffer/Player.d.ts +2 -1
- package/build/esm/source/buffer/Player.js +19 -11
- package/build/esm/source/buffer/Player.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/docs/tone.json +1 -1
- package/package.json +1 -1
|
@@ -31,7 +31,6 @@ export interface PlayerOptions extends SourceOptions {
|
|
|
31
31
|
* @category Source
|
|
32
32
|
*/
|
|
33
33
|
export class Player extends Source<PlayerOptions> {
|
|
34
|
-
|
|
35
34
|
readonly name: string = "Player";
|
|
36
35
|
|
|
37
36
|
/**
|
|
@@ -86,12 +85,22 @@ export class Player extends Source<PlayerOptions> {
|
|
|
86
85
|
* @param url Either the AudioBuffer or the url from which to load the AudioBuffer
|
|
87
86
|
* @param onload The function to invoke when the buffer is loaded.
|
|
88
87
|
*/
|
|
89
|
-
constructor(
|
|
88
|
+
constructor(
|
|
89
|
+
url?: string | AudioBuffer | ToneAudioBuffer,
|
|
90
|
+
onload?: () => void
|
|
91
|
+
);
|
|
90
92
|
constructor(options?: Partial<PlayerOptions>);
|
|
91
93
|
constructor() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
super(
|
|
95
|
+
optionsFromArguments(Player.getDefaults(), arguments, [
|
|
96
|
+
"url",
|
|
97
|
+
"onload",
|
|
98
|
+
])
|
|
99
|
+
);
|
|
100
|
+
const options = optionsFromArguments(Player.getDefaults(), arguments, [
|
|
101
|
+
"url",
|
|
102
|
+
"onload",
|
|
103
|
+
]);
|
|
95
104
|
|
|
96
105
|
this._buffer = new ToneAudioBuffer({
|
|
97
106
|
onload: this._onload.bind(this, options.onload),
|
|
@@ -157,8 +166,11 @@ export class Player extends Source<PlayerOptions> {
|
|
|
157
166
|
|
|
158
167
|
// delete the source from the active sources
|
|
159
168
|
this._activeSources.delete(source);
|
|
160
|
-
if (
|
|
161
|
-
this.
|
|
169
|
+
if (
|
|
170
|
+
this._activeSources.size === 0 &&
|
|
171
|
+
!this._synced &&
|
|
172
|
+
this._state.getValueAtTime(this.now()) === "started"
|
|
173
|
+
) {
|
|
162
174
|
// remove the 'implicitEnd' event and replace with an explicit end
|
|
163
175
|
this._state.cancel(this.now());
|
|
164
176
|
this._state.setStateAtTime("stopped", this.now());
|
|
@@ -196,7 +208,10 @@ export class Player extends Source<PlayerOptions> {
|
|
|
196
208
|
|
|
197
209
|
// compute the duration which is either the passed in duration of the buffer.duration - offset
|
|
198
210
|
const origDuration = duration;
|
|
199
|
-
duration = defaultArg(
|
|
211
|
+
duration = defaultArg(
|
|
212
|
+
duration,
|
|
213
|
+
Math.max(this._buffer.duration - computedOffset, 0)
|
|
214
|
+
);
|
|
200
215
|
let computedDuration = this.toSeconds(duration);
|
|
201
216
|
|
|
202
217
|
// scale it by the playback rate
|
|
@@ -223,9 +238,13 @@ export class Player extends Source<PlayerOptions> {
|
|
|
223
238
|
// cancel the previous stop
|
|
224
239
|
this._state.cancel(startTime + computedDuration);
|
|
225
240
|
// if it's not looping, set the state change at the end of the sample
|
|
226
|
-
this._state.setStateAtTime(
|
|
227
|
-
|
|
228
|
-
|
|
241
|
+
this._state.setStateAtTime(
|
|
242
|
+
"stopped",
|
|
243
|
+
startTime + computedDuration,
|
|
244
|
+
{
|
|
245
|
+
implicitEnd: true,
|
|
246
|
+
}
|
|
247
|
+
);
|
|
229
248
|
}
|
|
230
249
|
|
|
231
250
|
// add it to the array of active sources
|
|
@@ -236,7 +255,11 @@ export class Player extends Source<PlayerOptions> {
|
|
|
236
255
|
source.start(startTime, computedOffset);
|
|
237
256
|
} else {
|
|
238
257
|
// subtract the fade out time
|
|
239
|
-
source.start(
|
|
258
|
+
source.start(
|
|
259
|
+
startTime,
|
|
260
|
+
computedOffset,
|
|
261
|
+
computedDuration - this.toSeconds(this.fadeOut)
|
|
262
|
+
);
|
|
240
263
|
}
|
|
241
264
|
}
|
|
242
265
|
|
|
@@ -245,14 +268,14 @@ export class Player extends Source<PlayerOptions> {
|
|
|
245
268
|
*/
|
|
246
269
|
protected _stop(time?: Time): void {
|
|
247
270
|
const computedTime = this.toSeconds(time);
|
|
248
|
-
this._activeSources.forEach(source => source.stop(computedTime));
|
|
271
|
+
this._activeSources.forEach((source) => source.stop(computedTime));
|
|
249
272
|
}
|
|
250
273
|
|
|
251
274
|
/**
|
|
252
275
|
* Stop and then restart the player from the beginning (or offset)
|
|
253
276
|
* @param time When the player should start.
|
|
254
277
|
* @param offset The offset from the beginning of the sample to start at.
|
|
255
|
-
* @param duration How long the sample should play. If no duration is given,
|
|
278
|
+
* @param duration How long the sample should play. If no duration is given,
|
|
256
279
|
* it will default to the full length of the sample (minus any offset)
|
|
257
280
|
*/
|
|
258
281
|
restart(time?: Seconds, offset?: Time, duration?: Time): this {
|
|
@@ -318,7 +341,7 @@ export class Player extends Source<PlayerOptions> {
|
|
|
318
341
|
assertRange(this.toSeconds(loopStart), 0, this.buffer.duration);
|
|
319
342
|
}
|
|
320
343
|
// get the current source
|
|
321
|
-
this._activeSources.forEach(source => {
|
|
344
|
+
this._activeSources.forEach((source) => {
|
|
322
345
|
source.loopStart = loopStart;
|
|
323
346
|
});
|
|
324
347
|
}
|
|
@@ -335,7 +358,7 @@ export class Player extends Source<PlayerOptions> {
|
|
|
335
358
|
assertRange(this.toSeconds(loopEnd), 0, this.buffer.duration);
|
|
336
359
|
}
|
|
337
360
|
// get the current source
|
|
338
|
-
this._activeSources.forEach(source => {
|
|
361
|
+
this._activeSources.forEach((source) => {
|
|
339
362
|
source.loopEnd = loopEnd;
|
|
340
363
|
});
|
|
341
364
|
}
|
|
@@ -367,7 +390,7 @@ export class Player extends Source<PlayerOptions> {
|
|
|
367
390
|
}
|
|
368
391
|
this._loop = loop;
|
|
369
392
|
// set the loop of all of the sources
|
|
370
|
-
this._activeSources.forEach(source => {
|
|
393
|
+
this._activeSources.forEach((source) => {
|
|
371
394
|
source.loop = loop;
|
|
372
395
|
});
|
|
373
396
|
if (loop) {
|
|
@@ -399,17 +422,18 @@ export class Player extends Source<PlayerOptions> {
|
|
|
399
422
|
const stopEvent = this._state.getNextState("stopped", now);
|
|
400
423
|
if (stopEvent && stopEvent.implicitEnd) {
|
|
401
424
|
this._state.cancel(stopEvent.time);
|
|
402
|
-
this._activeSources.forEach(source => source.cancelStop());
|
|
425
|
+
this._activeSources.forEach((source) => source.cancelStop());
|
|
403
426
|
}
|
|
404
427
|
|
|
405
428
|
// set all the sources
|
|
406
|
-
this._activeSources.forEach(source => {
|
|
429
|
+
this._activeSources.forEach((source) => {
|
|
407
430
|
source.playbackRate.setValueAtTime(rate, now);
|
|
408
431
|
});
|
|
409
432
|
}
|
|
410
433
|
|
|
411
434
|
/**
|
|
412
|
-
* If the buffer should be reversed
|
|
435
|
+
* If the buffer should be reversed. Note that this sets the underlying [[ToneAudioBuffer.reverse]], so
|
|
436
|
+
* if multiple players are pointing at the same ToneAudioBuffer, they will all be reversed.
|
|
413
437
|
* @example
|
|
414
438
|
* const player = new Tone.Player("https://tonejs.github.io/audio/berklee/chime_1.mp3").toDestination();
|
|
415
439
|
* player.autostart = true;
|
|
@@ -432,7 +456,7 @@ export class Player extends Source<PlayerOptions> {
|
|
|
432
456
|
dispose(): this {
|
|
433
457
|
super.dispose();
|
|
434
458
|
// disconnect all of the players
|
|
435
|
-
this._activeSources.forEach(source => source.dispose());
|
|
459
|
+
this._activeSources.forEach((source) => source.dispose());
|
|
436
460
|
this._activeSources.clear();
|
|
437
461
|
this._buffer.dispose();
|
|
438
462
|
return this;
|
package/Tone/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version: string = "14.8.
|
|
1
|
+
export const version: string = "14.8.35";
|