Skip to content

Instantly share code, notes, and snippets.

@GavinJoyce
Last active October 25, 2021 19:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GavinJoyce/974028a20fbccac2b440421ce9765488 to your computer and use it in GitHub Desktop.
Save GavinJoyce/974028a20fbccac2b440421ce9765488 to your computer and use it in GitHub Desktop.
Ep 2
var MidiStream = require('midi-stream');
var push = MidiStream('Ableton Push 2 User Port');
push.on('data', function(data) {
var instruction = data[0];
var note = data[1] - 36;
var row = Math.floor(note / 8);
var column = note % 8;
if(instruction === 144) {
playRowColumn(row, column, randomVelocity());
playRowColumn(7 - row, 7 - column, randomVelocity());
}
});
function playRowColumn(row, column, velocity, delay) {
row = row % 8;
column = column % 8;
var note = (row * 8) + column;
play(note, velocity, delay);
}
function play(note, velocity, delay) {
setTimeout(() => push.write([144, note + 36, velocity]), delay || 0);
}
function randomVelocity() {
return Math.floor((Math.random() * 128));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment