{
   "description" : "fun patch using sloth canons to control places of a monzo",
   "ancestor_list" : [],
   "author" : "eli.rosenkim",
   "name" : "monzos + sloth patch",
   "is_private" : null,
   "id" : "1-5fV",
   "code" : "(\r\nSynthDef.new(\\gauss, {\r\n\targ freq = 500, dev = 0, svfFreq = 1000, decay = 0.1, attack = 0.01, k = 0.4, semRatio = 1;\r\n\tvar sig, env, sigM, sigS;\r\n\tfreq = freq.lag2(0.01);\r\n\tsig = [GaussTrig.ar(freq, dev), GaussTrig.ar(freq, dev)]*10;\r\n\tsigM = (sig[0]+sig[1])/2;\r\n\tsigS = (sig[0]-sig[1])/2;\r\n\tsig = [(sigM+sigS), (sigM-sigS)];\r\n\tsigM = VASEM12.ar(sig, svfFreq*semRatio, 1, 0.5);\r\n\tsigS = 100.do {sigS = FOS.ar(sigS, k.neg, 1, k);}; //allpass disperser\r\n\tsig = SVF.ar(sig, svfFreq, 0.1);\r\n\tenv = EnvGen.ar(Env.perc(attack, decay), 1, doneAction: 2);\r\n\tsig = sig*env/2;\r\n\tsig = LeakDC.ar(sig);\r\n\tOut.ar(0, sig);\r\n}).add;\r\n)\r\nx = Synth.new(\\gauss, [\\freq, 1000, \\dev, 0, \\svfFreq, 1500])\r\nx = Synth.new(\\gauss, [\\freq, 1000, \\dev, 1, \\svfFreq, 1500])\r\n\r\n(//function that takes a collection representing a monzo as an argument, and outputs the ratio it encodes\r\n~zo = {\r\n\targ exponentCollection;\r\n\tvar ratio = 1;\r\n\texponentCollection.do({arg item, i; ratio = ratio * (i.nthPrime).pow(item);});\r\n\tratio;\r\n};\r\n)\r\n\r\n//pattern\r\n(\r\ns.latency = 0.5;\r\n~func2 = {\r\n\tvar seed = #[-1,0,1], i=0, temp, temp2 = List[], out;\r\n\ttemp = seed;\r\n    loop {\r\n\t\tout = temp[((i/3).floor)%temp.size] + seed[i%seed.size];\r\n\t\tout.yield;\r\n\t\t//(\"o: \" ++ out).postln;\r\n\t\ti = i+1;\r\n\t\ttemp2.add(out);\r\n\t\tif((i+1) > (temp.size**2), {temp = temp2});\r\n    }\r\n};\r\n\r\n~func3 = {\r\n\tvar seed = #[1,0,-1, 0], i=0, temp, temp2 = List[], out;\r\n\ttemp = seed;\r\n    loop {\r\n\t\tout = temp[((i/3).floor)%temp.size] + seed[i%seed.size];\r\n\t\tout.yield;\r\n\t\t//(\"o: \" ++ out).postln;\r\n\t\ti = i+1;\r\n\t\ttemp2.add(out);\r\n\t\tif((i+1) > (temp.size**2), {temp = temp2});\r\n    }\r\n};\r\n\r\n~mutro = {\r\n\tvar  i = 0, deltas, randos, out, maxStep;\r\n\tdeltas = List[0.17, 0.17, 0.17, 0.17]; //starting deltas for each beat\r\n\trandos = List[0, 0, 0, 0]; //random values for each beat, first bar plays straight as randos are all 0\r\n\tmaxStep = deltas[0]/10;\r\n\tloop{\r\n\t\tout = ((deltas[i] - randos[(i-1)%(deltas.size)] + randos[i]).abs); //if the first beat is pushed back by 0.2s, the second beat is moved forward 0.2s to keep it in roughly the same position before rando is added\r\n\t\tout.yield;\r\n\t\ti = (i+1)%(deltas.size);\r\n\t\tif(i%(deltas.size) == 0, //adds random value to each term of random array on beat one of each bar after bar 1\r\n\t\t\t{randos = randos.collect({arg item, i; item+(rrand(-1* maxStep, maxStep))})}\r\n\t\t\t//{\"test\".postln}\r\n\t\t);\r\n\t};\r\n};\r\n\r\n~root = 45*4;\r\nw = Pbind(\r\n\t\\instrument, \\gauss,\r\n\t\\freq,  (~root*~zo.([Prout(~func2), Prout(~func3)])),\r\n\t\\svfFreq, 999 + Pgauss(0, 55),\r\n\t\\dev, Prout(~mutro)/4 + Pgauss(0, 0.05),\r\n\t\\dur, Prout(~mutro)*2,\r\n\t\\decay, Prout(~mutro)*2 + Pgauss(0, 0.05),\r\n\t\\attack, Pgauss(0.01, 0.02).max(0.01),\r\n\t\\k, Prout(~func2).max(0).min(1),\r\n\t\\semRatio, (Prout(~func2)/Prout(~func3)).abs\r\n).play;\r\n\r\nx = Pbind(\r\n\t\\instrument, \\gauss,\r\n\t\\freq,  (~root*~zo.([Prout(~func3), Prout(~func2)])),\r\n\t\\svfFreq, 888 + Pgauss(0, 55),\r\n\t\\dev, Prout(~mutro)/3 + Pgauss(0, 0.05),\r\n\t\\dur, 3*Prout(~mutro),\r\n\t\\decay, 3*Prout(~mutro) + Pgauss(0, 0.05),\r\n\t\\attack, Pgauss(0.01, 0.02).max(0.01),\r\n\t\\k, Prout(~func2).max(0).min(1),\r\n\t\\semRatio, (Prout(~func3)/Prout(~func2)).abs\r\n).play;\r\n\r\ny = Pbind(\r\n\t\\instrument, \\gauss,\r\n\t\\freq,  (~root*~zo.([Prout(~func2), Prout(~func3)])),\r\n\t\\svfFreq, 777 + Pgauss(0, 55),\r\n\t\\dev, Prout(~mutro)/2 + Pgauss(0, 0.05),\r\n\t\\dur, 2*Prout(~mutro),\r\n\t\\decay, 0.5*Prout(~mutro) + Pgauss(0, 0.05),\r\n\t\\attack, Pgauss(0.01, 0.02).max(0.01),\r\n\t\\k, Prout(~func2).max(0).min(1),\r\n\t\\semRatio, (Prout(~func2)/Prout(~func3)).abs\r\n).play;\r\n\r\nz = Pbind(\r\n\t\\instrument, \\gauss,\r\n\t\\freq,  (~root*(4/3)*~zo.([Prout(~func2), Prout(~func3)])),\r\n\t\\svfFreq, 555 + Pgauss(0, 55),\r\n\t\\dev, Prout(~mutro) + Pgauss(0, 0.05),\r\n\t\\dur, 2*Prout(~mutro),\r\n\t\\decay, Prout(~mutro) + Pgauss(0, 0.05),\r\n\t\\attack, Pgauss(0.01, 0.02).max(0.01),\r\n\t\\k, Prout(~func2).max(0).min(1),\r\n\t\\semRatio, (Prout(~func3)/Prout(~func2)).abs\r\n).play;\r\n\r\n{[GaussTrig.ar(freq: 45, dev: 0.1), GaussTrig.ar(freq: 45, dev: 0.1)]/50}.play;\r\n)\r\n\r\ns.scope;",
   "labels" : [
      "just intonation",
      "monzo",
      "sloth canon",
      "fractals"
   ]
}
