{
   "description" : "routine that takes a seed and generates a self-similar sloth canon with it by adding each term to each term, better explained in this blog post: https://www.science20.com/robert_inventor039s_column/blog/self_similar_sloth_canon_number_sequences-113689",
   "ancestor_list" : [],
   "author" : "eli.rosenkim",
   "name" : "sloth canons",
   "code" : "// Inspired by: https://www.science20.com/robert_inventor039s_column/blog/self_similar_sloth_canon_number_sequences-113689\r\n\r\n\r\n//self-similar sloth-canon routine, for some integer a, r(n) = r(a*n)\r\n(\r\nr = Routine({\r\n\tvar seed = #[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\tif(i%9 == 0, {out.post}); //comment next line and uncomment this line to demonstrate that for seed [0,1,0], r(n) = r(3*n) for all n\r\n\t\t//out.post;\r\n        0.1.wait;\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\nr.play;\r\nr.stop;\r\n\r\n\r\n\r\n\r\n\r\n\r\n//simple musical examples\r\n\r\n(//disperser taken from https://scsynth.org/t/phase-rotation-fos/5575\r\nSynthDef(\\simpleSaw, {\r\n\targ root=150, oTone=1, uTone=1, amp=0.8, gate = 0.5, release = 1, k= 0.4, curve = 2, lag = 0.01;\r\n\tvar sig, finalFreq, env, tempO, tempU, sigL, sigR, sigM, sigS, hornbostelwertheimerkonstante = 0.00063;\r\n\ttempO = oTone;\r\n\ttempU = uTone;\r\n\toTone = oTone.max(1);\r\n\tuTone = uTone.max(1);\r\n\tfinalFreq = (oTone/uTone) * root;\r\n\tfinalFreq = finalFreq.lag2(lag);\r\n\tsig = Saw.ar(finalFreq, 0.5);\r\n\tsig =sig *(tempO.abs.min(1))*(tempU.abs.min(1));//mutes notes with oTone or uTone = to 0\r\n\tsigL = DelayC.ar(sig, 1, LFNoise1.ar(1.11, finalFreq * hornbostelwertheimerkonstante * 0.005));\r\n\tsigR = DelayC.ar(sig, 1, LFNoise1.ar(1.1, finalFreq * hornbostelwertheimerkonstante * 0.005));\r\n\tsigM = sigL + sigR;\r\n\tsigS = sigL - sigR;\r\n\t100.do {sigS = FOS.ar(sigS, k.neg, 1, k);}; //allpass disperser\r\n\tsigL = (sigM + sigS);\r\n\tsigR =  (sigM - sigS);\r\n\tsig = [sigL, sigR];\r\n\tenv = EnvGen.kr(Env.adsr(0.01, 0, 1, release, 1, curve), gate, levelScale: 1, doneAction: Done.freeSelf);\r\n\tsig = sig*env;\r\n\tOut.ar(0, sig!2);\r\n}).add;\r\n)\r\n\r\n//sequence, wait for it to develop, increasingly complex ratios will emerge\r\n(\r\n\r\n~oFunc = {\r\n\tvar seed = #[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~uFunc = {\r\n\tvar seed = #[0,1, -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(\"u: \" ++ 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\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198 * Pseq([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, (3/2),  (3/2),  (3/2), (3/2),  (3/2)], inf),\r\n\t\\release, 0.1,\r\n\t\\curve, -2,\r\n\t\\k, 0.4,\r\n\t\\dur, 0.15,\r\n\t\\lag, Pseq([0.06, 0.05, 0.05, 0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198,\r\n\t\\release, 0.5,\r\n\t\\curve, -1,\r\n\t\\k, 0.8,\r\n\t\\dur, 0.3,\r\n\t\\lag, Pseq([0.06, 0.05, 0.05, 0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\n\r\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198,\r\n\t\\release, 0.5,\r\n\t\\curve, 1,\r\n\t\\k, 1,\r\n\t\\dur, 0.6,\r\n\t\\lag, Pseq([0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\n)\r\n\r\n\r\n\r\n//sequence 2\r\n(\r\n~oFunc = {\r\n\tvar seed = #[-3,0,3,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~uFunc = {\r\n\tvar seed = #[-3,-2,3], 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(\"u: \" ++ 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\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198*0.5,\r\n\t\\release, 0.05,\r\n\t\\curve, -2,\r\n\t\\k, 0.4,\r\n\t\\dur, 0.1,\r\n\t\\lag, Pseq([0.06, 0.05, 0.05, 0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198*0.5,\r\n\t\\release, 0.2,\r\n\t\\curve, -1,\r\n\t\\k, 0.8,\r\n\t\\dur, 0.2,\r\n\t\\lag, Pseq([0.06, 0.05, 0.05, 0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\n\r\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198*0.5,\r\n\t\\release, 0.1,\r\n\t\\curve, 1,\r\n\t\\k, 1,\r\n\t\\dur, 0.4,\r\n\t\\lag, Pseq([0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\n)\r\n\r\n\r\n\r\n\r\n//sequence 3\r\n(\r\n~oFunc = {\r\n\tvar seed = #[-3,0,3], 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~uFunc = {\r\n\tvar seed = #[-3,-2,0,5,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(\"u: \" ++ 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\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198*2,\r\n\t\\release, 0.1,\r\n\t\\curve, -2,\r\n\t\\k, 0.1,\r\n\t\\dur, 0.1,\r\n\t\\lag, Pseq([0.06, 0.05, 0.05, 0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198*2,\r\n\t\\release, 0.1,\r\n\t\\curve, -4,\r\n\t\\k, 0.8,\r\n\t\\dur, 0.2,\r\n\t\\lag, Pseq([0.06, 0.05, 0.05, 0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\n\r\nPmonoArtic(\r\n\t\\simpleSaw,\r\n\t\\oTone, Prout(~oFunc),\r\n\t\\uTone, Prout(~uFunc),\r\n\t\\root, 198*2,\r\n\t\\release, 0.2,\r\n\t\\curve, 1,\r\n\t\\k, 0.99,\r\n\t\\dur, 0.3,\r\n\t\\lag, Pseq([0.04], inf),\r\n\t\\legato, Pseq([1, 0.5], inf),\r\n).play;\r\n\r\n)",
   "id" : "1-5fU",
   "is_private" : null,
   "labels" : [
      "fractal",
      "just intonation",
      "sloth canon"
   ]
}
