{
   "code" : "(\r\nSynthDef(\\glitchySampler, {\r\n\t|\r\n\tbuffer,                //the buffer should contain a stereo file\r\n\tout          = 0,\r\n\tgate         = 1\r\n\trate         = 1,      //buffer playback rate\r\n\tamp          = 0.5,\r\n\tatt          = 0.01,   //attack time of the adsr envelope\r\n\tdec          = 0.4,    //decay time\r\n\tsust         = 0.7,    //sustain level\r\n\trel          = 1,      //release time (synth is freed when the envelope finishes)\r\n\tlpf          = 20000,  //low pass filtering frequency\r\n\thpf          = 20,     //high pass filtering frequency\r\n\ttrigfreq     = 1,      //the frequency at which the PlayBuf UGen is triggered to jump to the start position\r\n\ttrigrand     = 0,      //the actual trigger frequency is calculated by (\\trigfreq * (2 to the power of (this * an LFNoise UGen with range -1 to 1))); setting this to 0 will result in a constant trigger frequency\r\n\tstartmul     = 1,      // \\trigfreq also controls the frequency of an LFNoise UGen which changes PlayBuf's starting point; this is a multiplier for that frequency; setting this to 0 will result in a constant starting point\r\n\tdirmul       = 1,      //same as above, but controlling the frequency of random playback direction changes\r\n\trandmul      = 1       //same as above, but for random trigger frequency changes\r\n\t|\r\n\r\n\tvar start, direction, rand, trig, sig, env;\r\n\r\n\tstart = {LFNoise1.kr(trigfreq*startmul, 0.5, 0.5)}!2; //modulating the starting point; different for left and right channel\r\n\r\n\tdirection = {Select.kr(LFNoise1.kr(trigfreq*dirmul) > 0, [-1, 1])}!2; //modulating the direction; different for left and right channel\r\n\r\n\trand = {LFNoise1.kr(trigfreq*randmul)}!2; //modulating the trigger frequency; different for left and right channel\r\n\r\n\ttrig = Impulse.kr(trigfreq*pow(2, trigrand*rand)); //the trigger for PlayBuf\r\n\r\n\tsig = PlayBuf.ar(2, buffer, BufRateScale.kr(buffer)*rate*direction, trig, BufFrames.kr(buffer)*start, 1); //playing the (looping) stereo buffer\r\n\r\n\tenv = Env.adsr(att, dec, sust, rel, amp);\r\n\tenv = EnvGen.kr(env, gate, doneAction: 2); //simple adsr envelope which frees the synth when finished\r\n\r\n\tsig = LPF.ar(HPF.ar(sig*env, hpf), lpf); //basic filtering\r\n\r\n\tOut.ar(out, sig);\r\n\t}\r\n).add;\r\n)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////////////////////////\r\n// If you want to test the above fast, here is basically what I used for the EP - not really interesting though\r\n//////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\nb = Buffer.read(s, /*path to your stereo soundfile; I used recordings of a tuba, a western guitar and a panflute*/);\r\nMIDIClient.init;\r\nMIDIIn.connect(0, MIDIClient.sources[/*index of your device*/]);\r\n\r\n\r\n(\r\nvar activenotes = nil!128;\r\n\r\nvar sustain = 0;\r\n\r\nvar sustained = false!128;\r\n\r\nvar releasefunction = {|index|\r\n\r\n\tif(activenotes[index].notNil)\r\n\t{\r\n\t\tactivenotes[index].release;\r\n\t\tactivenotes[index] = nil;\r\n\t};\r\n};\r\n\r\n\r\nMIDIIn.noteOn = { arg src,chan, midinote, velocity;\r\n\r\n\treleasefunction.value(midinote);\r\n\r\n\tactivenotes[midinote] = Synth(\\glitchySampler,[\\buffer, b, \\rel, velocity/20, \\trigfreq, 0.15, \\trigrand, 1, \\rate, (midinote-60).midiratio, \\amp, velocity/(127.0*8), \\startmul, 2, \\dirmul, 0.3, \\randmul, 1, \\lpf, 7000]);\r\n\t//Synth(\\glitchySampler,[\\buffer, b, \\rel, velocity/20, \\trigfreq, 2, \\trigrand, 10, \\rate, (midinote-60).midiratio, \\amp, velocity/(127.0*8), \\startmul, 2, \\dirmul, 4, \\randmul, 2, \\lpf, 17000]);\r\n\t//Synth(\\glitchySampler,[\\buffer, b, \\rel, velocity/20, \\trigfreq, 0.4, \\trigrand, 5, \\rate, (midinote-60).midiratio, \\amp, velocity/(127.0*8), \\startmul, 1, \\dirmul, 1, \\randmul, 1, \\lpf, 4000]);\r\n\r\n};\r\n\r\n\r\nMIDIIn.noteOff = { arg src,chan, midinote, velocity;\r\n\r\n\tif(sustain == 0)\r\n\t{\r\n\t\treleasefunction.value(midinote);\r\n\t}{\r\n\t\tsustained[midinote] = true;\r\n\t};\r\n};\r\n\r\nMIDIIn.control = {|uid,channel,cN,v|\r\n\r\n\tif(cN == 64/*64 is the sustain pedal*/)\r\n\t{\r\n\t\tsustain = v;\r\n\r\n\t\tif(sustain == 0)\r\n\t\t{\r\n\t\t\tsustained.do{|value, index|\r\n\t\t\t\tif(value)\r\n\t\t\t\t{\r\n\t\t\t\t\tsustained[index] = false;\r\n\t\t\t\t\treleasefunction.value(index);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n};\r\n)",
   "is_private" : null,
   "id" : "1-4Ws",
   "labels" : [
      "sampler",
      "glitch"
   ],
   "ancestor_list" : [],
   "description" : "Hey guys!\r\nI used this code on my first release and some people asked for a look on it.\r\nIt's basically a PlayBuf UGen whose arguments are modulated to a user-defined degree by several LFNoise UGens, thus leading to playback direction changes and retriggering with different starting points.\r\n\r\nCheers!",
   "author" : "tigges-p",
   "name" : "glitchySampler"
}
