hey, im trying to digest an issue with a block of code and I have already spotted some of its problems but its difficult for me to share a simplified code example showing them all, so im trying to get there one by one.
The first problem is, Im declaring a function called ~makeMLP
with creates an Environment and Im passing an array of parameter keys to this function. Inside the Environment should be a buffer allocated with the number of frames i have values for my keys im passing.
If these would just be single key value pairs, i could use params.size
, but i would also like to pass array NamedControls
.
so take this test SynthDef with array NamedControls:
(
SynthDef(\test, {
var freqRange = \freqRange.kr([2500, 3500], spec: ControlSpec(100, 8000));
var ringRange = \ringRange.kr([0.1, 0.15], spec: ControlSpec(0.1, 2.0));
var ampRange = \ampRange.kr([0.1, 0.2], spec: ControlSpec(0.1, 1.0));
var sig = Splay.ar(
Array.fill(3, {
Ringz.ar(
Dust.ar(\dens.kr(5, spec: ControlSpec(1, 10))),
exprand(freqRange[0], freqRange[1]),
exprand(ringRange[0], ringRange[1]),
exprand(ampRange[0], ampRange[1])
)
})
).distort;
sig = sig * \amp.kr(0.5, spec: ControlSpec(0, 1));
Out.ar(\out.kr(0), sig);
}).add;
)
declare the simplified ~makeMLP
function
(
~makeMLP = { |synthDefName, params|
Environment.make { |self|
~synthDef = SynthDescLib.global[synthDefName].def ?? {
Error("SynthDef '%' not found".format(synthDefName)).throw
};
~params = params;
if (params.isNil or: params.isEmpty) {
Error("MLP: pass a non-empty array of parameter names to be controlled, % was given.".format(params)).throw
};
~nodeProxy = NodeProxy.audio(s, 2);
~nodeProxy.prime(~synthDef);
~getParamNums = { |self|
self.params.collect{ |param|
var val;
val = self.nodeProxy.get(param);
if (val.isArray) { val.size } { 1 };
}.sum;
};
~bufParams = Buffer.alloc(s, self.getParamNums);
}.know_(true);
};
)
and pass an array of keys to the function, where some of the keys have a corresponding array of values:
(
x = ~makeMLP.(\test,
params: [
\freqRange,
\ringRange,
\ampRange,
\dens,
],
);
)
i have created this ~getParamNums
method, which cannot be evaluated in the Environment and also probably could be written in an easier way. for this specific example it should create a buffer with 7 frames. do you have some ideas on that? thanks