mirror of
https://github.com/Tonejs/Tone.js
synced 2025-01-14 04:43:54 +00:00
better fix for #912 by stopping only the most recently created source on player.restart(); reverting prior fix attempt which didn't address all possible cases adequately
This commit is contained in:
parent
6700a3c5f5
commit
05a4ef7cf2
2 changed files with 3 additions and 4 deletions
|
@ -168,8 +168,7 @@ export abstract class OneShotSource<
|
|||
|
||||
// schedule the stop callback
|
||||
this._stopTime = this.toSeconds(time) + fadeOutTime;
|
||||
const nowTime = this.now();
|
||||
this._stopTime = Math.max(this._stopTime, nowTime);
|
||||
this._stopTime = Math.max(this._stopTime, this.now());
|
||||
if (fadeOutTime > 0) {
|
||||
// start the fade out curve at the given time
|
||||
if (this._curve === "linear") {
|
||||
|
@ -189,7 +188,7 @@ export abstract class OneShotSource<
|
|||
this._curve === "exponential" ? fadeOutTime * 2 : 0;
|
||||
this._stopSource(this.now() + additionalTail);
|
||||
this._onended();
|
||||
}, this._stopTime - nowTime);
|
||||
}, this._stopTime - this.context.currentTime);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ export class Player extends Source<PlayerOptions> {
|
|||
}
|
||||
|
||||
protected _restart(time?: Seconds, offset?: Time, duration?: Time): void {
|
||||
this._stop(time);
|
||||
[...this._activeSources].pop()?.stop(time); // explicitly stop only the most recently created source, to avoid edge case when > 1 source exists and _stop() erroneously sets all stop times past original end offset
|
||||
this._start(time, offset, duration);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue