{
   "ancestor_list" : [],
   "description" : "Translucent \"pad\" interface to play with subtractive synthesis. White noise triggered by either Impulses of LFPulse, then filtered by a Band Pass Filter (BPF). 16 different Patterns are created using this basic synth.",
   "name" : "Subtractive Synthesis GUI Demo 2",
   "author" : "Bruno Ruviaro",
   "is_private" : null,
   "id" : "1-4UI",
   "code" : "// ************************************\r\n// Subtractive Synthesis Demo (GUI)\r\n// Patch 2 - Patterns of Filtered Noise\r\n// Bruno Ruviaro, 2013-07-27\r\n// ************************************\r\n\r\n/*\r\n\r\nWhite Noise triggered by either Impulses of LFPulse;\r\nThen filtered by a Band Pass Filter (BPF).\r\n16 different Patterns are created using this basic synth.\r\n\r\n*/\r\n\r\ns.waitForBoot({\r\n\r\n\tvar win, buttonArray, padsArray, patternArray, volumeSlider, menu, whichBus, masterOut = 0.1;\r\n\r\n\tpadsArray = Array.newClear(16);\r\n\tpatternArray = Array.newClear(16);\r\n\r\n\t/*~masterOut = 0.1;*/\r\n\r\n\twhichBus = Bus.control(s, 1);\r\n\twhichBus.value = 0;\r\n\r\n\tWindow.closeAll;\r\n\ts.meter;\r\n\twin = Window.new(\"Subtractive Synthesis - Patterns of Filtered Noise\", Rect(450, 160, 480, 540)).front;\r\n\r\n\twin.background = Color.new255(102, 102, 102, 150);\r\n\twin.alpha = 0.95;\r\n\r\n\t// Change the gaps and margins to see how they work\r\n\twin.view.decorator = FlowLayout(win.view.bounds, margin: 10@10, gap: 20@20 );\r\n\r\n\tbuttonArray = Array.fill(16, {Button(win.view, 100@100)});\r\n\r\n\tbuttonArray.do({arg item, count;\r\n\t\titem.states = [[], [[], Color.black, Color.rand]]});\r\n\r\n\tbuttonArray.do({arg item, count;\r\n\t\titem.action = {arg state;\r\n\t\t\tcase\r\n\t\t\t{state.value==1} {padsArray[count] = patternArray[count].play}\r\n\t\t\t{state.value==0} {padsArray[count].stop}\r\n\t}});\r\n\r\n\t// subwin = CompositeView(win, Rect(0, 0, 460, 50));\r\n\t// subwin.background = Color.rand;\r\n\r\n\t// Noise Source menu\r\n\tmenu = PopUpMenu(win, 80 @ 35);\r\n\tmenu.items = [\"Pop\", \"Rasp\"];\r\n\tmenu.action = {arg menu;\r\n\t\tcase\r\n\t\t{menu.value==0} {whichBus.set(0.0)}\r\n\t\t{menu.value==1} {whichBus.set(1.0)}};\r\n\r\n\tvolumeSlider = EZSlider(\r\n\t\tparent: win,\r\n\t\tbounds: 355 @ 35,\r\n\t\tlabel: \"VOLUME\",\r\n\t\tcontrolSpec: ControlSpec(-40, 3, \\lin, 0.01, -12, \"dB\"),\r\n\t\taction: {|ez| masterOut.set(\\amp, ez.value.dbamp)},\r\n\t\tunitWidth: 30)\r\n\t.setColors(\r\n\t\tstringColor: Color.white,\r\n\t\tsliderBackground: Color.grey(0.9),\r\n\t\tnumNormalColor: Color.grey);\r\n\r\n\r\n\t// Patterns\r\n\r\n\tpatternArray[0] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\freq, Pwhite(100, 5500),\r\n\t\t\\pulseFreq, Pwhite(5, 10),\r\n\t\t\\dur, 0.3,\r\n\t\t\\amp, Pwhite(0.1, 0.5),\r\n\t\t\\rq, Pwhite(0.001, 0.05));\r\n\r\n\tpatternArray[1] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\degree, Pseq([0,3,5,7,9,11,14,17], inf),\r\n\t\t\\pulseFreq, Pwhite(1, 9),\r\n\t\t\\dur, 0.3,\r\n\t\t\\amp, 1,\r\n\t\t\\rq, 0.01);\r\n\r\n\tpatternArray[2] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\degree, Prand([0,3,5,7,9,11,14,17], inf) - 12,\r\n\t\t\\pulseFreq, Pwhite(1, 9),\r\n\t\t\\dur, 0.3,\r\n\t\t\\sustain, 0.1,\r\n\t\t\\amp, 1,\r\n\t\t\\rq, 0.1);\r\n\r\n\tpatternArray[3] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\degree, Pxrand([0,3,5,7,9,11,14,17], inf) + 12,\r\n\t\t\\pulseFreq, Pwhite(1, 9),\r\n\t\t\\dur, Pseq([0.2, 0.3, 0.2, 0.4], inf) * Pwhite(2, 4),\r\n\t\t\\sustain, 0.6,\r\n\t\t\\amp, Pwhite(0.3, 0.6),\r\n\t\t\\rq, Prand([0.05, 0.1], inf));\r\n\r\n\tpatternArray[4] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\scale, Scale.phrygian,\r\n\t\t\\degree, Pseq([0,3,5,7,9,11,14,17], inf),\r\n\t\t\\pulseFreq, Pwhite(5, 19),\r\n\t\t\\dur, 0.3,\r\n\t\t\\amp, 1,\r\n\t\t\\rq, Pwhite(0.005, 0.01));\r\n\r\n\tpatternArray[5] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\scale, Scale.phrygian,\r\n\t\t\\degree, Pseq([0,3,5,7,9,11,14,17], inf) + Pwrand([0, 1], [0.9, 0.1], inf),\r\n\t\t\\pulseFreq, Pwhite(5, 19),\r\n\t\t\\dur, 0.33,\r\n\t\t\\amp, 1,\r\n\t\t\\rq, Pwhite(0.005, 0.01));\r\n\r\n\tpatternArray[6] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\scale, Scale.phrygian,\r\n\t\t\\degree, Pseq([0,3,5,7,9,11,14,17], inf) + Pwrand([0, 1], [0.9, 0.1], inf),\r\n\t\t\\pulseFreq, 0.5,\r\n\t\t\\dur, Pseq( (0.1!60) ++ (0.2!8)   , inf),\r\n\t\t\\amp, 1,\r\n\t\t\\rq, Pwrand([0.005, 0.01], [0.95, 0.05], inf));\r\n\r\n\tpatternArray[7] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\freq, Pwhite(1000, 9500),\r\n\t\t\\pulseFreq, Pwhite(5, 10),\r\n\t\t\\dur, 0.3,\r\n\t\t\\amp, Pwhite(0.1, 0.5),\r\n\t\t\\rq, Pwhite(0.001, 0.05));\r\n\r\n\tpatternArray[8] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\degree, Pshuf([4,3,5,7,9,11,14,17], inf),\r\n\t\t\\pulseFreq, Pwhite(1, 9),\r\n\t\t\\dur, 0.3,\r\n\t\t\\amp, 1,\r\n\t\t\\rq, 0.01);\r\n\r\n\tpatternArray[9] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\note, Prand([0,3,5,7,9,11,14,17], inf),\r\n\t\t\\pulseFreq, Pwhite(1, 9),\r\n\t\t\\dur, 0.3,\r\n\t\t\\sustain, 0.1,\r\n\t\t\\amp, 1,\r\n\t\t\\rq, 0.1);\r\n\r\n\tpatternArray[10] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\degree, Pxrand([0,3,5,7,9,11,14,17], inf) - 12,\r\n\t\t\\pulseFreq, Pwhite(1, 9),\r\n\t\t\\dur, Pseq([0.2, 0.1, 0.2, 0.4], inf) * Pwhite(1, 4),\r\n\t\t\\sustain, 0.2,\r\n\t\t\\amp, Pwhite(0.3, 0.6),\r\n\t\t\\rq, Prand([0.05, 0.1], inf));\r\n\r\n\tpatternArray[11] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\scale, Scale.phrygian,\r\n\t\t\\degree, Pseq([0,5,9,3,7,11], inf),\r\n\t\t\\pulseFreq, Pwhite(5, 19),\r\n\t\t\\dur, 0.3,\r\n\t\t\\amp, 1,\r\n\t\t\\rq, Pwhite(0.005, 0.01));\r\n\r\n\tpatternArray[12] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\scale, Scale.phrygian,\r\n\t\t\\degree, Pseq([0,3,5,7,9,11,14,17], inf) + Pwrand([0, 12], [0.5, 0.5], inf),\r\n\t\t\\pulseFreq, Pwhite(1, 19),\r\n\t\t\\dur, 0.43,\r\n\t\t\\amp, 1,\r\n\t\t\\rq, Pwhite(0.005, 0.01));\r\n\r\n\tpatternArray[13] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\scale, Scale.locrian,\r\n\t\t\\degree, Pseq([7,8,6,5,4,3,2,1,0,4], inf) + Pwrand([0, 1], [0.9, 0.1], inf),\r\n\t\t\\pulseFreq, 0.5,\r\n\t\t\\dur, Pseq( (0.1!10) ++ (0.2!8)   , inf),\r\n\t\t\\amp, 0.6,\r\n\t\t\\rq, Pwrand([0.005, 0.01], [0.95, 0.05], inf));\r\n\r\n\tpatternArray[14] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\degree, Pxrand([1,3,4,7], inf) + 24,\r\n\t\t\\pulseFreq, Pwhite(1, 9),\r\n\t\t\\dur, Pseq([0.2, 0.3, 0.1, 0.4], inf) * Pwhite(2, 4),\r\n\t\t\\sustain, 0.6,\r\n\t\t\\amp, Pwhite(0.3, 0.6),\r\n\t\t\\rq, Prand([0.05, 0.1], inf));\r\n\r\n\tpatternArray[15] = Pbind(\r\n\t\t\\instrument, \"noise-quneo-2\",\r\n\t\t\\scale, Scale.mixolydian,\r\n\t\t\\degree, Pseq([0,7,5,3,9,11,0], inf) + 12,\r\n\t\t\\pulseFreq, Pwhite(5, 19),\r\n\t\t\\dur, 0.5,\r\n\t\t\\amp, 0.5,\r\n\t\t\\rq, Pwhite(0.05, 0.09));\r\n\r\n\t// SynthDefs\r\n\r\n\t{\r\n\t\tSynthDef(\"noise-quneo-2\", {arg freq = 1000, pulseFreq = 10, amp = 0.1, rq = 0.001, att = 0.01, dec = 0.3, sus = 1, rel = 1, gate = 1;\r\n\t\t\tvar snd, env;\r\n\t\t\tenv = EnvGen.kr(Env.adsr(att, dec, sus, rel), gate: gate, doneAction: 2);\r\n\t\t\tsnd = BPF.ar(\r\n\t\t\t\tin: WhiteNoise.ar(Select.ar(In.kr(whichBus),\r\n\t\t\t\t\t[\r\n\t\t\t\t\t\tImpulse.ar(pulseFreq),\r\n\t\t\t\t\t\tLFPulse.ar(pulseFreq,0,0.5) * 0.01\r\n\t\t\t\t\t]\r\n\t\t\t\t)),\r\n\t\t\t\tfreq: freq,\r\n\t\t\t\trq: Lag.kr(rq, 1));\r\n\t\t\tsnd = snd * env * Lag.kr(amp, 1) * 100;\r\n\t\t\tsnd = Clip.ar(snd, -0.5, 0.5);\r\n\t\t\tOut.ar(0, [snd, snd]);\r\n\t\t}).add;\r\n\r\n\t\tSynthDef(\\amp, {arg inbus=0, amp = 0.1;\r\n\t\t\tReplaceOut.ar(inbus, In.ar(inbus, 2) * amp);\r\n\t\t}).add;\r\n\r\n\t\t// Wait for SynthDefs to be added...\r\n\t\ts.sync;\r\n\r\n\t\t// Now call the Master Out Synth:\r\n\t\tmasterOut = Synth(\"amp\", addAction: \\addToTail);\r\n\r\n\t}.fork;\r\n\r\n\twin.onClose = {\r\n\t\tpadsArray.do{ |item, count| padsArray[count].stop};\r\n\t\tWindow.closeAll;\r\n\t\tmasterOut.free;\r\n\t\t\"Done!\".postln;\r\n\t};\r\n\r\n\tCmdPeriod.doOnce({Window.closeAll});\r\n\r\n\t\"Subtractive Synthesis Demo 2\".postln;\r\n\t\"\".postln;\r\n\r\n}); // end of block",
   "labels" : [
      "gui",
      "patterns",
      "synthesis techniques",
      "subtractive synthesis"
   ]
}
