Permalink
Browse files

tweaked comment.

  • Loading branch information...
1 parent 2447a77 commit ecee82489db65afd3821746776d8b08e6dfced5d @cwilso committed Sep 10, 2013
Showing with 71 additions and 1 deletion.
  1. BIN .DS_Store
  2. +1 −1 index.html
  3. +70 −0 tests/MIDITest.html
View
BIN .DS_Store
Binary file not shown.
View
2 index.html
@@ -85,7 +85,7 @@ <h2 id="project_tagline">This is a polyfill using the <a href="http://jazz-soft.
if (inputs.length>0) {
input = inputs[0];
-// input.onmessage = handleMIDIMessage;
+// input.onmidimessage = handleMIDIMessage;
input.addEventListener("midimessage", handleMIDIMessage);
log.innerHTML += "Hooked up first input.\n";
}
View
70 tests/MIDITest.html
@@ -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>

0 comments on commit ecee824

Please sign in to comment.