From 948f46623d24fac7aa41172434f7e8d46ce21ce1 Mon Sep 17 00:00:00 2001 From: Mick Grierson Date: Fri, 21 Oct 2011 23:04:31 +0100 Subject: basic drum machine example (minor edit) --- main.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 2b619e6..1888567 100755 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,11 @@ #include "maximilian.h" -maxiSample kick,snare; //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names. +maxiSample kick,snare; //we've got two sampleplayers -maxiOsc timer; +maxiOsc timer; //and a timer -int currentCount,lastCount,playHead,hit[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0}; -int snarehit[16]={0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0}; +int currentCount,lastCount,playHead,hit[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1}; //This is the sequence for the kick +int snarehit[16]={0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0};//This is the sequence for the snare int kicktrigger,snaretrigger; @@ -13,6 +13,8 @@ double sampleOut; void setup() {//some inits + //YOU HAVE TO PROVIDE THE SAMPLES.... + kick.load("/Users/mickgrierson/Documents/audio/blip.wav");//load in your samples. Provide the full path to a wav file. snare.load("/Users/mickgrierson/Documents/audio/snare.wav");//load in your samples. Provide the full path to a wav file. @@ -23,31 +25,34 @@ void setup() {//some inits void play(double *output) {//this is where the magic happens. Very slow magic. - currentCount=(int)timer.phasor(4);//this sets up a metronome that ticks 8 times a second + currentCount=(int)timer.phasor(8);//this sets up a metronome that ticks 8 times a second if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound - kicktrigger=hit[playHead%16]; - snaretrigger=snarehit[playHead%16]; - playHead++; - lastCount=0; + kicktrigger=hit[playHead%16];//get the value out of the array for the kick + snaretrigger=snarehit[playHead%16];//same for the snare + playHead++;//iterate the playhead + lastCount=0;//reset the metrotest } - if (kicktrigger==1) { + if (kicktrigger==1) {//if the sequence has a 1 in it - kick.trigger(); + kick.trigger();//reset the playback position of the sample to 0 (the beginning) } if (snaretrigger==1) { - snare.trigger(); + snare.trigger();//likewise for the snare } - sampleOut=kick.playOnce()+snare.playOnce();//just play the file. Looping is default for all play functions. + sampleOut=kick.playOnce()+snare.playOnce();//just play the file. No looping. - *output=sampleOut; - + output[0]=sampleOut;//left channel + output[1]=sampleOut;//right channel + + kicktrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering. + snaretrigger = 0; } \ No newline at end of file -- cgit v1.3