make sure that maxDelay is readonly

This commit is contained in:
Yotam Mann 2019-12-10 23:34:12 -05:00
parent cf8965f921
commit 61cfd3ab8c

View file

@ -1,5 +1,5 @@
import { Param } from "../context/Param"; import { Param } from "../context/Param";
import { Time } from "../type/Units"; import { Seconds, Time } from "../type/Units";
import { optionsFromArguments } from "../util/Defaults"; import { optionsFromArguments } from "../util/Defaults";
import { readOnly } from "../util/Interface"; import { readOnly } from "../util/Interface";
import { ToneAudioNode, ToneAudioNodeOptions } from "./ToneAudioNode"; import { ToneAudioNode, ToneAudioNodeOptions } from "./ToneAudioNode";
@ -18,10 +18,9 @@ export class Delay extends ToneAudioNode<DelayOptions> {
readonly name: string = "Delay"; readonly name: string = "Delay";
/** /**
* The maximum delay time. This cannot be changed after * Private holder of the max delay time
* the value is passed into the constructor.
*/ */
readonly maxDelay: Time; private _maxDelay: Seconds;
/** /**
* The amount of time the incoming signal is delayed. * The amount of time the incoming signal is delayed.
@ -47,7 +46,7 @@ export class Delay extends ToneAudioNode<DelayOptions> {
const options = optionsFromArguments(Delay.getDefaults(), arguments, ["delayTime", "maxDelay"]); const options = optionsFromArguments(Delay.getDefaults(), arguments, ["delayTime", "maxDelay"]);
const maxDelayInSeconds = this.toSeconds(options.maxDelay); const maxDelayInSeconds = this.toSeconds(options.maxDelay);
this.maxDelay = Math.max(maxDelayInSeconds, this.toSeconds(options.delayTime)); this._maxDelay = Math.max(maxDelayInSeconds, this.toSeconds(options.delayTime));
this._delayNode = this.input = this.output = this.context.createDelay(maxDelayInSeconds); this._delayNode = this.input = this.output = this.context.createDelay(maxDelayInSeconds);
@ -56,6 +55,8 @@ export class Delay extends ToneAudioNode<DelayOptions> {
param: this._delayNode.delayTime, param: this._delayNode.delayTime,
units: "time", units: "time",
value: options.delayTime, value: options.delayTime,
minValue: 0,
maxValue: this.maxDelay,
}); });
readOnly(this, "delayTime"); readOnly(this, "delayTime");
@ -68,6 +69,14 @@ export class Delay extends ToneAudioNode<DelayOptions> {
}); });
} }
/**
* The maximum delay time. This cannot be changed after
* the value is passed into the constructor.
*/
get maxDelay(): Seconds {
return this._maxDelay;
}
/** /**
* Clean up. * Clean up.
*/ */