{
   "description" : "This composition uses a task to read an array of durations and pitches. Every certain number of cycles, the functions scrambRand and octRand are called. scrambRand reverses a random sub-segment of the array. octRand randomly transposes a note up or down an octave. Every so often, all pitches are transposed according to the transp array. \r\n\r\nTwo instances of this process are run simultaneously, one left and one right.",
   "ancestor_list" : [],
   "author" : "madamdata",
   "name" : "Hymn #15 - generative melody by array rewriting",
   "code" : "(\r\nSynthDef(\\ping, {\r\n\targ freq = 440, pan = 0;\r\n\tvar sig;\r\n\tsig = SinOsc.ar(freq, 0, 0.3);\r\n\tsig = sig * EnvGen.ar(Env.perc(0.01, 1), doneAction:2);\r\n\tsig = Pan2.ar(sig, pan);\r\n\tOut.ar(0, sig)\r\n}).add;\r\n)\r\n\r\n(\r\n~scramb = {|pan|\r\nvar notes = [0,4,7,14,9,12,4,7,9,7];\r\nvar dur = [1,1,2,3,6,3,4,5,2,1,13];\r\nvar transp = [0, 5, 7, 3, 2];\r\nvar scrambRand = {|array|\r\n\tvar rand = rrand(0, array.size-3);\r\n\tvar end = rand + rrand(1,2);\r\n\tvar range = (rand..end);\r\n\tvar reverseRange = range.reverse;\r\n\tvar temp = array.copy;\r\n\trange.postln;\r\n\trange.do({|item, index|\r\n\t\tarray[item] = temp[reverseRange[index]];\r\n\t});\r\n\tarray;\r\n};\r\nvar octRand = {|array|\r\n\t\tvar rand = rrand(0, array.size-1);\r\n\t\tarray[rand] = array[rand] + [-12,0,12].choose;\r\n\t};\r\nvar task = Task {\r\n\tvar step = 0;\r\n\tvar transpStep = 0;\r\n\tloop {\r\n\t\tvar freq = (notes.wrapAt(step) + 60 + transp.wrapAt(transpStep)).midicps;\r\n\t\tSynth(\\ping, [\\freq, freq, \\pan, pan]);\r\n\t\t(dur.wrapAt(step) * 0.15).wait;\r\n\t\tstep = step + 1 % (notes.size * 12;);\r\n\t\tif (step%32 == 0, {scrambRand.value(notes)});\r\n\t\tif (step%20 == 0, {scrambRand.value(dur)});\r\n\t\tif (step%66 == 0, {transpStep = transpStep + 1 % (transp.size)});\r\n\t\tif (step%24 == 0, {notes = notes.rotate(rrand(-1, 1))});\r\n\t\tif (step%56 ==0, {octRand.value(notes)});\r\n\t}\r\n}.play;\r\n};\r\n)\r\n\r\n(\r\n~scramb.value(-0.7);~scramb.value(0.7);\r\n)",
   "id" : "1-51k",
   "is_private" : null,
   "labels" : [
      "algorithmic"
   ]
}
