Done Action Pause - is there a way to unpause?

The scenario is that I’ve got a synth connected to an envelope synth. When a midi note-off message is received I want to trigger the release on the envelope, so I set gate to 0. With a doneAction: 2 it frees up the envelope which isn’t what I want. What I want is that the envelope triggers the release and restarts when a new note-on event is received. The only option appears to be doneAction: 1, but I don’t see any way to unpause the envelope once it is paused. Am I just going about this the wrong way altogether?

If you set the doneAction to 0 (the default), then you can retrigger the envelope again and again.
See this example from SC help for EnvGen:

// using a gated envelope to gate a sound:
(
SynthDef(\env_help, { | out, gate = 0, freq = 440, doneAction = 0 |
    var z = EnvGen.kr(Env.adsr, gate, doneAction: doneAction) * SinOsc.ar(freq, 0, 0.1);
    Out.ar(out, z)
}).add;
)
​
a = Synth(\env_help);
​
​
// turn on
a.set(\gate, 1);
​
// turn off
a.set(\gate, 0);
​
// it does not matter to what value the gate is set, as long as it is > 0
a.set(\gate, 2);
​
a.set(\doneAction, 2, \gate, 0); // set doneAction to two to let the synth free itself
​
a.free; // alternatively, free it directly.

Best,
Paul

What Paul said is right, but to answer your question you can use synth.run(true) and set the gate to 1 at the same time.

Sam

Thanks! Paul’s suggestion did exactly what I was looking for, but I’m happy to gain knowledge where I get it.