Addressing Array as argument in SynthDef

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Addressing Array as argument in SynthDef

Matthias Kispert
I have some code that works but is very long, and I'm looking for a way to rein it in. One thing I'm stuck at is addressing elements in an Array that's an argument in a SynthDef. With what I have now, every time I move a slider, I get the error: Message 'at' not understood.
Maybe there's another way of achieving what I'm looking for.

The patch has 8 output channels, and each one of these has 6 MidEQ filters controlled via a GUI.

w = Window.new("test", Rect(200,200,1000,1000)).front;
e = View.new(w, Rect(10,250,1000,1000));  
e.decorator = FlowLayout(e.bounds);

~gcontrol = ControlSpec(-36,36,\lin,0.01,0,'dB');
~qcontrol = ControlSpec(1, 10, \lin, 0.01, 0.01);

for (0, 5, {arg i;
        ~eq_f_sl[i] = EZSlider(e,
                300@42,
                "EQ"++(i+1)++" freq",
                \freq,
                unitWidth:30,
                numberWidth:60,
                layout:\line2,
                margin: m,
                action: {|ez|
                        for (0, 7, {arg j;
                                ~outputs[j].set(\freq[i], ez.value);
                        });
        });
       
        ~eq_db_sl[i] = EZSlider(e,
                300@42,
                "EQ"++(i+1)++" gain",
                ~gcontrol,
                unitWidth:30,
                numberWidth:60,
                layout:\line2,
                margin: m,
                action: {|ez|
                        for (0, 7, {arg j;
                                ~outputs[j].set(\db[i], ez.value);
                        });
        });
       
        ~eq_q_sl[i] = EZSlider(e,
                300@42,
                "EQ"++(i+1)++" q",
                ~qcontrol,
                unitWidth:30,
                numberWidth:60,
                layout:\line2,
                margin: m,
                action: {|ez|
                        for (0, 7, {arg j;
                                ~outputs[j].set(\q[i], ez.value);
                        });
        });
});

SynthDef.new (\eq, {
        arg in, out, amp=0.5, freq = #[440, 440, 440, 440, 440, 440], db = #[0, 0, 0, 0, 0, 0], q = #[1, 1, 1, 1, 1, 1];
        var sig, rq = Array. newClear(6);
        sig = In.ar(in, 1);
        for (0, 5, {arg i;
                rq[i] = q[i];
        });
        sig = MidEQ.ar(sig, freq[0], rq[0], db[0], amp);
        sig = MidEQ.ar(sig, freq[1], rq[1], db[1], 1);
        sig = MidEQ.ar(sig, freq[2], rq[2], db[2], 1);
        sig = MidEQ.ar(sig, freq[3], rq[3], db[3], 1);
        sig = MidEQ.ar(sig, freq[4], rq[4], db[4], 1);
        sig = MidEQ.ar(sig, freq[5], rq[5], db[5], 1);
        sig = Limiter.ar(sig, 1, 0.01);
        Out.ar(out, sig);
}).add;

~outputs = Array.newClear(8);                                    
for (0, 7, { arg i;
        ~outputs[i] = Synth.new(\eq, [
                \in, i+16,                                                  
                \out, i                                                    
        ]);
});
Loading...