Web MIDIAccess Api
I'm trying to use Controls as MIDI that a webpage can get values from via javascript.
https://developer.mozilla.org/en-US/docs/Web/API/MIDIAccess
I'm not getting any connections. Any thoughts of examples of this working?
-
ok, got working over localhost. ( was just not working in codepen.io ). anyone interested in code
<html>
<head>
<script>
varmidi = null; // global MIDIAccess object
functiononMIDIMessage( event ) {
varstr = "MIDI message received at timestamp " + event.timeStamp + "[" + event.data.length + " bytes]: ";
for (vari=0; i<event.data.length; i++) {
str += "0x" + event.data[i].toString(16) + " ";
}
console.log( str );
}
functionstartLoggingMIDIInput( midiAccess, indexOfPort ) {
midiAccess.inputs.forEach( function(entry) {entry.onmidimessage = onMIDIMessage;});
}
functiononMIDISuccess( midiAccess ) {
console.log( "MIDI ready!" );
midi = midiAccess; // store in the global (in real usage, would probably keep in an object instance)
for (varentryofmidiAccess.inputs) {
varinput = entry[1];
console.log( "Input port [type:'" + input.type + "'] id:'" + input.id +
"' manufacturer:'" + input.manufacturer + "' name:'" + input.name +
"' version:'" + input.version + "'" );
}
for (varentryofmidiAccess.outputs) {
varoutput = entry[1];
console.log( "Output port [type:'" + output.type + "'] id:'" + output.id +
"' manufacturer:'" + output.manufacturer + "' name:'" + output.name +
"' version:'" + output.version + "'" );
}
startLoggingMIDIInput(midi), null
}
functiononMIDIFailure(msg) {
console.log( "Failed to get MIDI access - " + msg );
}
functiononLoadHandler(){
navigator.requestMIDIAccess().then( onMIDISuccess, onMIDIFailure );
}
</script>
</head>
<bodyonload="onLoadHandler()">
MONOGRAM TEST
</body>
</html>
Please sign in to leave a comment.
Comments
1 comment