for some reason i cant get the \degree values with a Pkey(\freq) without crashing sc if i use lists. With single values it works fine. This bothers me for a while but i cant figure it out. Im on 3.12.2
Have a good day!
Post:
Server ‘localhost’ exited with exit code 0.
server ‘localhost’ disconnected shared memory interface
HI,
thank you for the reply. What i do normally is to use \freq2 etc as frequency ratios avoiding the problem.
I think \degree is converted to \freq anyways and the “problem” lies in the conversion.
Putting data into the event (often/usually with Pbind). Pkey evaluates at this stage – so, properly, Pkey should refer only to keys that have already been put into the event as part of the pattern.
Event .play (or really, playAndDelta). \freq, \delta, \amp etc. conversions are done at this stage – after Pkey.
So the first thing is that this pattern design shouldn’t have been expected to work, and the proper solution is to model it a different way so that the pattern calculations don’t depend on future event calculations. Sending frequency ratios and letting the SynthDef multiply Hz * ratio is a good way (I do it myself).
It seems to work for single values because of some last-minute conversion that is done on the argument list, just before sending.
\degree gets a single value, like 0.
Pkey(\freq) finds, in the parent event, the freq function. So \freq2 gets { that function } * 2 which becomes a BinaryOpFunction.
(degree: 0, freq2: a BinaryOpFunction)
Same for freq3.
When playing the event, \freq gets calculated.
The arg list then has [freq: 261.xxxxx, freq2: a BinaryOpFunction, ...].
If needed, the arg list gets multichannel-expanded.
a BinaryOpFunction can’t be sent to the server. So there’s a last pass, just before sending, that loops over the arg list – the main reason is to embed $[ and $] array-enclosure values.
This loop also calls asControlInput on every item. Any Function “asControlInput” evaluates the function. So it’s at this time that you get the concrete freq2 and freq3.
Now the arg list has [key: number, key: number] as expected.
In the array case, step 5 multichannel-expands freqbut – here’s the problem – you don’t have the concrete freq2 and freq3 values (3 for each). So these are not multichannel-expanded – this means, even if the server didn’t crash, you would still get the wrong result. This problem, I don’t think there’s a solution. Multichannel expansion will work only if it has all of the concrete values before final arglist processing. So it will (AFAICS) never be valid to stick a function into an Event when you’re going to need multichannel expansion at play time.
And the crash is because the arglist then looks like:
On second thought – we could move the .asControlInput bit before the multichannel expansion. That would add a cycle through the loop but would get a more intuitive result.
I’ve used “functions-in-events” to “post-resolve” some values that needed preparation in the event type function, but always felt it was a bit fragile. Probably better to avoid it unless there’s really no other way.