«A simple bus routing matrix with GUI» by grirgz
on 30 May'16 18:57 in1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
( // init busses (change ?? to !? to init again) ~busses = ~busses ?? { ~matrix_in_count = 8; ~matrix_out_count = 4; ~matrix_ins = ~matrix_in_count.collect({ arg idx; var bus = Bus.audio(s,2); Ndef(\matrix).set(( \in++idx ).asSymbol, bus); bus; }); ~matrix_outs = ~matrix_out_count.collect({ arg idx; var bus = Bus.audio(s,2); Ndef(\matrix).set(( \out++idx ).asSymbol, bus); bus; }); }; // the matrix synth! Ndef(\matrix, { var ins; // Collects inputs in a list // Inside a Synthdef, instead of "arg freq=440", you can use \freq.kr(440) // here we use this system to generate argument names in a loop ins = ~matrix_in_count.collect { arg in_idx; InFeedback.ar(( \in++in_idx ).asSymbol.kr(100), 2); }; // for each output, sum the inputs with a different gain for each ~matrix_out_count.do { arg out_idx; Out.ar(( \out++out_idx ).asSymbol.kr(0), ins.collect({ arg in, in_idx; in * (\gain++in_idx++"_"++out_idx).asSymbol.kr(0) }).sum ); }; }).play; ) // test ( // source Pdef(\pp, Pbind( \instrument, \default, \degree, Prand([0,1,4,3],inf), \dur, 1/Prand([2,4,8],inf), \out, ~matrix_ins[0], \amp, 0.1 )).play; // fxs Ndef(\fx1, { arg freq=200, pan=0, amp=0.1; var sig; sig = InFeedback.ar(~matrix_outs[0], 2); sig = SinOsc.ar(freq) * sig; }).play; Ndef(\fx2, { arg freq=200, pan=0, amp=0.1; var sig; sig = InFeedback.ar(~matrix_outs[1], 2); sig = LFSaw.ar(freq) * sig; }).play; ); // gui ( ~matrix_gui = { var win; var layout; win = Window.new; // generate an array of array representing the knob grid layout = GridLayout.rows(* // top label header [ [ StaticText.new.string_("") ] ++ ~matrix_out_count.collect { arg out_idx; StaticText.new.string_("Out " ++ out_idx) } ] ++ // knobs ~matrix_in_count.collect { arg in_idx; [ StaticText.new.string_("In " ++ in_idx) ] ++ // left label header ~matrix_out_count.collect { arg out_idx; var knob; var key = ( \gain++in_idx++"_"++out_idx ).asSymbol; knob = Knob.new.action_({ arg my; Ndef(\matrix).set(key, my.value) }); knob.value = Ndef(\matrix).get(key); knob; } } ); win.layout = layout; win.front; }; ~matrix_gui.value; // show the gui! )
reception
comments