I’m not sure to understand correctly what you are trying to achieve.
Is it that on every Pbind event, you wish your Ndef to detect that it must retrigger the envelop ?
Or you want one Pbind controlling the freq and one controlling the open/close of the envelop ?
However, if you want to control everything through Pbinds and given the following two remarks:
-
The principle of the triggers and gates controls is to have a value that raises from non-positive to positive.
-
Instead of writing a Pbind controlling your Ndef you can write this in the Ndef itself. In another slot of the Ndef. So no need to seek for Ndef reference. It is self-referencing.
and not knowing how you want to control your gate, this is a proposition:
(
Ndef(\gateNode).stop.play;
Ndef(\gateNode, {|freq=440, amp=0.5, opened=0|
var sig, env;
// env = EnvGen.kr(Env.adsr,Trig.kr(ggate)); //
env = EnvGen.kr(Env.adsr,opened);
Poll.kr(Impulse.kr(4),opened,"opened");
sig=Pan2.ar(SinOsc.ar(freq).cubed*amp*env);
sig;
}
);
Ndef(\gateNode)[1] = \set -> Pbind(
\dur,Pseq([Pwhite(0.1,2.0,1),Pwhite(0.1,2.0,1)],inf),
\freq, Pdup(2, Pwhite(220,440,inf)),
\opened,Pseq([1,0],inf).poll,
)
)
The key here is that the Pbind will open and close a gate (here called “opened”) by sending alternatively 1 and 0 to the Envelop. Upon reception of a 1 the envelop will be retriggered. Upon reception of a 0, the decay will be activated.
2 \dur
s are computed : one between the \opened=1
and \opened=0
(=how long your envelop will stay opened), one between the \opened=0
and \opened=1
(=how long to wait between the next trigger).
Every values in the Pbind (except the \opened
) are then held for 2 events (the “open” event and the “close” event) with the Pdup(2,...)
in order to avoid having a change of e.g. frequency on the decay of the note.