I’m trying to understand how to use Ndefs in combination with patterns and events to control a SynthDef. I’m new to the Ndef paradigm so this might be an obvious one or just my summer-brain being slow, but i couldn’t find it in the docs.
I really like that you can combine pattern control and plug in Ndef’s as LFO’s directly into the pattern, but i fail to understand why the Ndef(\env)
in this example doesn’t re-trigger on each event:
SynthDef(\syn, {|out, freq, amp, gate = 1, filterFreq = 2700, pan = 0|
var env, sig;
env = EnvGen.kr(Env.adsr(0, 0.1, 0.6, 0.6), gate, doneAction: 2);
sig = RLPF.ar(Saw.ar(freq, amp * env), filterFreq.clip(20, 20000), 0.2);
sig = Pan2.ar(sig, pan);
Out.ar(out, sig);
}).add;
(
Ndef(\x).play(vol: 1.0);
Ndef(\lfo, {|lfoFreq = 1.5| SinOsc.kr(lfoFreq).exprange(900, 1800)});
Ndef(\env, {|gate = 1, offset = 900| EnvGen.kr(Env.perc(0.01, 0.5, 3600 + offset), gate, 2.0, -0.5, doneAction: 2) + offset});
Pdef(\ptn,
Pbind(
\instrument, \syn,
\degree, Pseq([[0, 2, 5], [-2, 0, 2], [-5, -2, 2]], inf),
\strum, Pwhite(0.02, 0.05),
\mtranspose, Pdup(5, Pseq([0, -2, -5, 2, 0, -2, 5, 2, 3, -3], inf)),
\filterFreq, Pfunc{|ev| Ndef(\lfo).set(\lfoFreq, ev.degree[rrand(0, 2)])},
//\filterFreq, Pfunc{Ndef(\env)}, // how to trigger it?
\dur, Pwhite(0.45, 0.54),
\amp, Pwhite(0.08, 0.15),
\out, Pfunc{Ndef(\x).bus.index},
\group, Pfunc({Ndef(\x).group})
)
).play;
)
Pdef(\ptn).stop;