mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 00:27:58 +00:00
every class calls super.dispose()
makes sure that things don't get disposed twice, which seems to be a common source of issues
This commit is contained in:
parent
fde2ff65eb
commit
60a63cacf8
13 changed files with 26 additions and 5 deletions
|
@ -91,6 +91,7 @@ export class Volume extends ToneAudioNode<VolumeOptions> {
|
|||
* clean up
|
||||
*/
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this.input.dispose();
|
||||
this.volume.dispose();
|
||||
return this;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -272,6 +272,7 @@ extends ToneWithContext<ClockOptions> implements Emitter<ClockEvent> {
|
|||
* Clean up
|
||||
*/
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this.context.off("tick", this._boundLoop);
|
||||
this._tickSource.dispose();
|
||||
this._state.dispose();
|
||||
|
|
|
@ -337,6 +337,7 @@ export class TickSource<Type extends "bpm" | "hertz"> extends ToneWithContext<Ti
|
|||
* Clean up
|
||||
*/
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this._state.dispose();
|
||||
this._tickOffset.dispose();
|
||||
this.frequency.dispose();
|
||||
|
|
|
@ -372,6 +372,7 @@ export class Context extends Emitter<"statechange" | "tick"> 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());
|
||||
|
|
|
@ -183,15 +183,15 @@ implements AbstractParam<Type> {
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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<Type> {
|
|||
}
|
||||
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this._events.dispose();
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -154,6 +154,7 @@ export class ToneAudioBuffer extends Tone {
|
|||
* clean up
|
||||
*/
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this._buffer = undefined;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -249,6 +249,7 @@ extends ToneWithContext<Options> {
|
|||
* Dispose and disconnect
|
||||
*/
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
if (isDefined(this.input)) {
|
||||
if (isArray(this.input)) {
|
||||
this.input.forEach(input => {
|
||||
|
|
|
@ -95,6 +95,7 @@ export class Draw extends ToneWithContext<ToneWithContextOptions> {
|
|||
}
|
||||
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this._events.dispose();
|
||||
cancelAnimationFrame(this._animationFrame);
|
||||
return this;
|
||||
|
|
|
@ -117,6 +117,7 @@ export class Emitter<EventType extends string = string> extends Tone {
|
|||
* Clean up
|
||||
*/
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this._events = undefined;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -367,6 +367,7 @@ export class Timeline<GenericEvent extends TimelineEvent> extends Tone {
|
|||
* Clean up.
|
||||
*/
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this._timeline = [];
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -288,6 +288,7 @@ export abstract class Source<Options extends SourceOptions> extends ToneAudioNod
|
|||
* Clean up.
|
||||
*/
|
||||
dispose(): this {
|
||||
super.dispose();
|
||||
this.unsync();
|
||||
this._volume.dispose();
|
||||
this._state.dispose();
|
||||
|
|
Loading…
Reference in a new issue