«MCElectronique.sc» by brianlheim
on 21 May'15 20:23 inMCElectronique.sc (Meta-Composer or Meta-Coder Electronique) is a tool for finding inspiration and humor in random but interesting output. Essentially, the main method .newDef() creates a string that, when .interpret'd, makes a new Synth consisting of a given number of UGens plugged into one another at random (although parameters are clipped within acceptable limits). Other parameters for .newDef() are explained in the comments. Note that while I've tried my best to avoid it, it's still possible to crash or overload the server. Of course, the larger the requested SynthDef, the greater the chance of this happening. Apart from just generating weird sounds, the output code can also be seen as a jumping-off point for further investigation or improvement.
Sample usage: MCElectronique.newDef(100, 8).postln.interpret
I get pretty good results with MCElectronique.newDef(80,8,0.8,0.6,0.3,0.2,true).postln.interpret
Sample output: https://soundcloud.com/brian-heim-experimental/mcelectroniquesc-output-sampler
1 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
// MCElectronique.sc // Idea and code by Brian L Heim (2015) // Summary: a class that outputs randomly generated SynthDefs as strings. // Main method is .newDef() // Example usage: MCElectronique.newDef.postln.interpret; MCElectronique { classvar freq1, freq2, freq3, freq4, freq5, lag, <>dict, <>pureList, binopList; *new { ^super.new; } *init { freq1=[\freq, [1,44100],[200,1600]]; freq2 = [\freq, [1,44100], [22050,44100]]; freq3 = [\freq, [0.0,10.0], [0.0,1.5]]; freq4 = {[freq1, freq3].choose}; freq5 = [\freq, [1,10000], [1,10000]]; lag = [\lagTime, [0.0,1.0],[0.0,1.0]]; // dict is a dictionary mapping UGen classes to lists of their parameters. Each parameter is listed // with low and high bounds. NewDef interprets a single-value entry (like [\freq, 100]) as requiring a default // value. Any paramter can be replaced by a preexisting variable clipped/wrapped/folded to the high and low values. // in [\freq, [1,44100],[200,1600]], the first set of values are the clip range for a UGen input; the second // set of values is the range for random scalar generation. // Certain troublesome UGens like Compander and Limiter, are disabled here. Some chaotic UGens as well, since there // are just so many of them. dict = Dictionary[ AllpassC -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]],[\decaytime,[0,1],[0.1,1]]], AllpassL -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]],[\decaytime,[0,1],[0.1,1]]], AllpassN -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]],[\decaytime,[0,1],[0.1,1]]], Amplitude -> [\in, [\attackTime, [0.0,1],[0.001,0.1]],[\releaseTime,[0.0,1],[0.001,0.1]]], BAllPass -> [\in, [\freq,[1,1000],[1,10000]], [\rq, [0.0001,2],[0.1,0.8]]], BBandPass -> [\in, freq5, [\bw, [0.0001,2],[0.1,1.9]]], BBandStop -> [\in, [\freq, [100,44100],[100,44100]], [\bw, [0.01,2],[0.1,1.9]]], BHiPass -> [\in, freq5, [\rq, [0.01,2],[0.1,0.8]]], BHiShelf -> [\in, freq5, [\rs, [0.01,2],[0.1,1.5]], [\db, [-12,12],[-6,6]]], BLowPass -> [\in, freq5, [\rq, [0.01,2],[0.1,0.8]]], BLowShelf -> [\in, freq5, [\rs, [0.01,2],[0.1,1.5]], [\db, [-12,12],[-6,6]]], BPF -> [\in, freq5, [\rq, [0.0001,2],[0.1,0.8]]], BPeakEQ -> [\in, freq5, [\rs, [0.0001,2],[0.1,1.5]], [\db, [-12,12],[-6,6]]], BRF -> [\in, freq5, [\rq, [0.0001,2],[0.1,0.8]]], Ball -> [\in, [\g, [0.01, 10], [0.1,3]], [\damp, [0.0,1], [0.0,0.5]], [\friction, [0.0,1],[0.01,0.1]]], Blip -> [[\freq, [1,22000], [1,22000]], [\numharm, [1.0,200], [1.0,50]]], BrownNoise -> [], Changed -> [\in, [\threshold, [0.0,1],[0.0,1]]], Clip -> [\in, [\lo, [0.0,1],[0.0,0.5]], [\hi, [0.0,1],[0.5,1]]], ClipNoise -> [], CoinGate -> [[\prob, [0.0,1],[0.0,1]],\in], CombC -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]],[\decaytime,[0,1],[0.1,1]]], CombL -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]],[\decaytime,[0,1],[0.1,1]]], CombN -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]],[\decaytime,[0,1],[0.1,1]]], //Compander -> [\in, \in, [\thresh, [0.0,1],[0.0,1]],[\slopeBelow, [0.0,5],[1.0,2]],[\slopeAbove,[0.0,5],[1.0,2]],[\clampTime,[0.0,1],[0.001,0.1]],[\relaxTime,[0.0,1],[0.001,0.5]]], //CompanderD -> [\in, \in, [\thresh, [0.0,1],[0.0,1]],[\slopeBelow, [0.0,5],[1.0,2]],[\slopeAbove,[0.0,5],[1.0,2]],[\clampTime,[0.0,1],[0.001,0.1]],[\relaxTime,[0.0,1],[0.001,0.5]]], Crackle -> [[\chaosParam, [1.0,2.01],[1.0,2.01]]], CuspL -> [freq2,[\a,[0.8,1.2],[0.9,1.1]],[\b,[1.8,2.2],[1.9,2.1]],[\xi, 0]], CuspN -> [freq2,[\a,[0.8,1.2],[0.9,1.1]],[\b,[1.8,2.2],[1.9,2.1]],[\xi, 0]], Decay -> [\in, [\decayTime, [0,1],[0.001,1]]], Decay2 -> [\in, [\decayTime, [0,1],[0.001,1]]], Delay1 -> [\in], Delay2 -> [\in], DelayC -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]]], DelayL -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]]], DelayN -> [\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]]], Dust -> [[\density, [1.0,10000], [1.0,100]]], Dust2 -> [[\density, [1.0,10000], [1.0,100]]], FBSineC -> [freq1, [\im,[30,35],[32,33]], [\fb,[-1,1],[-0.5,0.5]],[\a,[1.0,1.2],[1.0,1.1]], [\c,[0.0,0.8],[0.0,0.6]], [\xi,[0.0,1],[0.0,1]], [\yi,[0.0,1],[0.0,1]]], FBSineL -> [freq1, [\im,[30,35],[32,33]], [\fb,[-1,1],[-0.5,0.5]], [\a,[1.0,1.2],[1.0,1.1]], [\c,[0.0,0.8],[0.0,0.6]], [\xi,[0.0,1],[0.0,1]], [\yi,[0.0,1],[0.0,1]]], FBSineN -> [freq1, [\im,[30,35],[32,33]], [\fb,[-1,1],[-0.5,0.5]], [\a,[1.0,1.2],[1.0,1.1]], [\c,[0.0,0.8],[0.0,0.6]], [\xi,[0.0,1],[0.0,1]], [\yi,[0.0,1],[0.0,1]]], Fold -> [\in, [\lo, [0.0,0.5],[0.0,0.5]],[\hi,[0.5,1],[0.5,1]]], Formant -> [freq1, freq1, freq1], Formlet -> [\in, freq1, [\attacktime, [0.0,1],[0.0,1]],[\decaytime, [0.0,1],[0.0,1]]], FreeVerb -> [\in, [\mix, [0.0,1],[0.0,1]], [\room, [0.0,1],[0.0,1]], [\damp, [0.0,1],[0.0,1]]], FreqShift -> [\in, freq1, [\phase, [0.0,2pi],[0.0,2pi]]], Gate -> [\in, \in], GbmanL -> [freq2, [\xi, [-3.0,3], [-3.0,3]],[\yi, [-3.0,3],[-3.0,3]]], GbmanN -> [freq2, [\xi, [-3.0,3], [-3.0,3]],[\yi, [-3.0,3],[-3.0,3]]], Gendy1 -> [[\ampdist, 1],[\durdist,1],[\adparam,[0.0,1],[0.0,1]],[\ddparam,[0.0,1],[0.0,1]],freq1,freq2,[\ampscale,[0.0,1],[0.0,1]],[\durscale,[0.0,1],[0.0,1]],[\initCPs,12],[\knum,[1.0,12],[1.0,12]]], //Gendy2 -> [[\ampdist, 1],[\durdist,1],[\adparam,[0.0,1],[0.0,1]],[\ddparam,[0.0,1],[0.0,1]],freq1,freq2,[\ampscale,[0.0,1],[0.0,1]],[\durscale,[0.0,1],[0.0,1]],[\initCPs,12],[\knum,[1.0,12],[1.0,12]]], Gendy3 -> [[\ampdist, 1],[\durdist,1],[\adparam,[0.0,1],[0.0,1]],[\ddparam,[0.0,1],[0.0,1]],freq1,freq2,[\ampscale,[0.0,1],[0.0,1]],[\durscale,[0.0,1],[0.0,1]],[\initCPs,12],[\knum,[1.0,12],[1.0,12]]], GrayNoise -> [], HPF -> [\in, freq5], HPZ1 -> [\in], HPZ2 -> [\in], Hasher -> [\in], HenonC -> [freq2, [\a, [1.0,2],[1.1,1.5]], [\b, [0.1,1],[0.1,0.5]]], HenonL -> [freq2, [\a, [1.0,2],[1.1,1.5]], [\b, [0.1,1],[0.1,0.5]]], //HenonN -> [freq2, [\a, [1.0,2],[1.1,1.5]], [\b, [0.1,1],[0.1,0.5]]], Impulse -> [freq1,[\phase, [0.0, 2pi], [0.0, 2pi]]], InRange -> [\in, [\lo, [0.0,0.5],[0.0,0.5]],[\hi,[0.5,1],[0.5,1]]], //Integrator -> [\in, [\coef,[0.001,1],[0.001,1]]], LFClipNoise -> [freq4], LFCub -> [freq4], LFDClipNoise -> [freq4], LFDNoise0 -> [freq4], LFDNoise1 -> [freq4], LFDNoise3 -> [freq4], LFPar -> [freq4], LFPulse -> [freq4, [\iphase, 0], [\width, [0.0,1],[0.0,1]]], LFSaw -> [freq4], LFTri -> [freq4], LPF -> [\in, freq1], LPZ1 -> [\in], LPZ2 -> [\in], Lag -> [\in,lag], Lag2 -> [\in,lag], Lag2UD -> [\in,lag,lag], Lag3 -> [\in,lag], Lag3UD -> [\in,lag,lag], LagUD -> [\in,lag,lag], LastValue -> [\in, [\diff, [0.0,1],[0.0,1]]], Latch -> [\in,\in], LatoocarfianC -> [freq2,[\a,[1.0,5],[1.0,5]],[\b,[1.0,5],[1.0,5]],[\c,[0.1,2],[0.1,2]],[\d,[0.1,2],[0.1,2]]], //LatoocarfianL -> [freq2,[\a,[1.0,5],[1.0,5]],[\b,[1.0,5],[1.0,5]],[\c,[0.1,2],[0.1,2]],[\d,[0.1,2],[0.1,2]]], LatoocarfianN -> [freq2,[\a,[1.0,5],[1.0,5]],[\b,[1.0,5],[1.0,5]],[\c,[0.1,2],[0.1,2]],[\d,[0.1,2],[0.1,2]]], LeastChange -> [\in,\in], Limiter -> [\in,[\level,[0.0,1],[0.5,1]],[\dur,[0.01,1],[0.01,0.1]]], LinCongC -> [freq2, [\a,[0.8,1.2],[0.8,1.2]],[\b,[-0.2,0.2],[-0.2,0.2]],[\m,[0.5,1.5],[0.5,1.5]]], LinCongL -> [freq2, [\a,[0.8,1.2],[0.8,1.2]],[\b,[-0.2,0.2],[-0.2,0.2]],[\m,[0.5,1.5],[0.5,1.5]]], //LinCongN -> [freq2, [\a,[0.8,1.2],[0.8,1.2]],[\b,[-0.2,0.2],[-0.2,0.2]],[\m,[0.5,1.5],[0.5,1.5]]], Logistic -> [[\chaosParam, [0.0, 4], [0.0, 4]], freq2, [\init, [0.0,1], [0.0,1]]], LorenzL -> [freq2, [\s, [8.0,12],[8.0,12]], [\r, [20.0,35],[20.0,35]],[\b,2.667],[\h,0.05]], MidEQ -> [\in, freq5, [\rs, [0.01,2],[0.01,1.5]], [\db, [-12,12],[-6,6]]], MoogFF -> [\in, freq1, [\gain, [0.0,4],[0.0,4]]], MostChange -> [\in, \in], //Normalizer -> [\in, [\level, 1], [\dur, [0.0,0.5],[0.0,0.5]]], OnePole -> [\in, [\coef, [0.0,1],[0.0,1]]], OneZero -> [\in, [\coef, [0.0,1],[0.0,1]]], Peak -> [\in, \in], PeakFollower -> [\in, [\decay,[0.99,1],[0.99,1]]], Phasor -> [\in, [\rate, [1/44100,1/100],[1/44100,1/100]]], PinkNoise -> [], PitchShift -> [\in, [\windowSize, [0.001,1], [0.001,0.5]], [\pitchRatio, [0.0,4], [0.0,4]], [\pitchDispersion, [0.0,1], [0.0,1]], [\timeDispersion, [0.0,1],[0.0,1]]], //Pluck -> [\in,\in, [\maxdelaytime, 1],[\delaytime, [0.0,1],[0.1,0.5]],[\decaytime,[-1,1],[0.1,1]],[\coef,[0.1,0.9],[0.1,0.9]]], Pulse -> [freq5,[\width, [0.0,1], [0.2,0.8]]], QuadC -> [freq2,[\a,1],[\b,-1],[\c,[0.5,1],[0.5,1]]], //QuadL -> [freq2,[\a,1],[\b,[-2,-1],[-2,-1]],[\c,[-1,1],[-1,1]]], QuadN -> [freq2,[\a,1],[\b,-1],[\c,[0.5,1],[0.5,1]]], RHPF -> [\in, freq5, [\rq, [0.0,2],[0.1,0.8]]], RLPF -> [\in, freq5, [\rq, [0.0,2],[0.1,0.8]]], Ramp -> [\in, lag], Resonz -> [\in, freq5, [\rq, [0.0,2],[0.1,0.8]]], Ringz -> [\in, freq5, [\decaytime, [0.0,1],[0.0,1]]], RunningMax -> [\in,\in], RunningMin -> [\in,\in], Saw -> [[\freq, [1,2e4],[1,2e4]]], Schmidt -> [\in, [\lo,[0.0,0.5],[0.0,0.5]],[\hi,[0.5,1],[0.5,1]]], SinOsc -> [freq4,[\phase, [0.0, 2pi], [0.0, 2pi]]], SinOscFB -> [freq5,[\feedback, [0.0, 2pi], [0.0, 2pi]]], Slew -> [\in, [\up, [1/44100,1],[1/44100,1]],[\dn, [1/44100,1],[1/44100,1]]], Slope -> [\in], Spring -> [\in, [\spring,[0.0,8],[0.0,2]],[\damp,[0.0,3],[0.0,1]]], StandardL -> [freq2, [\k, [0.0,2],[0.0,2]]], StandardN -> [freq2, [\k, [0.0,2],[0.0,2]]], SyncSaw -> [freq1, freq1], ToggleFF -> [\in], Trig -> [\in, [\dur,[0.0,1],[0.0,1]]], Trig1 -> [\in, [\dur,[0.0,1],[0.0,1]]], TwoPole -> [\in, freq1, [\radius, [0.0,1],[0.0,1]]], TwoZero -> [\in, freq1, [\radius, [0.0,1],[0.0,1]]], VarSaw -> [freq1, [\iphase, 0], [\width, [0.0,1],[0.0,1]]], Vibrato -> [freq1, [\rate,[0.1,10],[0.1,10]],[\depth,[0.0,1],[0.0,1]],[\delay,[0.0,1],[0.0,1]],[\onset,[0.0,1],[0.0,1]],[\rateVariation,[0.0,1],[0.0,1]],[\depthVariation,[0.0,1],[0.0,1]]], WhiteNoise -> [], Wrap -> [\in, [\lo, [0.0,0.5],[0.0,0.5]],[\hi,[0.5,1],[0.5,1]]], ZeroCrossing -> [\in] ]; pureList = [ Blip, Dust, Dust2, FBSineC, FBSineL, FBSineN, Impulse, LFClipNoise, LFCub, LFDClipNoise, LFDNoise0, LFDNoise1, LFDNoise3, LFPar, LFPulse, LFSaw, LFTri, Pulse, Saw, SinOsc, SinOscFB ]; // a list of binary operations, infix notation binopList = List[ "*", " excess: ", "+", "-", "%", " ring1: ", " min: ", " max: ", " ring4: ", " difsqr: ", " sumsqr: ", " sqrsum: ", " sqrdif: ", " absdif: ", " amclip: ", " scaleneg: ", " clip2: ", " rrand: ", " round: ", " trunc: ", " hypot: ", " thresh: " ]; } // PARAMS: // nLines -- number of variables in the def // nChan -- output a mix of the last nChan uGens // mingleRate -- probability (0..1) that a uGen input will be another uGen instead of a constant // binopRate -- probability that a given line will be a bin op rather than a uGen // amp -- overall amplitude scaling // experimental -- if true, use .clip, .fold, and .wrap; if false, only use .clip to wrap a uGen input to another uGen // debug -- if true, include a CheckBadValues line wrapped around all channels to catch any bugginess. *newDef { arg nLines = 10, nChan = 4, mingleRate = 0.5, binopRate = 0.5, preferSimpleUgens = 0.1, amp = 1, experimental = false, debug = false; // array for objects var arr = []; // choose a ugen that doesn't require input var toAdd, string, outArray; dict??{MCElectronique.init}; toAdd = MCElectronique.makeClassChoice(preferSimpleUgens); while {dict[toAdd].includes(\in)} {toAdd = MCElectronique.makeClassChoice(preferSimpleUgens)}; arr = arr.add(toAdd); (nLines-1).do {arr = arr.add(MCElectronique.makeClassChoice(preferSimpleUgens))}; string = "{\n\t"; arr.do({ |class,index| var name = class.asString; var args = dict[class]; string = string ++ (binopRate*(index>0).asInteger).coin.if {MCElectronique.binopStr(index)} {MCElectronique.ugenStr(index,name,args,mingleRate,experimental)}; string = string ++ ";\n\t"; }); outArray = ((arr.size-nChan)..(arr.size-1)).collect({|x| "v"++x.asString}).asString; string = debug.if {string++"\n\tCheckBadValues.ar("++(0..(arr.size-1)).collect({|x| "v"++x.asString}).asString++");"} {string}; string = string ++ "\n\tOut.ar(0,"++amp++"*LeakDC.ar(Pan2.ar(Mix.ar(Limiter.ar(" ++ outArray ++ ")))));\n}.play"; ^string; } *makeClassChoice { arg prob; ^[pureList,dict.keys].wchoose([prob,1-prob]).choose; } *binopStr { arg index; var string = "var v"++index++"="; string = string ++ "v" ++ (0.rrand(index-1)) ++ binopList.choose ++ "v" ++ (0.rrand(index-1)); ^string } *ugenStr { arg index, name, args, mingleRate, experimental; var string = "var v"++index++"="++name++".ar("; var controlMethod = experimental.if {["clip","fold","wrap"].choose} {"clip"}; args.do { |argps,index2| argps = argps.value; if(argps == \in) { string = string++"v"++(0.rrand(index-1)); } { if(argps[1].isArray) { var iinput = mingleRate.coin.if {-1.rrand(index-1)} {-1}; if(iinput==(-1)) {string = string++(argps[2][0].rrand(argps[2][1]))} {string = string++"v"++iinput++"."++controlMethod++"("++argps[1][0]++","++argps[1][1]++")"}; } { string = string++(argps[1]) }; }; if(index2<(args.size-1)) {string = string++","}; }; ^string ++ ")"; } }
Really nice, and I didn't get crash anymore :) This really show the power of SC, inspiring!