Get standard arguments of a synthdef as a dictionary or array?

Hello, i want to get the standard arguments as pairs/array or dictionary or from a synth def.
Lets say i have this SynthDef:

(
SynthDef(\test_synth,{
	|amp = 0.3, freq = 220, rel = 1|
	Out.ar(0,SinOsc.ar(freq!2)*Line.kr(amp,0,rel,doneAction:2));
}).add;
)

Synth(\test_synth)

Then i want a function or method that gives me [\amp, 0.3, \freq, 220, \rel, 1] or something similar. The arguments might also be initialized in the synthdef by \amp.kr(0.3) or something.

Is this possible somehow? It would help me out a lot.
Thank you!

Like this!

SynthDescLib.at(\test_synth).controlDict.collect(_.defaultValue)
4 Likes

Thank you very much, especially for the quick response, keeps me coding (:

Your welcome!
Take a peek at SynthDesc and ControlName if you want to see why this works.
J

1 Like

Interesting, I didn’t know you could just do .at directly with the Synth name, I thought you had to go through the \global SynthDescLib. Anyhow, I did something similar (maybe with a bit fancier output, and including things like lag info) for Bacalao:

is there a way to do this without writing a synthdef? could I all the parameters in a function?

Yes, take a look at the documentation for FunctionDef. As a quick example, you can get the argument names as an array with {...}.def.argNames

thanks! Do you know if there is any way to get it to work with the named control method?

(~a={|freq=100|SinOsc.ar(freq,0,0.01)})
~a.def.argNames

(~a={SinOsc.ar(\freq.kr(100),0,0.01)})
~a.def.argNames

NamedControls are not function arguments, so they are not visible as function argument names.

That’s why the initial suggestion was to go through the SynthDesc – because the SynthDesc reports all controls, whether they were created from function arguments or NamedControl.

hjh

FYI: when you call {...some function...}.play it converts it to a synthdef behind the scenes.

I always figured that the temp synth def that playing a function creates was not really “cataloged” or stored in the same way a synthdef(\symbol).add is? Thus, not accessible through SynthDescLib?

Yes you are right, Synthdef(...).add will catalogue it with SynthDescLib whereas Function.play doesn’t do this as it is considered a temporary. I only mentioned it because your initial question sounded like you wanted to avoid SynthDefs entirely — which isn’t possible —, and it might not be obvious to some that Function.play is just a wrapper around SynthDef.