{
   "description" : "A quick demo of one way to allocate server-side resources (SynthDefs, Buffers) that works in RT/NRT with minimal modification.\r\n\r\nYou'll need Jonatan Liljedahl's ScoreClock quark:\r\n\r\n\r\n// Mac OSX / Linux\r\n\r\nQuarks.install(\"ScoreClock\");\r\n\r\n\r\n// Windows, see http://swiki.hfbk-hamburg.de/MusicTechnology/883",
   "ancestor_list" : [],
   "author" : "jamshark70",
   "name" : "ScoreClock, Patterns, RT/NRT and server-side resources",
   "is_private" : null,
   "id" : "1-Al",
   "code" : "(\r\np = Pbind(\r\n\t\\instrument, \\bufGrainPan,\r\n\t\\bufnum, b,\r\n\t\\time, Pwhite(0.1, 0.3, inf),\r\n\t\\start, Pwhite(0.0, b.duration - Pkey(\\time), inf) * b.sampleRate,\r\n\t\\pan, Pwhite(-1.0, 1.0, inf),\r\n\t\\delta, Pkey(\\time) * Pexprand(0.8, 1.25, inf)\r\n);\r\n\r\nq = Pseq([\r\n\t(play: {\r\n\t\t// initialization event\r\n\t\tSynthDef(\\bufGrainPan, { |start, time, bufnum, pan, rate = 1, amp = 1,\r\n\t\t\tattack = 0.001, decay = 0.02, outbus|\r\n\t\t\tvar sig;\r\n\t\t\tsig = PlayBuf.ar(1, bufnum, rate * BufRateScale.kr(bufnum), 1, start, 0)\r\n\t\t\t* EnvGen.kr(Env.linen(attack, time, decay), doneAction:2);\r\n\t\t\tOut.ar(outbus, Pan2.ar(sig, pan, amp));\r\n\t\t}).add;\r\n\r\n// NOTE: Mac OSX/Windows users need to change this for the actual location\r\n\r\n\t\tb = Buffer.read(s, Platform.systemAppSupportDir +/+ \"sounds/a11wlk01.wav\");\r\n\r\n\t\ts.sync\r\n\t}, delta: 0),\r\n\tp\r\n]);\r\n\r\nf = {  // cleanup func\r\n\tb.debug(\"freeing\").free\r\n};\r\n)\r\n\r\n\r\ns.reboot;\r\n\r\n// RT\r\n(\r\nr = q.play;\r\nc = SimpleController(r).put(\\stopped, { c.remove; f.value });\r\n)\r\n\r\nr.stop;  // should free the buffer\r\n\r\n\r\n\r\n// NRT\r\n(\r\nScoreClock.beginScore;\r\nPfindur(10, q).play(ScoreClock);  // cleanup not needed since NRT server dies anyway\r\n\r\nScoreClock.makeScore.recordNRT(PathName.tmp +/+ \"osc.osc\", thisProcess.platform.recordingsDir +/+ \"test2.aiff\", options: ServerOptions.new.numOutputBusChannels_(2), duration: 10, action: { \"done\".postln });\r\n)",
   "labels" : [
      "patterns",
      "nrt",
      "nonrealtime",
      "sync"
   ]
}
