BLOGGER TEMPLATES AND TWITTER BACKGROUNDS

Sunday, 28 February 2010

Drum sequencing with Patterns

This is v2 of my drum sequencer. It uses Patterns instead of a routine and therefore has a slightly more intuitve method of editing, as you can see the whole pattern laid out in a grid. There are randomised Patterns used to control the pitch of the cymbal and kick, and the decay on the hi-hat. The code could be neatened up a lot but there are way cooler things I could be doing...like...
1. Integrating a GUI to control volume/pitch/decay of different drums.
2. Create a way of selecting different patterns.
3. Create a controller to put shuffle on the hi-hats.
4. Make some GUI-editable laser sounds.
5. Integrate a bassline synthesiser.
6. Put some chords on top.
7. Make an arpeggiator...


// Kick Drum

SynthDef(\kick,
    {arg vol= 1, decay= 1, pitch= 1, filter= 1, on=0;
    var sin, pw, kik, kikfilter, volon;
    volon= vol*on;
    sin= LFTri.ar(freq: Line.kr(40,20,0.1*decay,doneAction:2)*pitch,
            add: 0, mul: 0.3*volon);
    pw= Pulse.ar(freq: 40, add: 0,
               mul: EnvGen.ar(Env.perc(0,0.07,0.3*volon)));
    kik= Mix.new([sin,pw]);
    kikfilter= LPF.ar(in: kik, freq: XLine.kr(200,30,0.1*decay)*filter);

    Out.ar(0, kikfilter)}).store  

// Snare Drum

SynthDef(\snare,
    {arg vol= 1, on= 0, decay= 1, pitch= 1, filter= 1, filter2= 1;
    var noise, filtap, volon, tri, snare, snaref, snaref2;
    volon= vol*on;
    filtap= EnvGen.ar(Env.perc(0,0.2*decay,0.2*volon,1));
    noise= WhiteNoise.ar(mul: filtap, add: Line.kr(-3.5,2,1));
    tri= Pulse.ar(freq: Line.kr(60*pitch,228,0.3,doneAction:2),
               mul: Line.kr(0.1,0.00,0.1)*volon);
    snare= noise+tri;
    snaref= HPF.ar(in: snare, freq: Line.kr(800,200,0.22)*filter);
    snaref2= LPF.ar(in: snaref, freq: Line.kr(600,1000,0.81)*filter2);
Out.ar(0, snaref*on)}).store

// Hi-hats

SynthDef(\hats,
    {arg vol= 1, decay= 1, on=0;
    var noise, filter, envel, menv,onvol;
    onvol= on*vol;
    menv= EnvGen.ar(Env.perc(0.3,0.01,1,4));
    noise= PinkNoise.ar(mul: menv*onvol*7, add: Line.kr(0,0,0.03*decay,doneAction:2));
    envel= EnvGen.ar(Env.adsr(0,0.2*decay,0.7,0.2,2900));
    filter= HPF.ar(in: noise, freq: envel);
Out.ar(0, filter)}).store

// Other thing

SynthDef(\cymbal,
    {arg vol= 0.5, decay= 1, pitch= 1, on= 0;
    var sq1, sq2, volon;
    volon= vol*on;
    sq1= Pulse.ar(freq: Line.kr(623*pitch,223,0.2*decay,doneAction:2)*pitch,
            mul: 0.3*volon);
    sq2= Pulse.ar(add: 0,
    freq:EnvGen.ar(Env.triangle(0.8*decay,300)),
        mul: 0.3*volon);
Out.ar(0, sq1*sq2)}).store


(
var clock,
hh, hhpatt, kd, kdpatt, sn, snpatt, cy, cypatt,
cypitch, hhdecay, basspitch, snrdc;
clock= TempoClock(8);
kd= Pseq([1,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,0],inf);
hh= Pseq([1,1,1,1, 1,0,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1],inf);
sn= Pseq([0,0,0,0, 1,0,0,0, 0,0,0,0, 1,0,0,0],inf);
cy= Pseq([0,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,0, 0,0,1,0],inf);

cypitch= Pxrand([1,2,3,0.3, 1.2,0.6],inf);
hhdecay= Pseq([1,1,2,1, 1,2,1,1, 1,3,1,1, 1,2,1,1],inf);
basspitch= Pseq([2,2,3],inf);
snrdc= Prand([1,1,1,1,1,1.3],inf);

hhpatt= Pbind(    \on,Pseq([hh],inf),
    \instrument, \hats,
    \decay,Pseq([hhdecay],inf));
kdpatt= Pbind(  \on,Pseq([kd],inf),
    \instrument, \kick,
    \vol,1,\decay,4,\pitch,Pseq([basspitch],inf),\filter,115);
snpatt= Pbind( \on,Pseq([sn],inf),
    \instrument, \snare,
    \vol,1,\decay,Pseq([snrdc],inf),\pitch,5);
cypatt= Pbind( \on,Pseq([cy],inf),
    \instrument, \cymbal,
    \vol,1,\decay,1.5,\pitch,Pseq([cypitch],inf));

Ppar([hhpatt,kdpatt,snpatt,cypatt]).play(clock); )
 

0 comments: