diff options
| author | Mick Grierson <mickgrierson@strangebook.lan> | 2011-10-21 23:04:31 +0100 |
|---|---|---|
| committer | Mick Grierson <mickgrierson@strangebook.lan> | 2011-10-21 23:04:31 +0100 |
| commit | 948f46623d24fac7aa41172434f7e8d46ce21ce1 (patch) | |
| tree | a4f79b166134200385059f8fbec6252360a53f12 /maximilian_examples/18.DrumMachine.cpp | |
| parent | 6dcd4a08f246122ea71f5813eec16ddb30c5d80f (diff) | |
basic drum machine example (minor edit)
Diffstat (limited to 'maximilian_examples/18.DrumMachine.cpp')
| -rw-r--r-- | maximilian_examples/18.DrumMachine.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/maximilian_examples/18.DrumMachine.cpp b/maximilian_examples/18.DrumMachine.cpp index a655ffb..a5a73c3 100644 --- a/maximilian_examples/18.DrumMachine.cpp +++ b/maximilian_examples/18.DrumMachine.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,8 +13,10 @@ double sampleOut; void setup() {//some inits - 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. + //YOU HAVE TO PROVIDE THE SAMPLES.... + + kick.load("/Users/yourusername/somewhere/kick.wav");//load in your samples. Provide the full path to a wav file. + snare.load("/Users/yourusername/somewhere/snare.wav");//load in your samples. Provide the full path to a wav file. printf("Summary:\n%s", kick.getSummary());//get info on samples if you like. @@ -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 |
