Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | ||
<title>Web MIDI test</title> | ||
<script> | ||
var midi=null; | ||
var inputs=null; | ||
var outputs=null; | ||
var input=null; | ||
var output=null; | ||
var log=null; | ||
|
||
function runTest() { | ||
if (!log) | ||
log = document.getElementById("log"); | ||
log.innerText = "Starting up MIDI...\n"; | ||
navigator.requestMIDIAccess().then( success, failure ); | ||
} | ||
|
||
function handleMIDIMessage( ev ) { | ||
// testing - just reflect. | ||
log.innerText += "Message: " + ev.data.length + " bytes, timestamp: " + ev.timestamp; | ||
if (ev.data.length == 3) | ||
log.innerText += " 0x" + ev.data[0].toString(16) + " 0x" + ev.data[1].toString(16) + " 0x" + ev.data[2].toString(16); | ||
if (output) { | ||
output.send( ev.data ); | ||
log.innerText += " reflected to output '" + output.name + "'"; | ||
} | ||
log.innerText += "\n"; | ||
} | ||
|
||
function success( midiAccess ) { | ||
log.innerText += "MIDI ready!\n"; | ||
midi = midiAccess; | ||
|
||
inputs = midi.inputs(); | ||
log.innerText += inputs.length+" inputs:\n"; | ||
for (var i=0;i<inputs.length;i++) | ||
log.innerText += i + ": " + inputs[i].name + "\n"; | ||
|
||
if (inputs.length>0) { | ||
input = inputs[0]; | ||
input.onmidimessage = handleMIDIMessage; | ||
log.innerText += "Hooked up first input: " + input.name + ".\n"; | ||
} | ||
|
||
outputs = midi.outputs(); | ||
log.innerText += outputs.length+" outputs:\n"; | ||
for (var i=0;i<outputs.length;i++) | ||
log.innerText += i + ": " + outputs[i].name + "\n"; | ||
|
||
if (outputs.length) { | ||
output = outputs[0]; | ||
} | ||
} | ||
|
||
function failure( error ) { | ||
alert( "Failed to initialize MIDI - " + ((error.code==1) ? "permission denied" : ("error code " + error.code)) ); | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<button onclick="runTest();">Test MIDI!</button> | ||
<pre id="log"> | ||
</pre> | ||
<div id="MIDIPlugin" style="position:absolute; visibility:hidden"></div> | ||
</body> | ||
</html> |