Just confirming, is it a gated envelope?
If you know the duration that the envelope should be closed to new triggers, you can measure the time using
Sweep.kr(trig, 1) (or
.ar) – if it’s a gated envelope, then the timer should start when releasing, so
Sweep.kr(gate <= 0, 1).
So the “gate mask” would be:
- Triggered envelope:
Sweep.kr(trig, 1) > totalEnvDuration;
- Gated envelope:
Sweep.kr(gate <= 0, 1) > releaseDuration.
But you’ll need another condition for the first one, so I guess it’ll be like this (untested), for a trigger:
// in the SynthDef
arg ......., t_trig, ......;
var trigMask = ((PulseCount.kr(trig) < 0) + (Sweep.kr(trig, 1) > totalDur)) > 0,
eg = EnvGen.kr(env..., t_trig * trigMask, ...);
+ is a logical-or here, and
* is logical-and: the trigger will be passed (“and true”) if it’s never been triggered before or enough time has passed, and suppressed (“and false”) otherwise.
That’s a good way to do it. LocalIn/Out delay should be on the order of 1.5 ms only. I’d expect DetectSilence to be too slow for this purpose: why not just
eg <= 0?