Last active
April 30, 2020 14:56
-
-
Save TheWispy/acf2ebb5ab1b178c387e6d5d49d6857f to your computer and use it in GitHub Desktop.
APC20 MIDI controller Hydra script
This file contains 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
navigator.requestMIDIAccess() | |
.then(onMIDISuccess, onMIDIFailure); | |
function onMIDISuccess(midiAccess) { | |
console.log(midiAccess); | |
var inputs = midiAccess.inputs; | |
var outputs = midiAccess.outputs; | |
for (var input of midiAccess.inputs.values()){ | |
input.onmidimessage = getMIDIMessage; | |
} | |
} | |
function onMIDIFailure() { | |
console.log('Could not access your MIDI devices.'); | |
} | |
var cc=Array(256).fill(0.5).map(x => Array(256).fill(0.5)); | |
getMIDIMessage = function(midiMessage) { | |
var arr = midiMessage.data; | |
var index_a = arr[0]; | |
var index_b = arr[1]; | |
var val = (arr[2]+1)/128.0; | |
console.log('Midi received on cc' + index_a + ' ,' + index_b + ' value:' + val); | |
cc[index_a][index_b] = val; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment