mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 00:27:58 +00:00
small optimization to avoid setting the same value twice
happens sometimes on initialization
This commit is contained in:
parent
3a3d563c6e
commit
3208497102
1 changed files with 8 additions and 2 deletions
|
@ -103,8 +103,8 @@ implements AbstractParam<Type> {
|
|||
}
|
||||
set value(value: Type) {
|
||||
this._initialValue = this._fromType(value);
|
||||
this.cancelScheduledValues(this.now());
|
||||
this.setValueAtTime(value, this.now());
|
||||
this.cancelScheduledValues(0);
|
||||
this._param.value = this._fromType(value);
|
||||
}
|
||||
|
||||
get minValue(): number {
|
||||
|
@ -188,6 +188,12 @@ implements AbstractParam<Type> {
|
|||
this.assert(isFinite(numericValue) && isFinite(computedTime),
|
||||
`Invalid argument(s) to setValueAtTime: ${JSON.stringify(value)}, ${JSON.stringify(time)}`);
|
||||
|
||||
const currentEvent = this._events.get(computedTime);
|
||||
// if there's already the same event, don't bother adding this one
|
||||
if (currentEvent && currentEvent.time === computedTime &&
|
||||
currentEvent.type === "setValue" && currentEvent.value === numericValue) {
|
||||
return this;
|
||||
}
|
||||
this.log(this.units, "setValue", value, computedTime);
|
||||
this._events.add({
|
||||
time: computedTime,
|
||||
|
|
Loading…
Reference in a new issue