mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 16:48:00 +00:00
searches for envelope position in attack curve
This commit is contained in:
parent
217ecf7369
commit
49768eb658
1 changed files with 9 additions and 7 deletions
|
@ -250,13 +250,15 @@ define(["Tone/core/Tone", "Tone/signal/Signal",
|
||||||
} else if (attack > 0){
|
} else if (attack > 0){
|
||||||
this._sig.cancelAndHoldAtTime(time);
|
this._sig.cancelAndHoldAtTime(time);
|
||||||
var curve = this._attackCurve;
|
var curve = this._attackCurve;
|
||||||
//take only a portion of the curve
|
//find the starting position in the curve
|
||||||
if (attack < originalAttack){
|
for (var i = 1; i < curve.length; i++){
|
||||||
var percentComplete = 1 - attack / originalAttack;
|
//the starting index is between the two values
|
||||||
var sliceIndex = Math.floor(percentComplete * this._attackCurve.length);
|
if (curve[i-1] <= currentValue && currentValue <= curve[i]){
|
||||||
curve = this._attackCurve.slice(sliceIndex);
|
curve = this._attackCurve.slice(i);
|
||||||
//the first index is the current value
|
//the first index is the current value
|
||||||
curve[0] = currentValue;
|
curve[0] = currentValue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this._sig.setValueCurveAtTime(curve, time, attack, velocity);
|
this._sig.setValueCurveAtTime(curve, time, attack, velocity);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue