# Playing Ndef with a Pbind/def of a synthdef going to a effect

Hello,
I still don’t understand fully how to manipulate the Ndef with all other methods. Generally i have lots of problems understanding Ndef, so I’ll try to formulate some of my struggle here, maybe it can be answered.
Also feel free to improve any of my example code, I wouldn’t know how to optimally write it.

I create a Synth def, and want to embed it into a Ndef. Then the Ndef gives me a reverb as effect. Finally i want to play this Ndef with a pattern. Can be Pbind, Pdef, or something like that. The Playing with the pattern, i didn’t manage to figure out in my methodology. I think it becomes clear from reading the code.

``````//making a SynthDef
(
SynthDef(\sins, {
|freq=440, out = 0|
Out.ar(out,SinOsc.ar(freq!2)*Line.kr(1,0,0.1,0.1,doneAction:2))
)
Synth(\sins);
//refering a Ndef to this SynthDef (?)
Ndef(\sinn).play;
Ndef(\sinn).prime(\sins);
Ndef(\sinn).put(100,\filter -> {arg in; FreeVerb.ar(in)})
Ndef(\sinn).put(0,Ndef(\sinn).source,0,[\freq, 69.midicps]);
//create a pattern
(
x = Pbind(
// \istrument, \sinn, // this doesnt work obviously
\degree, Pseq((0..3), inf)
).play;
)
``````

At this point I need a way to play different Ndefs, i guess with this ‘put’ format. (Btw i couldnt find a documentation for the put method on Ndefs…)

Anyways. Thanks for any solutions!

Also a Bonus question: I was wondering, since i create a chain of effects in this Ndef with the ‘\sins’ SynthDef. Is it somehow possible to route another Synthdef through this chain of effects? Well in this case the chain of effects consists only of 1 effect, the FreeVerb one.

1 Like

Hello,
I think, you can do it like this:

``````//making a SynthDef
(
SynthDef(\sins, {
|freq=440, out = 0|
Out.ar(out,SinOsc.ar(freq!2)*Line.kr(1,0,0.1,0.1,doneAction:2))
)
Synth(\sins);
//refering a Ndef to this SynthDef (?)
Ndef(\sinn).play;
Ndef(\sinn).prime(\sins);
Ndef(\sinn).put(100,\filter -> {arg in; FreeVerb.ar(in)})
Ndef(\sinn).put(0,Ndef(\sinn).source,0,[\freq, 68.midicps]);
//create a pattern
(
Ndef(\sinn).put(101, \xset -> Pbind(
\degree, Pseq((0..3), inf)
))
)

Ndef(\sinn).clear;
``````

\xset is designed to be used with the fadetime method, I dont’t know if it’s relevant for you.
Maybe you’ll find something that feet better to your needs here:
https://doc.sccode.org/Reference/NodeProxy_roles.html

2 Likes

Hey, Thank you very much for responding, this is already helping a lot!

can you tell me however what the argument that you send with 101 in the put is? what does it stand for? I’m guessing its somehow the position in this side chaining effect. if i set it to any number below 100, it also crashes my supercollider.

101 is the number of the slot, you guess it correctly, it’s the position in the chain.
When you do:

``````Ndef(\sinn).put(100,\filter -> {arg in; FreeVerb.ar(in)})
``````

you put an effect on slot number 100, it’s the same but one slot after.
I don’t know why it crashes your SC, if I set it on 99, for example, it is still working here (windows10 & SC 3.11.2).

If I remember well, putting the slot number at `10` or `100` is a good practice because it saves some slots between your source and your effect, or between each element in the audio chain. Your source will always take the first slot, so If you entered `000`, you probably killed your source, which was the first element in the chain.

The practice of numbering things 10 by 10 or 100 by 100 comes from BASIC number lines if I’m correct (keeping spaces for in-between lines of code). Kinda funny to see that it is still used for some niche cases.

Yeah, i thought of it, since it seems like a oversee-able way of adding effects without writing much code and keeping track of all the buses.

hmm i have some problems with this approach. apparently the pbind is killing the effect chain when the dur value is over. ive documented this problem in another thread, but maybe you might have an answer to this?

Here is the documentation of the full problem:

Hello,
the reverb stop abruptly cause the default fadeTime of the role \xset is 0 apparently.

If you try it like this:

``````(
Ndef(\snn).put(101, \xset -> Pbind(
\amp, Pseq([1,0],inf),
\freq, Pif(Pkey(\amp) > 0, 1, \rest),
\dur, Pseq([1.9, 4],inf),
)).fadeTime_(1) // play with this value
)
``````

the reverb isn’t cut.

But again maybe \xset is not the better role for your needs.
Have you check the different NodeProxies roles in the documentation ?

Can someone explain me why this `put` instruction acts like a Ndef re-triggering ? Thanks.

`xset` creates a second node (which is started from its beginning) in order to cross-fade it with the current one playing with the previous values.