diff --git a/Tone/component/channel/Volume.ts b/Tone/component/channel/Volume.ts index 439e9f34..df2cd2ee 100644 --- a/Tone/component/channel/Volume.ts +++ b/Tone/component/channel/Volume.ts @@ -91,6 +91,7 @@ export class Volume extends ToneAudioNode { * clean up */ dispose(): this { + super.dispose(); this.input.dispose(); this.volume.dispose(); return this; diff --git a/Tone/core/Tone.ts b/Tone/core/Tone.ts index 99ffe4a0..520c2f32 100644 --- a/Tone/core/Tone.ts +++ b/Tone/core/Tone.ts @@ -32,10 +32,19 @@ export abstract class Tone { */ protected abstract name: string; + /** + * If the instance was already disposed + */ + private _wasDisposed = false; + /** * disconnect and dispose. */ - abstract dispose(): this; + dispose(): this { + this.assert(!this._wasDisposed, "Instance has already been disposed"); + this._wasDisposed = true; + return this; + } /** * Takes a partial options an returns the completed options by filling in the defaults diff --git a/Tone/core/clock/Clock.ts b/Tone/core/clock/Clock.ts index dacce83b..bc67e46a 100644 --- a/Tone/core/clock/Clock.ts +++ b/Tone/core/clock/Clock.ts @@ -272,6 +272,7 @@ extends ToneWithContext implements Emitter { * Clean up */ dispose(): this { + super.dispose(); this.context.off("tick", this._boundLoop); this._tickSource.dispose(); this._state.dispose(); diff --git a/Tone/core/clock/TickSource.ts b/Tone/core/clock/TickSource.ts index b71a5306..5316f61f 100644 --- a/Tone/core/clock/TickSource.ts +++ b/Tone/core/clock/TickSource.ts @@ -337,6 +337,7 @@ export class TickSource extends ToneWithContext implements BaseAudi * Clean up. Also closes the audio context. */ dispose(): this { + super.dispose(); this._ticker.dispose(); this._timeouts.dispose(); Object.keys(this._constants).map(val => this._constants[val].disconnect()); diff --git a/Tone/core/context/Param.ts b/Tone/core/context/Param.ts index f83a3912..94855156 100644 --- a/Tone/core/context/Param.ts +++ b/Tone/core/context/Param.ts @@ -183,15 +183,15 @@ implements AbstractParam { /////////////////////////////////////////////////////////////////////////// setValueAtTime(value: UnitMap[Type], time: Time): this { - time = this.toSeconds(time); + const computedTime = this.toSeconds(time); const numericValue = this._fromType(value); this._events.add({ - time, + time : computedTime, type: "setValue", value: numericValue, }); - this.log("setValue", value, time); - this._param.setValueAtTime(numericValue, time); + this.log("setValue", value, computedTime); + this._param.setValueAtTime(numericValue, computedTime); return this; } @@ -389,6 +389,7 @@ implements AbstractParam { } dispose(): this { + super.dispose(); this._events.dispose(); return this; } diff --git a/Tone/core/context/ToneAudioBuffer.ts b/Tone/core/context/ToneAudioBuffer.ts index 1ae024df..aac05315 100644 --- a/Tone/core/context/ToneAudioBuffer.ts +++ b/Tone/core/context/ToneAudioBuffer.ts @@ -154,6 +154,7 @@ export class ToneAudioBuffer extends Tone { * clean up */ dispose(): this { + super.dispose(); this._buffer = undefined; return this; } diff --git a/Tone/core/context/ToneAudioNode.ts b/Tone/core/context/ToneAudioNode.ts index a8b42f9f..b0add3ed 100644 --- a/Tone/core/context/ToneAudioNode.ts +++ b/Tone/core/context/ToneAudioNode.ts @@ -249,6 +249,7 @@ extends ToneWithContext { * Dispose and disconnect */ dispose(): this { + super.dispose(); if (isDefined(this.input)) { if (isArray(this.input)) { this.input.forEach(input => { diff --git a/Tone/core/util/Draw.ts b/Tone/core/util/Draw.ts index 64950256..97bbf1be 100644 --- a/Tone/core/util/Draw.ts +++ b/Tone/core/util/Draw.ts @@ -95,6 +95,7 @@ export class Draw extends ToneWithContext { } dispose(): this { + super.dispose(); this._events.dispose(); cancelAnimationFrame(this._animationFrame); return this; diff --git a/Tone/core/util/Emitter.ts b/Tone/core/util/Emitter.ts index 549eb84e..5bc6adef 100644 --- a/Tone/core/util/Emitter.ts +++ b/Tone/core/util/Emitter.ts @@ -117,6 +117,7 @@ export class Emitter extends Tone { * Clean up */ dispose(): this { + super.dispose(); this._events = undefined; return this; } diff --git a/Tone/core/util/IntervalTimeline.ts b/Tone/core/util/IntervalTimeline.ts index cf7f831c..8ef9a0fd 100644 --- a/Tone/core/util/IntervalTimeline.ts +++ b/Tone/core/util/IntervalTimeline.ts @@ -337,6 +337,7 @@ export class IntervalTimeline extends Tone { * Clean up */ dispose(): this { + super.dispose(); if (this._root !== null) { this._root.traverse(node => node.dispose()); } diff --git a/Tone/core/util/Timeline.ts b/Tone/core/util/Timeline.ts index 6b87ccac..3bb10203 100644 --- a/Tone/core/util/Timeline.ts +++ b/Tone/core/util/Timeline.ts @@ -367,6 +367,7 @@ export class Timeline extends Tone { * Clean up. */ dispose(): this { + super.dispose(); this._timeline = []; return this; } diff --git a/Tone/source/Source.ts b/Tone/source/Source.ts index 04fe7bf5..d1e5c068 100644 --- a/Tone/source/Source.ts +++ b/Tone/source/Source.ts @@ -288,6 +288,7 @@ export abstract class Source extends ToneAudioNod * Clean up. */ dispose(): this { + super.dispose(); this.unsync(); this._volume.dispose(); this._state.dispose();