diff options
| author | Mick Grierson <mickgrierson@strangebook.local> | 2011-10-21 16:58:50 +0100 |
|---|---|---|
| committer | Mick Grierson <mickgrierson@strangebook.local> | 2011-10-21 16:58:50 +0100 |
| commit | 6dcd4a08f246122ea71f5813eec16ddb30c5d80f (patch) | |
| tree | a4d596f759972efcda71b96d8ea14bfab94ccdd1 /maximilian_examples | |
| parent | 2b01058183bdbab5ddf50905d34db2138946e276 (diff) | |
basic drum machine example
Diffstat (limited to 'maximilian_examples')
| -rw-r--r-- | maximilian_examples/18.DrumMachine.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/maximilian_examples/18.DrumMachine.cpp b/maximilian_examples/18.DrumMachine.cpp new file mode 100644 index 0000000..a655ffb --- /dev/null +++ b/maximilian_examples/18.DrumMachine.cpp @@ -0,0 +1,53 @@ +#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. + +maxiOsc 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 kicktrigger,snaretrigger; + +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. + + + printf("Summary:\n%s", kick.getSummary());//get info on samples if you like. + //beats.getLength(); +} + +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 + + + 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; + } + + if (kicktrigger==1) { + + kick.trigger(); + + } + + if (snaretrigger==1) { + + snare.trigger(); + + } + + sampleOut=kick.playOnce()+snare.playOnce();//just play the file. Looping is default for all play functions. + + *output=sampleOut; + +}
\ No newline at end of file |
