Literally just yesterday: MIDI cc values as array index for Array.fill
I suppose we need to implement a way to fake a variable array size and then document it. This is an extremely popular question.
Fixed structure. Think a bit what it takes to build a SynthDef.
- Assemble UGen objects, with relationships expressed through each UGen’s
inputs
array. - Optimize: Math operator substitution. Remove dead units (pure-functional UGens that never reach an output unit may be deleted).
- Sort into optimal order.
- Encode into the binary format that the server understands.
If you had an array of 10 signals and you want it to change dynamically to an array of 12 signals, then: at step 1 there are now more UGens. Therefore all subsequent steps need to be reevaluated. There is no way to skip steps here. Even changing an array size by 1 means you are all the way back to the beginning.
For large SynthDefs, this can take even a couple hundred milliseconds. So what if you sent your s_new message with a latency-timestamp for 200ms from now, but the server needs 250ms to rebuild the SynthDef? That’s right… “late.” And there is no way to guarantee this won’t happen.
Even worse: you start with size = 3 and later set x.set(\size, 12000)
– now the server has at most one hardware buffer of time to do potentially >100 ms of work. It’s impossible.
Well, there is one way to guarantee that you never get into that situation: to disallow it. Build SynthDefs in the language as fixed structures, transmit them to the server as fixed structures, and the server has no power to alter the structure. That’s how SC does it.
Array sizes, array indexing, and conditionals are all things to watch out for.
hjh