Hi there -
I am trying to understand how to manage synths a little better, but I’m a little confused about something.
I can collect 10 sine wave generators an array. ~array = 10.collect{{SinOsc.ar(800.rand, 0, 0.1)}.play};
But, in order to free them all, do I need to iterate through the list and take them out one-by-one, like this?
~array.do{|x|
x.free;
x.release;
};
Even if I do this, my ~array still has all of these items in it. So, do I also need this at the end, in order to start again with a clean slate? ~array = [];
Yes, that’s correct. Sc has no concept of a destructor so the disconnected server representation will always hang around. That being said, you can just override them with new synths.
Alternatively, you can put Synths into a group and free / release the whole group. That’s practical in many contexts, maybe overcomplicated here. You can also use partial application:
~array.do(_.release)
Other than that, you can take also produce the multitude of SinOscs inside the SynthDef and sum or mix to stereo with Splay.
I often use a List instead of an Array, which allows you to ~list.pop.stop one or all of your Synths, and the size of the List will stay aligned with how many Synths are in it. To stop and remove them all, use ~list.size.do{ ~list.pop.stop }.
EDIT: Just to clarify, I was using .stop here because these were Pbinds, but you would use .free for Synths!