{
   "ancestor_list" : [],
   "description" : "Example reworked and extended from http://wiki.cs.princeton.edu/index.php/Example_5\r\n\r\nIt outputs MONO as it was designed for SCLOrk",
   "name" : "Spacey Synth example",
   "author" : "Bruno Ruviaro",
   "id" : "1-58J",
   "is_private" : null,
   "code" : "// ==========\r\n// Synth\r\n// ==========\r\n\r\n// Run this block once (it creates the synth) \r\n(\r\nSynthDef(\"spacey\", { arg freq, amp;\r\n\tvar snd, env;\r\n\tenv = Env.perc(level: amp).kr(2);\r\n\tsnd = LFSaw.ar(freq: freq, mul: env);\r\n\tsnd = RLPF.ar(\r\n\t\tin: snd,\r\n\t\tfreq: LFNoise1.kr(2).range(500, 20000),\r\n\t\trq: 0.2\r\n\t);\r\n\tOut.ar(0, snd);\r\n}).add;\r\n)\r\n\r\n// ==========\r\n// Patterns\r\n// ==========\r\n\r\n// bass line (alternating with a rest)\r\n(\r\nb = Pbind(\r\n\t\\instrument, \"spacey\",\r\n\t\\midinote, Prand([\\rest, Pseq([24, 31, 36, 43, 48, 55])], inf),\r\n\t\\dur, 0.2,\r\n\t\\amp, 0.5\r\n).play;\r\n)\r\n\r\nb.stop;\r\n\r\n\r\n// middle arpeggio\r\n(\r\nm = Pbind(\r\n\t\\instrument, \"spacey\",\r\n\t// \\midinote, Pseq([60, 63, 67, 74], inf), // compare this line and below \r\n\t\\midinote, Pseq([60, Prand([63, 65]), 67, Prand([70, 72, 74])], inf),\r\n\t\\dur, 0.13,\r\n\t\\amp, 0.4\r\n).play;\r\n)\r\n\r\nm.stop;\r\n\r\n\r\n// random note melody (5 to 7 notes, from listed notes only)\r\n// note that this one is not infinite\r\n(\r\nr = Pbind(\r\n\t\\instrument, \"spacey\",\r\n\t\\midinote, Prand([74, 75, 77, 79, 81], rrand(5, 7)),\r\n\t\\dur, 0.13,\r\n\t\\amp, 0.3\r\n).play;\r\n)\r\n\r\n\r\n\r\n\r\n// putting it all together\r\n// note the use of Pbindef (a variation of Pbind that allows you to re-run the code in real time without stopping the sound)\r\n(\r\nPbindef(\\wow,\r\n\t\\instrument, \"spacey\",\r\n\t\\midinote, Pseq([\r\n\t\t// bass run\r\n\t\tPrand([\\rest, Pseq([24, 31, 36, 43, 48, 55])]),\r\n\t\t\r\n\t\t// middle part (plays twice)\r\n\t\tPseq([60, Prand([63, 65]), 67, Prand([70, 72, 74])], 2),\r\n\t\t\r\n\t\t// ending melody of 3 to 9 notes\r\n\t\tPrand([74, 75, 77, 79, 81], rrand(3, 9))\r\n\t], inf),\r\n\t\\dur, 0.13,\r\n\t\\amp, 0.5\r\n).play;\r\n)\r\n\r\nPbindef(\\wow).stop;\r\nPbindef(\\wow).play;\r\nPbindef(\\wow, \\dur, 0.2);\r\n\r\n\r\n\r\n\r\n// Adding some reverb\r\nNdef(\\rev).play;\r\n\r\n// Reverb 1\r\nNdef(\\rev, { ReplaceOut.ar(0, Limiter.ar(Mix(FreeVerb.ar(In.ar(0), mix: 0.5, room: 0.9)))) }).play;\r\n\r\n// Reverb 2\r\n(\r\nNdef(\\rev, {\r\n\tvar snd = In.ar(In.ar(0));\r\n\t6.do({ snd = AllpassN.ar(snd, 0.05, [0.05.rand, 0.05.rand], 4) });\r\n\tReplaceOut.ar(0, Limiter.ar(Mix(snd), 0.9))\r\n});\r\n)\r\n\r\n// stop reverb\r\nNdef(\\rev).clear(1);",
   "labels" : [
      "pbind",
      "spacey",
      "ndef",
      "pbindef"
   ]
}
