{
   "labels" : [
      "algorithmic"
   ],
   "code" : "( // first run synthdef\r\nSynthDef(\\piano, {|midinote, outBus=0|\r\n\tOut.ar(outBus, MdaPiano.ar(midinote.midicps, decay:0.5)); // from sc3-plugins\r\n}).add;\r\n)\r\n\r\n( // now the rest\r\n~dur = {|len1=4, len2=3|\r\n\tPlazy({\r\n\t\tvar dur = len1;\r\n\r\n\t\tinf.do{|n|\r\n\t\t\tvar overlap = (n % len1 == 0) || (n % len2 == 0);\r\n\t\t\tif(n>=len1 && dur==len1 && overlap,\r\n\t\t\t\t{\r\n\t\t\t\t\tdur=len2;\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\tif(n>0 && dur==len2 && overlap,\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdur=len1;\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t);\r\n\t\t\tdur.yield;\r\n\t\t};\r\n\t}).asStream;\r\n};\r\n\r\n~note = { |root=48|\r\n\tPlazy({\r\n\t\tvar scale = Scale.major.degrees.flat;\r\n\t\tinf.do{|n|\r\n\t\t\tvar oct = (n / scale.size).floor;\r\n\t\t\tvar degree = 12*oct + scale.wrapAt(n) + root;\r\n\t\t\tdegree.yield;\r\n\t\t}\r\n\t}).asStream;\r\n};\r\n\r\nr = Routine({\r\n\tvar durStream  = ~dur.value(9, 14.5);\r\n\tvar noteStream = ~note.value(48);\r\n\tinf.do {\r\n\t\tvar dur  = durStream.next();\r\n\t\tvar note = noteStream.next();\r\n\t\tfork{\r\n\t\t\tinf.do{\r\n\t\t\t\tSynth(\\piano, [\\midinote, note]);\r\n\t\t\t\t4.yield; // loop duration\r\n\t\t\t};\r\n\t\t};\r\n\t\tdur.yield;\r\n\t};\r\n});\r\n\r\nr.play(TempoClock(2));\r\n)",
   "id" : "1-4X3",
   "is_private" : null,
   "name" : "Yet another molecular music box",
   "author" : "coreyker",
   "description" : "An attempt at coding this algorithm:\r\nhttp://www.synthtopia.com/content/2014/12/22/the-molecular-music-box-how-simple-rules-can-lead-to-rich-patterns/\r\n\r\nI haven't really checked for errors, but is sounds ok.\r\n\r\nThere are a few other SC versions as well. See for example:\r\n\r\nhttp://www.kimri.org/blog/?p=487\r\n\r\nand\r\n\r\nhttp://sccode.org/1-4Ww",
   "ancestor_list" : []
}
