Created
September 9, 2021 14:18
-
-
Save fronterior/f5aa29e0698d4f7f526639936951c32c to your computer and use it in GitHub Desktop.
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
// Focusrite-Novation Launchpad Mini | |
const midiDeviceMap = {}; | |
const midi = await navigator.requestMIDIAccess(); | |
midi.inputs.forEach(entry => { | |
const key = entry.manufacturer+entry.name+entry.version; | |
if (!midiDeviceMap[key]) midiDeviceMap[key] = {}; | |
midiDeviceMap[key].input = entry; | |
}); | |
midi.outputs.forEach(entry => { | |
const key = entry.manufacturer+entry.name+entry.version; | |
if (!midiDeviceMap[key]) midiDeviceMap[key] = {}; | |
midiDeviceMap[key].output = entry; | |
}); | |
for (const key in midiDeviceMap) { | |
const {input, output} = midiDeviceMap[key]; | |
input.onmidimessage = ({data}) => { | |
const [chn, pos, vel] = data; | |
output.send([chn, pos, vel ? Math.floor(Math.random() * 127) + 1 : 0]); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment