hey, i was wondering how i get the same behaviour via Pbind with the `passed_Env SynthDef`

compared to the `synthDef_Env SynthDef`

and how to approach this topic in general. any other advices? thanks

```
(
// create a new event type called hasEnv
// which checks every parameter whose key ends in Env or env:
// - convert non-env values to envs (e.g 0 becomes Env([0,0],[dur]))
// - stretch envelope to last for the event's sustain (converted from beats to seconds)
~utils = ();
~utils.hasEnv = {
// calc this event's duration in seconds
var durSeconds = ~dur * ~legato / thisThread.clock.tempo;
// find all parameters ending in env or Env
var envKeys = currentEnvironment.keys.select{|k|"[eE]nv$".matchRegexp(k.asString)};
envKeys.do{|param|
var value = currentEnvironment[param];
if (value.isArray.not) { value = [value] };
value = value.collect {|v|
// pass rests along...
if (v.isRest) { v } {
// convert non-env values to a continuous, fixed value env
if (v.isKindOf(Env).not) { v = Env([v, v], [1]) }
};
// stretch env's duration
v.duration = durSeconds;
};
currentEnvironment[param] = value;
};
};
Event.addParentType(\hasEnv,(
finish: ~utils[\hasEnv]
));
)
(
SynthDef(\synthDef_Env, {
arg out=0, freq=500, mRatio=1, cRatio=1, index=1, iScale= 5,
amp=0.2, widthMod=1, atk=0.01, rel=3, cAtk=4, cRel=(-4), width=0.25, time=1;
var sig, mod, car;
var iEnv, gainEnv;
iEnv = EnvGen.kr(
Env.new(
[index, index * iScale, index],
[atk, rel],
[cAtk, cRel]
)
);
gainEnv = EnvGen.kr(
Env.perc(atk, rel, curve: [cAtk, cRel]),
doneAction: 2
);
mod = SinOsc.ar(freq * mRatio, mul: iEnv);
car = SinOsc.ar(freq * cRatio, mod.wrap(0, 4pi));
sig = car * gainEnv * amp;
sig = Limiter.ar(sig, 0.95);
sig = LeakDC.ar(sig);
Out.ar(out, sig);
}).add;
)
(
SynthDef(\passed_Env, {
arg t_gate=1, out=0, freq=500, mRatio=1, cRatio=1, index=1, iScale= 5,
amp=0.2, widthMod=1, atk=0.01, rel=3, cAtk=4, cRel=(-4), width=0.25, time=1;
var sig, mod, car;
var gainEnv = \gainEnv.kr(Env.newClear(8).asArray);
var iEnv = \iEnv.kr(Env.newClear(8).asArray);
// freq Envelope
iEnv = EnvGen.kr(iEnv, timeScale:time);
// amp envelope
gainEnv = EnvGen.kr(gainEnv, t_gate, timeScale:time, doneAction:2);
mod = SinOsc.ar(freq * mRatio, mul: iEnv);
car = SinOsc.ar(freq * cRatio, mod.wrap(0, 4pi));
sig = car * gainEnv * amp;
sig = Limiter.ar(sig, 0.95);
sig = LeakDC.ar(sig);
Out.ar(out, sig);
}).add;
)
(
Pdef(\synthDef_Env,
Pbind(
\instrument, \synthDef_Env,
\midinote, Pseq([
Pseq([38,41,48,50],1),
Pseq([43,46,53,58],1),
Pseq([38,41,48,50],1),
Pseq([43,46,58,53],1)
],inf),
\dur, 0.875,
\legato, 0.80,
\atk, 0.01,
//Phase Modulation
\mRatio, 1,
\cRatio, 1,
\index, 1,
\iScale, 5,
\amp, 0.15,
\out, 0,
)
).play;
)
Pdef(\synthDef_Env).stop;
(
Pdef(\passed_Env,
Pbind(
\type, \hasEnv,
\instrument, \passed_Env,
\midinote, Pseq([
Pseq([38,41,48,50],1),
Pseq([43,46,53,58],1),
Pseq([38,41,48,50],1),
Pseq([43,46,58,53],1)
],inf),
\dur, 0.875,
\legato, 0.80,
\atk, 0.01,
\sus, 3,
\time, Pfunc { |ev| ev.use { ~sus.value } / thisThread.clock.tempo },
\gainEnv, Pfunc{|e|
var rel = (1 - e.atk);
var cAtk = exprand(2,4);
var cRel = exprand(-2,-4);
Env([0,1,1,0],[e.atk,e.sus,rel],[cAtk,0,cRel])
},
//Phase Modulation
\mRatio, 1,
\cRatio, 1,
\index, 1,
\iScale, 5,
\iEnv, Pfunc{|e|
var rel = (1 - e.atk);
var cAtk = exprand(2,4);
var cRel = exprand(-2,-4);
Env([e.index, e.index * e.iScale, e.index],[e.atk,rel],[cAtk, cRel])
},
\amp, 0.15,
\out, 0,
\finish, ~utils[\hasEnv]
)
).play;
)
Pdef(\passed_Env).stop;
```