searches for envelope position in attack curve

This commit is contained in:
Yotam Mann 2018-05-28 17:59:31 -04:00
parent 217ecf7369
commit 49768eb658

View file

@ -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);
} }