{
   "id" : "1-50G",
   "is_private" : null,
   "code" : "// Rumush\r\n// Facebook: https://www.facebook.com/rumushproduction\r\n// SoundCloud: https://soundcloud.com/rumushproduction\r\n// YouTube: https://www.youtube.com/channel/UCs_Cn1R4iFrYOyc8liFucSQ\r\n// Blog: https://mycelialcordsblog.wordpress.com/\r\n// GitHub: https://github.com/RumushMycelialCords\r\n\r\nMIDIIn.connectAll\r\n(\r\n/*\r\nGlobal Variables\r\n*/\r\n~len = 8;\r\n~gBuf1 = Buffer.alloc(s, s.sampleRate*~len);\r\n~gBuf2 = Buffer.alloc(s, s.sampleRate,*~len);\r\n~gBuf3 = Buffer.alloc(s, s.sampleRate*~len);\r\n~gBuf4 = Buffer.alloc(s, s.sampleRate,*~len);\r\n~buf1 = Buffer.alloc(s, s.sampleRate*~len, 2);\r\n~buf2 = Buffer.alloc(s, s.sampleRate*~len, 2);\r\n~buf3 = Buffer.alloc(s, s.sampleRate*~len, 2);\r\n~buf4 = Buffer.alloc(s, s.sampleRate*~len, 2);\r\n\r\n/*\r\nSynthDefs\r\n*/\r\nSynthDef(\\tone1, {\r\n\targ gate = 1, freq = 440, out = 2, index=100, modMix = 0, dur;\r\n\tvar env = EnvGen.ar(Env.linen(0.0005, dur-0.001, 0.0005, 1, IRand(-8,-4)), gate, doneAction:2);\r\n\tvar mod = SinOsc.ar(freq*Rand(0.25,2),0,index-(index*modMix))+HenonC.ar(freq*IRand(4,8),mul:index*modMix);\r\n\tvar src = SinOsc.ar(freq+mod,0,0.125);\r\n\r\n\tOut.ar([out, out+1], src*env)\r\n}).add;\r\nSynthDef(\\grain1, {\r\n\targ gate = 1, out = 0, dur, freq=16, lfo=2, lfo2=1;\r\n\tvar env = EnvGen.ar(Env.linen(0.0005, dur-0.001, 0.0005, 1, IRand(-8,4)), gate, doneAction:2);\r\n\tvar src = GrainBuf.ar(2, Impulse.ar(freq), LFNoise0.ar(lfo).range(0.005,0.125), ~gBuf1,\r\n\t\tLFNoise0.ar(lfo2).range(-1,1), LFNoise0.ar(lfo).abs, 2, LFNoise0.ar(lfo2), -1, 1024, 0.25);\r\n\tOut.ar(out, src*env)\r\n}).add;\r\nSynthDef(\\grain2, {\r\n\targ gate = 1, out = 0, dur, freq=16, lfo=2, lfo2=1;\r\n\tvar env = EnvGen.ar(Env.linen(0.0005, dur-0.001, 0.0005, 1, IRand(-8,4)), gate, doneAction:2);\r\n\tvar src = GrainBuf.ar(2, Impulse.ar(freq), LFNoise0.ar(lfo).range(0.005,0.025), ~gBuf2,\r\n\t\tLFNoise0.ar(lfo2).range(-1,1), LFNoise0.ar(lfo).abs, 2, LFNoise0.ar(lfo2), -1, 1024, 0.25);\r\n\tOut.ar(out, src*env)\r\n}).add;\r\nSynthDef(\\grain3, {\r\n\targ gate = 1, out = 0, dur, freq=16, lfo=2, lfo2=1;\r\n\tvar env = EnvGen.ar(Env.linen(0.0005, dur-0.001, 0.0005, 1, IRand(-8,4)), gate, doneAction:2);\r\n\tvar src = GrainBuf.ar(2, Impulse.ar(freq), LFNoise0.ar(lfo).range(0.005,0.025), ~gBuf3,\r\n\t\tLFNoise0.ar(lfo2).range(-1,1), LFNoise0.ar(lfo).abs, 2, LFNoise0.ar(lfo2), -1, 1024, 0.25);\r\n\tOut.ar(out, src*env)\r\n}).add;\r\nSynthDef(\\grain4, {\r\n\targ gate = 1, out = 0, dur, freq=16, lfo=2, lfo2=1;\r\n\tvar env = EnvGen.ar(Env.linen(0.0005, dur-0.001, 0.0005, 1, IRand(-8,4)), gate, doneAction:2);\r\n\tvar src = GrainBuf.ar(2, Impulse.ar(freq), LFNoise0.ar(lfo).range(0.005,0.025), ~gBuf4,\r\n\t\tLFNoise0.ar(lfo2).range(-2,2), LFNoise0.ar(lfo).abs, 2, LFNoise0.ar(lfo2), -1, 1024, 0.25);\r\n\tOut.ar(out, src*env)\r\n}).add;\r\n\r\n/*\r\nPatterns\r\n*/\r\nPdef(\\seq1,\r\n\tPbind(\\instrument, \\tone1,\r\n\t\t\\dur, Prand([0.5,0.5,1],8),\r\n\t\t\\freq, Pwhite(25,12500,inf),\r\n\t\t\\index, Pwhite(10,1000,inf),\r\n\t\t\\modMix, Pwhite(0.0,1.0,inf),\r\n\t\t\\out, Prand([2, 4, 6], inf)\r\n)).play;\r\nPdef(\\seq2,\r\n\tPbind(\\instrument, \\grain1,\r\n\t\t\\dur, Prand([1,0.25,0.25],inf),\r\n\t\t\\freq, Pwhite(1,512,inf),\r\n\t\t\\lfo, Pwhite(0.5,16,inf),\r\n\t\t\\lfo2, Pwhite(0.25,1,inf),\r\n\t\t\\out, Prand([0], inf)\r\n)).play;\r\nPdef(\\seq3,\r\n\tPbind(\\instrument, \\grain2,\r\n\t\t\\dur, Prand([1,0.5,0.5],inf),\r\n\t\t\\freq, Pwhite(1,1024,inf),\r\n\t\t\\lfo, Pwhite(0.5,16,inf),\r\n\t\t\\lfo2, Pwhite(0.25,1,inf),\r\n\t\t\\out, Prand([0], inf)\r\n));\r\nPdef(\\seq4,\r\n\tPbind(\\instrument, \\grain3,\r\n\t\t\\dur, Prand([1,1,0.5],inf),\r\n\t\t\\freq, Pwhite(1,512,inf),\r\n\t\t\\lfo, Pwhite(8,160,inf),\r\n\t\t\\lfo2, Pwhite(2.5,10,inf),\r\n\t\t\\out, Prand([0], inf)\r\n));\r\nPdef(\\seq5,\r\n\tPbind(\\instrument, \\grain4,\r\n\t\t\\dur, Prand([0.125,0.25,0.125],inf),\r\n\t\t\\freq, Pwhite(1,128,inf),\r\n\t\t\\lfo, Pwhite(0.5,16,inf),\r\n\t\t\\lfo2, Pwhite(0.25,1,inf),\r\n\t\t\\out, Prand([0], inf)\r\n));\r\n\r\n/*\r\nNdefs\r\n*/\r\nNdef(\\rd1, {\r\n\targ note=36, vol = 0.125, rt = 1, rAmt = 127.rand;\r\n\tvar rate = rt.linlin(0,127,-1.0,1.0).round(0.5);\r\n\tvar bufWr = Phasor.ar(0,1,0,s.sampleRate*(~len-(~len*rAmt.linlin(0,127,0.0,1.0))))+(LFNoise2.ar(0.2!2).abs*(s.sampleRate*(~len*rAmt.linlin(0,127,0.0,1.0))));\r\n\tvar src = BufRd.ar(2,~buf1,Phasor.ar(0,rate,0,s.sampleRate*~len));\r\n\tBufWr.ar(In.ar(2,2)*vol+src,~buf1,bufWr);\r\n\tBufWr.ar(In.ar(2,1)*vol+Mix.new(src),~gBuf1,bufWr);\r\n\tsrc\r\n});\r\nNdef(\\rd2, {\r\n\targ note=36, vol = 0.125, rt = 1, rAmt = 127.rand;\r\n\tvar rate = rt.linlin(0,127,-1.0,1.0).round(0.5);\r\n\tvar bufWr = Phasor.ar(0,1,0,s.sampleRate*(~len-(~len*rAmt.linlin(0,127,0.0,1.0))))+(LFNoise2.ar(0.2!2).abs*(s.sampleRate*(~len*rAmt.linlin(0,127,0.0,1.0))));\r\n\tvar src = BufRd.ar(2,~buf2,Phasor.ar(0,rate,0,s.sampleRate*~len));\r\n\tBufWr.ar(In.ar(4,2)*vol+src,~buf2,bufWr);\r\n\tBufWr.ar(In.ar(4,1)*vol+Mix.new(src),~gBuf2,bufWr);\r\n\tsrc\r\n});\r\nNdef(\\rd3, {\r\n\targ note=36, vol = 0.125, rt = 1, rAmt = 127.rand;\r\n\tvar rate = rt.linlin(0,127,-1.0,1.0).round(0.5);\r\n\tvar bufWr = Phasor.ar(0,1,0,s.sampleRate*(~len-(~len*rAmt.linlin(0,127,0.0,1.0))))+(LFNoise2.ar(0.2!2).abs*(s.sampleRate*(~len*rAmt.linlin(0,127,0.0,1.0))));\r\n\tvar src = BufRd.ar(2,~buf3,Phasor.ar(0,rate,0,s.sampleRate*~len));\r\n\tBufWr.ar(In.ar(6,2)*vol+src,~buf3,bufWr);\r\n\tBufWr.ar(In.ar(6,1)*vol+Mix.new(src),~gBuf3,bufWr);\r\n\tsrc\r\n});\r\nNdef(\\rd4, {\r\n\targ note=36, vol = 0.125, rt = 1, rAmt = 127.rand;\r\n\tvar rate = rt.linlin(0,127,-1.0,1.0).round(0.5);\r\n\tvar bufWr = Phasor.ar(0,1,0,s.sampleRate*(~len-(~len*rAmt.linlin(0,127,0.0,1.0))))+(LFNoise2.ar(0.2!2).abs*(s.sampleRate*(~len*rAmt.linlin(0,127,0.0,1.0))));\r\n\tvar src = BufRd.ar(2,~buf4,Phasor.ar(0,rate,0,s.sampleRate*~len));\r\n\tBufWr.ar(In.ar(8,2)*vol+src,~buf4,bufWr);\r\n\tBufWr.ar(In.ar(8,1)*vol+Mix.new(src),~gBuf4,bufWr);\r\n\tsrc\r\n});\r\n\r\n/*\r\nMIDI Control\r\n*/\r\nMIDIdef.noteOn(\\notes, {arg ...args; args.postln;\r\n\tNdef(\\rd1).set(\\note, args[1]);\r\n\tNdef(\\rd2).set(\\note, args[1]);\r\n\tNdef(\\rd3).set(\\note, args[1]);\r\n\tNdef(\\rd4).set(\\note, args[1])\r\n});\r\nMIDIdef.cc(\\vol, {arg ...args; args.postln;\r\n\tswitch(args[1],\r\n\t\t0, {Ndef(\\rd1).set(\\vol, args[0]/4)};\r\n\t\t1, {Ndef(\\rd2).set(\\vol, args[0]/4)};\r\n\t\t2, {Ndef(\\rd3).set(\\vol, args[0]/4)};\r\n\t\t3, {Ndef(\\rd4).set(\\vol, args[0]/4)}\r\n\t);\r\n},(0..3)); // match cc 0 to 3\r\nMIDIdef.cc(\\rate, {arg ...args; args.postln;\r\n\tswitch(args[1],\r\n\t\t8, {\r\n\t\t\tNdef(\\rd1).set(\\rt, args[0]);\r\n\t\t\tNdef(\\rd2).set(\\rt, args[0]);\r\n\t\t\tNdef(\\rd3).set(\\rt, args[0]);\r\n\t\t\tNdef(\\rd4).set(\\rt, args[0])\r\n\t\t},\r\n\t\t9, {\r\n\t\t\tNdef(\\rd1).set(\\rAmt, args[0]);\r\n\t\t\tNdef(\\rd2).set(\\rAmt, args[0]);\r\n\t\t\tNdef(\\rd3).set(\\rAmt, args[0]);\r\n\t\t\tNdef(\\rd4).set(\\rAmt, args[0])\r\n\t\t}\r\n\t);\r\n},(8..11)); // match cc 8 to 11\r\n\r\n/*\r\nPlay\r\n*/\r\nPdef(\\seq1).play;\r\nPdef(\\seq2).play;\r\nPdef(\\seq3).play;\r\nPdef(\\seq4).play;\r\nPdef(\\seq5).play;\r\nNdef(\\rd1).play;\r\nNdef(\\rd2).play;\r\nNdef(\\rd3).play;\r\nNdef(\\rd4).play\r\n)",
   "labels" : [
      "noise"
   ],
   "description" : "A draft of performance setup I started working on some time ago. For now I've got simple MIDI controls and buffers that you can granularize. You can read more about it on (sound example): https://mycelialcordsblog.wordpress.com/2015/12/22/performance-unit-buffers-part-2/\r\nLet me know if you've got any suggestions.",
   "ancestor_list" : [],
   "author" : "rumush",
   "name" : "Performance Unit - Buffers (part 2)"
}
