{
   "code" : "(\r\nNdef(\\polysynth, {|t_gate, midinote=60|\r\n\tvar n_voices = 10, max_voice_time=120;\r\n\tvar times = LocalIn.kr(n_voices);\r\n        // Latch returns 0 by default before the first trig, that is why we\r\n        // sum 1 to the index and then subtract.\r\n\tvar voice = (Latch.kr(ArrayMax.kr(times)[1] + 1, t_gate) - 1);\r\n\tvar trigs = n_voices.collect {|idx|\r\n\t\tBinaryOpUGen('==', voice, idx);\r\n\t};\r\n\t\r\n\tvar voices = n_voices.collect {|idx|\r\n\t\tSinOsc.ar(Latch.kr(midinote.midicps, trigs[idx])) * EnvGen.ar(\r\n\t\t\tEnv.perc(0.01,3),\r\n\t\t\ttrigs[idx];\r\n\t\t);\r\n\t};\r\n\t\t\r\n\tLocalOut.kr(\r\n\t\tn_voices.collect {|idx|\r\n\t\t\tEnvGen.kr(Env.new([1,0,1],[0,max_voice_time]), trigs[idx]);\r\n\t});\r\n\tSplay.ar(voices);\r\n}).play;\r\n)\r\n\r\n(\r\nTdef(\\melody, {\r\n\tvar scale = Scale.choose;\r\n\t24.rand.do {\r\n\t\tNdef(\\polysynth).set(\\t_gate, 1, \\midinote, 60+scale.degrees.choose);\r\n\t\t2.0.rand.wait;\r\n\t}\r\n}).play;\r\n)\r\n\r\n(\r\nTdef(\\chord, {\r\n\tNdef(\\polysynth).set(\\t_gate, 1, \\midinote, 50);\r\n\t0.003.wait;\r\n\tNdef(\\polysynth).set(\\t_gate, 1, \\midinote, 60);\r\n\t0.003.wait;\r\n\tNdef(\\polysynth).set(\\t_gate, 1, \\midinote, 70);\r\n}).play;\r\n)",
   "id" : "1-5dn",
   "is_private" : null,
   "labels" : [
      "ndef",
      "poly"
   ],
   "description" : "playing multiple voices in an Ndef",
   "ancestor_list" : [],
   "author" : "bgola",
   "name" : "poly ndef"
}
