Skip to content

Instantly share code, notes, and snippets.

@gridwalk
Created December 8, 2013 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gridwalk/7854235 to your computer and use it in GitHub Desktop.
Save gridwalk/7854235 to your computer and use it in GitHub Desktop.
This is a simple template for processing MIDI events with JavaScript, using the Jazz Plugin.
<!--
MIDI JS Template for use with the Jazz plugin.
Google Jazz browser plugin and install it.
You also need a USB MIDI controller to use this.
-->
<html>
<head>
<style>
#Jazz{
visibility: hidden;
}
</style>
</head>
<body>
<object id="Jazz" type="audio/x-jazz"></object>
<div id="midi-info"></div>
<script>
var Jazz = document.getElementById("Jazz");
var code = document.getElementById('code');
Jazz.MidiInOpen(0);
Jazz.MidiOutOpen(1);
window.setInterval(function(){
var arr;
while(arr=Jazz.QueryMidiIn()){
a=arr.slice(1,arr.length);
// Every MIDI signal will have all three parts: a[0] a[1] and a[2]
// a[0] usually corresponds to areas of the controller
// a[1] is an individual control
// a[2] is the current value of the individual control (1 - 127)
// So to get all MIDI events, run an list of if/else statements like so:
if( a[0]==176 && a[1]==14 ){ //KNOB 14
// Do something with a[2]
}else if( a[0]==144 && a[1]==21 && a[2]==64){ //BUTTON 21
// Do something. When the button is pressed, a[2] goes to 64
}
}
},0);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment