Given:
(
a = {
arg t_trig1, t_trig2, t_trig3, t_trig4;
var clock = Impulse.kr([1,2,3,4]);
4.do { |n| SendReply.kr(clock[n],"/eoc/%".format(n+1) ) };
}.play
);`
I can do:
4.do { |n| SendReply.kr(clock[n],"/eoc/%".format(n+1) ) };
Can I do something simliar when defining n-arguments to the function? Like (pseudo-code):
(
a = {
4.do { |n| arg "t_trig%".format(n) };
var clock = Impulse.kr([1,2,3,4]);
4.do { |n| SendReply.kr(clock[n],"/eoc/%".format(n+1) ) };
}.play
);
smoge
3
That’s how the language is. In SCLang, you cannot dynamically generate argument names using string formatting or loops—at least not this way.
The loop inside the SynthDef is quite normal, and it works well in many relatively common situations when designing the synth graph.
1 Like
smoge
4
(
a = {
var trigs = 4.collect { |n|
NamedControl.kr("t_trig" ++ (n+1).asString, 0)
};
4.do { |n|
SendReply.kr(
trig: trigs[n],
cmdName: '/the_answer'
values: [n+1],
replyID: n+1
)
};
}.play
);
OSCFunc({ |msg|
var replyID = msg[2];
var value = msg[3];
"Trigger % fired with value %".format(replyID, value).postln;
}, '/the_answer');
a.set(\t_trig1, 1)
// Trigger 1 fired with value 1.0
1 Like
Yes, that’s what I was driving at (answering the question behind the question, which is about synth inputs).
You’d need NamedControl.tr to mimic the t_
from the first version though.
hjh
2 Likes
Thanks @jamshark70 and @smoge
This is working as I expect it:
4.do { |n| OSCFunc({ |msg| Node.basicNew(s, msg[1]).set("t_trig%".format(n+1).asSymbol, 1) }, "/eoc/%".format(n+1)) };
(
a = {
var clock = Impulse.kr([1,2,3,4]);
var controls = 4.collect { |n| NamedControl.tr("t_trig%".format(n+1) ) };
// Test code
Trig.kr(controls[0]).poll(controls[0], "1");
Trig.kr(controls[1]).poll(controls[1], "2");
Trig.kr(controls[2]).poll(controls[2], "3");
Trig.kr(controls[3]).poll(controls[3], "4");
// End test
4.collect { |n| SendReply.kr(clock[n],"/eoc/%".format(n+1) ) };
}.play
);
1 Like