From 25004d2b2ff682e610efec69f5bd758b1daa0556 Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Mon, 18 Nov 2019 14:48:24 -0500 Subject: [PATCH] fixing typo, and cancelling events before next one is added --- Tone/source/buffer/Player.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Tone/source/buffer/Player.ts b/Tone/source/buffer/Player.ts index 6b8744eb..1e91b7de 100644 --- a/Tone/source/buffer/Player.ts +++ b/Tone/source/buffer/Player.ts @@ -183,16 +183,16 @@ export class Player extends Source { } // compute the values in seconds - let comptuedOffset = this.toSeconds(offset); + let computedOffset = this.toSeconds(offset); // if it's synced, it should factor in the playback rate for computing the offset if (this._synced) { - comptuedOffset *= this._playbackRate; + computedOffset *= this._playbackRate; } // compute the duration which is either the passed in duration of the buffer.duration - offset const origDuration = duration; - duration = defaultArg(duration, Math.max(this._buffer.duration - comptuedOffset, 0)); + duration = defaultArg(duration, Math.max(this._buffer.duration - computedOffset, 0)); let computedDuration = this.toSeconds(duration); // scale it by the playback rate @@ -216,6 +216,8 @@ export class Player extends Source { // set the looping properties if (!this._loop && !this._synced) { + // cancel the previous stop + this._state.cancel(startTime + computedDuration); // if it's not looping, set the state change at the end of the sample this._state.setStateAtTime("stopped", startTime + computedDuration, { implicitEnd: true, @@ -227,10 +229,10 @@ export class Player extends Source { // start it if (this._loop && isUndef(origDuration)) { - source.start(startTime, comptuedOffset); + source.start(startTime, computedOffset); } else { // subtract the fade out time - source.start(startTime, comptuedOffset, computedDuration - this.toSeconds(this.fadeOut)); + source.start(startTime, computedOffset, computedDuration - this.toSeconds(this.fadeOut)); } } @@ -274,11 +276,11 @@ export class Player extends Source { seek(offset: Time, when?: Time): this { const computedTime = this.toSeconds(when); if (this._state.getValueAtTime(computedTime) === "started") { - const comptuedOffset = this.toSeconds(offset); + const computedOffset = this.toSeconds(offset); // if it's currently playing, stop it this._stop(computedTime); // restart it at the given time - this._start(computedTime, comptuedOffset); + this._start(computedTime, computedOffset); } return this; }