{
   "name" : "A simple drum machine",
   "author" : "coreyker",
   "ancestor_list" : [],
   "description" : "A simple drum machine, using synthetic (analog type) drum sounds. No SynthDef's were used, although this would be a good idea. The various \"players\" can be modified and re-evaluated while the Routine is running....",
   "labels" : [
      "drums",
      "sequence"
   ],
   "code" : "Server.default = s = Server.internal;\r\ns.boot;\r\n\r\n/* ----------------------\r\n   Synthetic bass drum\r\n   ---------------------- */\r\n\r\n\r\n~bass = {\r\n\targ amp=0.5;\r\n\t{\r\n\t\tvar amp_env, phase_env, phase, freq, dur;\r\n\r\n\t\tfreq = 50.rand + 40;\r\n\t\tdur = 0.25;\r\n\r\n\t\tamp_env   = EnvGen.ar(Env.perc(1e-6,dur), doneAction:2);\r\n\t\tphase_env = EnvGen.ar(Env.perc(1e-6,0.125));\r\n\r\n\t\tphase = SinOsc.ar(20,0,pi) * phase_env;\r\n\t\tSinOsc.ar([freq,1.01*freq],phase) * amp_env * amp;\r\n\t}\r\n}\r\n\r\n~bass.value.play;\r\n\r\n\r\n\r\n/* ----------------------\r\n   Synthetic snare\r\n   ---------------------- */\r\n\r\n\r\n~snare = {\r\n\targ amp=0.5;\r\n\t{\r\n\t\tvar amp_env, cut_freq, dur;\r\n\r\n\t\tcut_freq = 3000;\r\n\t\tdur = [0.0625, 0.125, 0.25].choose;\r\n\r\n\t\tamp_env = EnvGen.ar(Env.perc(1e-6, dur), doneAction:2);\r\n\t\tLPF.ar( {WhiteNoise.ar(WhiteNoise.ar)}.dup * amp_env, cut_freq ) * amp;\r\n\t}\r\n}\r\n\r\n~snare.value.play;\r\n\r\n\r\n\r\n/* ----------------------\r\n   Synthetic hi-hat\r\n   ---------------------- */\r\n\r\n\r\n~hat = {\r\n\targ amp=0.5;\r\n\t{\r\n\t\tvar amp_env, cut_freq, dur;\r\n\r\n\t\tcut_freq = 6000;\r\n\t\tdur = [0.0625, 0.125, 0.25].choose;\r\n\r\n\t\tamp_env = EnvGen.ar(Env.perc(1e-7, dur), doneAction:2);\r\n\t\tHPF.ar( {WhiteNoise.ar}.dup * amp_env, cut_freq ) * amp / 4;\r\n\t}\r\n}\r\n\r\n~hat.value.play;\r\n\r\n\r\n/* ------------------------\r\n   Simple 8-step sequencer\r\n   ------------------------ */\r\n\r\n~player = {\r\n\targ beat_list, synth;\r\n\t{\r\n\t\targ i;\r\n\t\tvar amp = beat_list.wrapAt(i);\r\n\t\tif( amp>0, { synth.value(amp).play } );\r\n\t}\r\n}\r\n\r\n~bd_player = ~player.value([1, 1, 0, 0.1, 0.5, 0, 0, 1], ~bass);\r\n~sn_player = ~player.value([1, 0.1, 0.75, 0, 0.175, 0, 1, 0.5], ~snare);\r\n~hh_player = ~player.value([1, 0.1, 0.1, 1, 0.25, 0.1, 0.75, 0.5], ~hat);\r\n\r\n\r\n(\r\nc = TempoClock.new(1);\r\n~swing = 0.3; // swing amount\r\n~times = [1 + ~swing, 1 - ~swing, 1 + ~swing, 1 - ~swing]; // add swing\r\n{\r\n\tinf.do{\r\n\t\targ i;\r\n\t\t~bd_player.value(i);\r\n\t\t~sn_player.value(i);\r\n\t\t~hh_player.value(i);\r\n\r\n\t\t~times.wrapAt(i).wait;\r\n\t};\r\n\r\n}.fork(c);\r\n)\r\n\r\nc.tempo = 6;\r\n\r\n~bd_player = ~player.value([0], ~bass);\r\n~sn_player = ~player.value([0], ~snare);\r\n~hh_player = ~player.value([0], ~hat);",
   "is_private" : null,
   "id" : "1-4WI"
}
