{
   "ancestor_list" : [
      "1-5cr"
   ],
   "description" : "Re: Let me know if you have ideas for improvement! (code-wise or feature-wise) ->\r\nI used an object prototype to streamline the process of registering notes and getting sequences of them. Code looks simpler to me and easier to further develop :)",
   "author" : "elgiano",
   "name" : "Re: midified arpeggiator/auto-accompaniment using patterns",
   "id" : "1-5cx",
   "is_private" : null,
   "code" : "(\r\ns.waitForBoot({\r\n\tvar right, left;\r\n\r\n\tMIDIdef.freeAll;\r\n\tif (~midi_initilized.isNil) {\r\n\t\tMIDIClient.init;\r\n\t\tMIDIIn.connectAll;\r\n\t\t~midi_initialized = 1;\r\n\t};\r\n\r\n\t~n = (\r\n\t\ttable: Order(),\r\n\t\tnoteOn: {|n,note| n.table[note] = 1},\r\n\t\tnoteOff: {|n,note| n.table.removeAt(note)},\r\n\t\tget: {|n,i| \r\n\t\t\tn.table.indices[i] ?? n.table.indices.first ?? Rest(1)\r\n\t\t},\r\n\t\tseq: {|n,notes|\r\n\t\t\tnotes.asArray.collect{|i| Plazy{n.get(i)}}\r\n\t\t}\r\n\t);\r\n\t\r\n\tMIDIdef.noteOn(\r\n\t\t\\mynoteonhandler, // just a name for this handler\r\n\t\t{\r\n\t\t\t|val, num, chan, src|\r\n\t\t\t~n.noteOn(num)\r\n\t\t}\r\n\t);\r\n\r\n\tMIDIdef.noteOff(\r\n\t\t\\mynoteoffhandler, // just a name for this handler\r\n\t\t{\r\n\t\t\t|val, num, chan, src|\r\n\t\t\t~n.noteOff(num) // update note table and update ~n\r\n\t\t\t/*\r\n\t\t\t// only enable the following lines if you want the arpeggio to stop as soon as you release the keys\r\n\t\t\t~n.table.clear\r\n\t\t\t*/\r\n\t\t}\r\n\t);\r\n\r\n\tright = Pbind(\r\n\t\t\\instrument, \\default,\r\n\t\t\\midinote, Pseq(~n.seq(\r\n\t\t\t[ 0, 2, 1, 2] ++ (([ 0, 2, 1, 2] + 12)!2).flatten\r\n\t\t)),\r\n\t\t\\dur, 2*Pseq([1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ].normalizeSum)\r\n\t);\r\n\tleft = Pbind(\r\n\t\t\\instrument, \\default,\r\n\t\t\\midinote, Pseq(~n.seq([ 0, 2, 0, 2, 0, 2, 0, 2] - 12)),\r\n\t\t\\dur, 2*Pseq([1, 1, 1, 1, 1, 1, 1, 1].normalizeSum)\r\n\t);\r\n\tif (~player.notNil) { ~player.stop; };\r\n\t~player = Pn(Ppar([right,left])).play;\r\n});\r\n)",
   "labels" : [
      "pattern",
      "arpeggio",
      "midi",
      "code fork",
      "arpeggiator",
      "autoaccompaniment"
   ]
}
