I’m trying to control the number of times a “do” loop is run in a SynthDef. I set an arg “passes” to do the looping.
If I hard code a “4.do” I get the result I expect.
( SynthDef( \test, {|out=0,passes=4|
var sig=0,i;
4.do { |i|
sig = sig + SinOsc.ar(200*i,0,0.05);
};
Out.ar(out,sig)
}).play
)
This is a very frequently asked question! It’s quite a subtle aspect of Sc. I’m not sure the best place to point you, certainly someone else will know better, but perhaps this as a starting point?
I think I get it. I’m guessing when a Synthdef is sent to the server, a static collection of commands is constructed. If I put in a “10.do”, 10 copies of the enclosed function are instanced on the server. This can’t change.
Correct. Luckily in many cases it’s still possible to get what you want by replacing one synth with another while it’s running. Take a look at the help for the Ndef class.