Jazz-Soft.net
We make it sound!
Home » Examples » Jazz-Plugin » Connected MIDI

Connected MIDI

This example requires Jazz-Plugin v.1.4 or later.

This page requires Jazz-Plugin v.1.4 or later.

How it works

This demo shows how to set handlers for MIDI port Connect/Disconnect events.

If you have a USB MIDI device, try to plug or unplug it. The page will display an alert and update the port list above.

Page source

<!DOCTYPE html>
<html>
<head>
<title>Connected MIDI</title>

<meta http-equiv="X-UA-Compatible" content="requiresActiveX=true"/>

<style type="text/css">
.hidden {
 visibility: hidden;
 width: 0px;
 height: 0px;
 margin: 0px;
 padding: 0px;
 border-style: none;
 border-width: 0px;
 max-width: 0px;
 max-height: 0px;
}
</style>
</head>

<body>
<h1>Connected MIDI</h1>

<object id="Jazz1" classid="CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90" class="hidden">
  <object id="Jazz2" type="audio/x-jazz" class="hidden">
<p style="visibility:visible;">This page requires <a href=http://jazz-soft.net>Jazz-Plugin</a> ...</p>
  </object>
</object>

<div id=out>This page requires Jazz-Plugin v.1.4 or later.</div>

<script><!--
var Jazz = document.getElementById("Jazz1"); if(!Jazz || !Jazz.isJazz) Jazz = document.getElementById("Jazz2");
var out=document.getElementById("out");
function list_midi_ports(){
 var i;
 var info;
 var txt="<ul><li>MIDI-Out ports:</li><ul>";
 var outs=Jazz.MidiOutList();
 if(outs.length){
  for(i=0;i<outs.length;i++){
   txt+="<li>"+outs[i];
   info=Jazz.MidiOutInfo(outs[i]);
   if(info.length>=3){
    txt+="<ul><li>Manufacturer: "+info[1]+"; Version: "+info[2]+"</li></ul>";
   }
   txt+="</li>";
  }
 } else {
  txt+="<li>none</li>";
 }
 txt+="</ul><li>MIDI-In ports:</li><ul>";
 var ins=Jazz.MidiInList();
 if(ins.length){
  for(i=0;i<ins.length;i++){
   txt+="<li>"+ins[i];
   info=Jazz.MidiInInfo(ins[i]);
   if(info.length>=3){
    txt+="<ul><li>Manufacturer: "+info[1]+"; Version: "+info[2]+"</li></ul>";
   }
   txt+="</li>";
  }
 } else {
  txt+="<li>none</li>";
 }
 txt+="</ul></ul>";
 out.innerHTML=txt;
}
if(Jazz.isJazz){
 list_midi_ports();
 Jazz.OnConnectMidiOut(function(name){ list_midi_ports(); alert("New MIDI-Out port connected: "+name);});
 Jazz.OnDisconnectMidiOut(function(name){ list_midi_ports(); alert("MIDI-Out port disconnected: "+name);});
 Jazz.OnConnectMidiIn(function(name){ list_midi_ports(); alert("New MIDI-In port connected: "+name);});
 Jazz.OnDisconnectMidiIn(function(name){ list_midi_ports(); alert("MIDI-In port disconnected: "+name);});
}
--></script>

</body>
</html>

See also