Last active
October 25, 2021 19:24
-
-
Save GavinJoyce/974028a20fbccac2b440421ce9765488 to your computer and use it in GitHub Desktop.
Ep 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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