Manipulate Patterns with Ndefs?

Hello everybody.

I am curious of how I could adresse some arguments of a Synth, which is created by a pattern, which is embedded in an Ndef. By using the arguments, ‘.set’ or ‘.gui’ of the Ndef. Maybe I’m also looking for a more favorable way of writing this kind of things, such as using the Pattern to trigger a Ndef of a Synth. But I’m yet not sure how to archieve this properly.

However here is my example code, and basically I’m looking for a way to change the \amp or \freq, since its not addressed in the pattern, this should be possible with an Ndef.

(
//simple Synth and Pdef
SynthDef(\sins,{|out=0,freq=440,amp=0.3|Out.ar(out,amp*SinOsc.ar(freq!2)*Line.kr(1,0,0.2,doneAction:2))}).add;
Pdef(\ptrn,Pbind(\instrument,\sins));
)
//starting the Ndef of a pattern
Ndef(\fdsa)[0]=Pdef(\ptrn)
Ndef(\fdsa).play
//how to address the amp or the frequency?
Ndef(\fdsa).gui

Thank you very much.

I’m not 100% sure what you’re trying to do, but it seems like Node Proxy Roles might be helpful.

You can use a pattern to set arguments of an Ndef like so:

(
Ndef(\a, {
|freq = 440|

SinOsc.ar(freq + [0,1]) * -10.dbamp;
}).play;
)

Ndef(\a)[1] = \set -> Pbind(\dur, 3, \freq, Pwhite(100, 800))

Hope this helps. @madskjeldgaard has a nice tutorial about this too.

If you’re only worried about setting unaddressed arguments to fixed values, you can use:

Ndef(\fdsa).set(\amp, 1.0);

The same set method also works on Pdef. Note that these will only work as “default” values - if e.g. your pattern contains an \amp key, the one you’re .set will not be used.