/
drum_machine.js
executable file
·37 lines (32 loc) · 1.22 KB
/
drum_machine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
var codetraxx = require('beatduino-helpers');
var exec = require('child_process').exec;
var KICK = "wavs/kick.wav";
var KICK2 = "wavs/KickDrum0016.aif";
var KICK3 = "wavs/KickDrum0013.aif";
//var SNARE = "wavs/SnareDrum0012.aif";
var SNARE = "wavs/Clap.aif";
function playrrr(wav ){
exec("play " + wav + " bass +7 echo 0.8 0.88 60 0.4");
}
codetraxx.subscribe( 'bpm', function(msg) {
var bpm = msg.bpm, microTick = msg.microTick, tickCounter = msg.tickCounter, beat = msg.beat;
console.log("BPM: " + bpm + " MICROTICK: " + microTick + " TICK COUNTER: " + tickCounter + " and BEAT is: " + beat);
if (/[1357]/.test(beat) && microTick == 1) {
console.log("MICROTICK IS A " + typeof microTick);
if (beat % 7 === 0 || beat % 3 === 0 ) {
console.log("Modulo beatches!");
exec("play " + KICK2 + " " + KICK3 + " bass +3");
} else {
playrrr(KICK);
}
} else if (/[2468]/.test(beat) && microTick == 1) {
randNum = codetraxx.randyNum(10);
setTimeout( function() {
return playrrr(SNARE);
},randNum);
} else if (/[5]/.test(beat) && microTick == 3 && Math.round(Math.random()*1)) {
console.log("SNEAKY!");
exec("play " + KICK2 + " " + KICK3 + " bass +3");
}
});