{}.play on a UGen stored in variable?

Hi. This might be very newbie question, but I would really like to know why the second example does not produce sound despite ‘running’ on server.

// works (instance in the plotTree, sound:
c = {SinOsc.ar};
c.play;

// UGen instance in the plotTree, but no sound:
c = SinOsc.ar;
{c}.play;

Does the second example for some reason not create Out.ar? How can I see the precise message sent to server by the second example (that would enable me to debug this question myself)?

1 Like

All UGens must be created within the function.

You can never create the UGen outside the function and reference it within.

hjh

yes, that makes sense.
thank you!

As an add-on: though, from the ugenGraphFunction you can reference to a Function that generates a UGen, which enables nice live-coding options.

https://www.listarc.bham.ac.uk/lists/sc-users-2012/msg22935.html

Right, I had forgotten that:

c = SinOsc.ar;
{c}.play;  // not OK

c = { SinOsc.ar };
// now 'c' is not a UGen
// it's an instruction to create a UGen

{ c.value }.play;  // run the instruction *in* a synth function - OK

{ c }.play;  // also OK

The last one is OK because the function ‘c’ is automatically evaluated, when it’s used as an input to another UGen.

hjh

1 Like

SynthDef*-wrap is another way of injecting functions into SynthDefs - https://doc.sccode.org/Classes/SynthDef.html#*wrap. Not entirely related but I found this far too late when I was learning SC.

2 Likes