Skip to content

Commit

Permalink
feat: Can set the parameter after constructing Param
Browse files Browse the repository at this point in the history
used in the new ToneAudioWorklet node
  • Loading branch information
tambien committed Sep 27, 2019
1 parent f7bdd75 commit 23ca0f9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Tone/core/context/Param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export class Param<Type extends Unit = number>
} as ParamOptions<any>);
}

readonly input: GainNode;

/**
* The input connection
*/
readonly input: AudioParam;
// readonly input: AudioParam;
readonly units: UnitName;
convert: boolean;
overridden: boolean = false;
Expand Down Expand Up @@ -109,8 +111,11 @@ export class Param<Type extends Unit = number>
while (!isAudioParam(options.param)) {
options.param = options.param._param;
}

this.input = this.context.createGain();
// initialize
this._param = this.input = options.param;
this._param = options.param;
this.input.connect(this._param);
this._events = new Timeline<AutomationEvent>(1000);
this._initialValue = this._param.defaultValue;
this.units = options.units;
Expand Down Expand Up @@ -470,6 +475,18 @@ export class Param<Type extends Unit = number>
return this;
}

/**
* Replace the Param's internal AudioParam. Will apply scheduled curves
* onto the parameter and replace the connections.
*/
setParam(param: AudioParam): this {
this.input.disconnect(this._param);
this.apply(param);
this._param = param;
this.input.connect(this._param);
return this;
}

dispose(): this {
super.dispose();
this._events.dispose();
Expand Down

0 comments on commit 23ca0f9

Please sign in to comment.