diff --git a/.gitignore b/.gitignore index 79780ba..cb4fdde 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules -public/bower_components \ No newline at end of file +public/bower_components +.AppleDouble +.DS_Store diff --git a/Brobot/brobot.js b/Brobot/brobot.js index f676082..55c0c73 100644 --- a/Brobot/brobot.js +++ b/Brobot/brobot.js @@ -13,13 +13,13 @@ module.exports = { initialize: function(){ // Calculate maximum latency var slowestInstrument = _.max(config.instruments, function(instrument){ - return instrument.softLatencyAbsolute; + return instrument.latency; }); - var maximumLatency = slowestInstrument.softLatencyAbsolute; + var maximumLatency = slowestInstrument.latency; // instantiate instrument controllers _.each(config.instruments, function(instrument){ - instrument.softLatencyRelative = maximumLatency - instrument.softLatencyAbsolute; + instrument.relativeOffset = maximumLatency - instrument.latency; instruments[instrument.note] = new instrumentController(instrument); }); this.initializeArduino(); @@ -65,11 +65,29 @@ module.exports = { if ([144,155,153].indexOf(instruction) !== -1){ this.onMidiNote(channel, velocity) } + if([128,129].indexOf(instruction) !== -1){ + this.onInstruction({ + instruction: instruction, + channel: channel, + velocity: velocity + }); + } + }, + onInstruction: function(e){ + if(e.instruction === 128){ + if(instruments[e.channel]){ + instruments[e.channel].determineMinimumDurationForContact(); + } + } }, onMidiNote: function (channel, velocity){ console.log("Midi note incoming", channel, velocity); - if(instruments[channel]){ - instruments[channel].queue(velocity); + if(new Date().getHours() >= 10 || true){ + if(instruments[channel]){ + instruments[channel].queue(velocity); + } + }else{ + console.log("Not within operating hours"); } } -}; \ No newline at end of file +}; diff --git a/Brobot/config.js b/Brobot/config.js index 75ac813..73145da 100644 --- a/Brobot/config.js +++ b/Brobot/config.js @@ -4,44 +4,44 @@ var config = { name: "(electric) Snare", note: 40, pinNumber: 9, - softVelocity: 20, - softLatencyAbsolute: 50 + latency: 8 // tested }, { name: "(electric) Kick", note: 36, pinNumber: 5, - softVelocity: 40, - softLatencyAbsolute: 50 + latency: 16 // tested }, { name: "(closed) Hat", note: 42, pinNumber: 10, - softVelocity: 20, - softLatencyAbsolute: 50 + latency: 15 // tested }, { name: "Crash (cymbal 1)", note: 49, pinNumber: 11, - softVelocity: 20, - softLatencyAbsolute: 50 + latency: 15 // tested }, { name: "Floor Tom (low)", note: 41, pinNumber: 6, - softVelocity: 50, - softLatencyAbsolute: 50 + latency: 9 // tested }, { name: "Low Tom", note: 45, pinNumber: 7, - softVelocity: 50, - softLatencyAbsolute: 50 + latency: 9 // tested } +// { +// name: "Ride", +// note: 51, +// pinNumber: 10, +// softLatencyAbsolute: 8 +// } ] } -module.exports = config; \ No newline at end of file +module.exports = config; diff --git a/Brobot/instrument-controller.js b/Brobot/instrument-controller.js index 1704b88..c12d402 100644 --- a/Brobot/instrument-controller.js +++ b/Brobot/instrument-controller.js @@ -8,12 +8,25 @@ var InstrumentController = function(instrument, config) { // properties and methods InstrumentController.prototype = { - // delayForVelocity(velocity:Int) return Int - // calculates delay in MS from strike to impact for given :velocity - delayForVelocity: function(velocity){ - // TODO : Make exponential, not linear - var velocityFactor = 1 / 128 * velocity; - return Math.ceil(this.softLatencyAbsolute * velocityFactor); + // DEVELOPMENT METHODS + determineMinimumDurationForContact: function(){ + var self = this; + var min = 5; // minimum duration in milliseconds + var max = 30; // maximum duration in milliseconds + + for(var x=min; x= 0.5.0", - "serialport": "^2.1.0", + "moment": "^2.15.0", + "node-pre-gyp": "^0.6.30", + "serialport": "^2.1.2", "underscore": "^1.8.3" + }, + "devDependencies": { + "debug": "^2.2.0", + "node-pre-gyp": "^0.6.30" } }