mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 02:58:32 +00:00
account for phase complete
This commit is contained in:
parent
dec039ead3
commit
5671b40707
@ -4,7 +4,11 @@ import { clamp } from './util.mjs';
|
|||||||
const setRelease = (param, phase, sustain, startTime, endTime, endValue, curve = 'linear') => {
|
const setRelease = (param, phase, sustain, startTime, endTime, endValue, curve = 'linear') => {
|
||||||
const ctx = getAudioContext();
|
const ctx = getAudioContext();
|
||||||
const ramp = curve === 'exponential' ? 'exponentialRampToValueAtTime' : 'linearRampToValueAtTime';
|
const ramp = curve === 'exponential' ? 'exponentialRampToValueAtTime' : 'linearRampToValueAtTime';
|
||||||
if (param.cancelAndHoldAtTime == null) {
|
// if the decay stage is complete before the note event is done, we don't need to do anything special
|
||||||
|
if (phase < startTime) {
|
||||||
|
param.setValueAtTime(sustain, startTime);
|
||||||
|
param[ramp](endValue, endTime);
|
||||||
|
} else if (param.cancelAndHoldAtTime == null) {
|
||||||
//this replicates cancelAndHoldAtTime behavior for Firefox
|
//this replicates cancelAndHoldAtTime behavior for Firefox
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
//sustain at current value
|
//sustain at current value
|
||||||
@ -15,9 +19,7 @@ const setRelease = (param, phase, sustain, startTime, endTime, endValue, curve =
|
|||||||
param[ramp](endValue, endTime);
|
param[ramp](endValue, endTime);
|
||||||
}, (startTime - ctx.currentTime) * 1000);
|
}, (startTime - ctx.currentTime) * 1000);
|
||||||
} else {
|
} else {
|
||||||
if (phase < startTime) {
|
//stop the envelope, hold the value, and then set the release stage
|
||||||
param.setValueAtTime(sustain, startTime);
|
|
||||||
}
|
|
||||||
param.cancelAndHoldAtTime(startTime);
|
param.cancelAndHoldAtTime(startTime);
|
||||||
param[ramp](endValue, endTime);
|
param[ramp](endValue, endTime);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user