Passing Array Values to Synth

I am currently working on a project where I’m attempting to pass values from an array to a synth. I’ve created a simple example, but I’m encountering some issues.

Below is a simplified version of the code:

// Define the synth
SynthDef(\sineSynth, {|out = 0, freq = 300, amp = 0.5|
    var src;
    src = SinOsc.ar(freq);
    Out.ar(out, src * amp);
}).add;

// Example array with key-value pairs
~arrayA = [
    [0.2, [\freq, 700]],
    [0.4, [\freq, 500, \amp, 0.2]],
    [0.5, [\freq, 900]],
    [0.7, [\freq, 600, \amp, 0.7]],
];


~synthA = Synth(\sineSynth, [\out, 0]);

// Attempting to set parameters from the array
~synthA.set(~arrayA.[0].[1])

The goal here is to pass frequency (\freq) and amplitude (\amp) values etc from the array to the synth. However, the current implementation doesn’t work

I would greatly appreciate any insights or suggestions on how to properly pass values from the array to the synth.

How about this?

~synthA.set(~arrayA[0][1][0], ~arrayA[0][1][1])

or

(
~setSynth = { |aSynth, setValues| 
	(setValues.size / 2).do { |i|
		var thisControlSet = i * 2;
	aSynth.set(setValues[thisControlSet], setValues[thisControlSet + 1]) }
}
)
~setSynth.(~synthA, ~arrayA[0][1])
~setSynth.(~synthA, ~arrayA[1][1])

But what is the floating point number of the first element in each array? If it is the time from the start or the time to the next control, you could configure a different structure…

Use * notation:

~synthA.set( * ~arrayA[0][1])

See Symbolic Notations | SuperCollider 3.12.2 Help

(Also, you don’t need the dots for array indexing.)

hjh

1 Like