Hello, I am switching the function of an Ndef programatically, doing something like this
Ndef(\sdm, ~sdmFunc.choose);
Where ~sdmFunc is an array containing various functions with ugens generating sound, and I was wondering if there is a method which can allow me to assign control values to all arguments of my ndef. For example, some pseudo code to elaborate a bit more
Why doesn’t it work to just use Ndef(\sdm).set(<the control values here>) and then you do your switching with Ndef(\sdm, ~sdmFunc.choose)? The control values should automatically map to your synth that comes from the function.
I think this is a question of efficiency. Arguments are not universal in all functions meaning different functions embed different parameters. Without checking first which arguments are inside the function it will mean that each time running just .set will try to change parameters that doesn’t exist imo.
Then, would setting parameters dynamically sort work? Or some macro-like code generation hack? (not tested, it’ s sort of pseudo-code)
// Function to set parameters based on available arguments
~setParams = { |ndef, func|
func.argNames.do { |arg|
if (~specs[arg].notNil) {
ndef.set(arg, ~specs[arg].map(rrand(0.1, 1.0)));
}
};
};
// Switch the Ndef function and set parameters
Ndef(\sdm, {
var func = ~sdmFunc.choose;
~setParams.(Ndef(\sdm), func);
func.value;
});
EDIT: I don’t use much Ndef or specs, but I think referring to Ndef(\sdm, ...), choosing a function that will kind of " pattern match" the elements in~setParams, will set only params that exist in that one function, and avoiding potential errors. Code I posted (not tested, sorry) can have mistakes, but the idea makes sense to me if you want to experiment a little with that.
I wouldn’t care about efficiency too early. If the paramters are set, you don’t need to set them again, new functions pick them up. And if you set a parameter that the synth doesn’t have, it won’t do much harm, and they stay around for a future synth to pick up.
When you need high efficiency, you better use setGroup(<params>), also there you don’t have to care about non-matching control names.
`Yes, that makes sense. I don’t know why I didn’t write this. But I guess that fits what you want in general? If you start exploring code generation, there are a lot of possibilities.
Again, this verges on the off topic, at least as far as the title of the topic goes. Now @smoge what about this: make a new one with this interesting theme of macro-thinking and link back to the current one?
The topic-drifting is much less straining if you do it yourself, but for the others it may feel like someone taking over the steering wheel and driving into the bush. I kind of like it, but only when it is not enforced on others. We should have a special category of topic for that (maybe like the cadavre exquis / code tennis ones).
@julian I only know one other member who ever discussed macros with me in this forum, and he seems to have left. It would make sense otherwise, and I would not feel like I’m “pushing” something into the group. I think I was into the limits of the discussion since the idea was in the air.
(I suspect you misunderstood my sense of humor; I did NOT suggest anything to anyone)
yes, but not yet well defined. It is unclear what should happen with an old setting if you change or even remove the spec from the inside. Also a proxy may have settings that partly have been set with spec, others without.