Jazz-Soft.net

We make it sound!

Home » Examples » Jazz-Plugin » MIDI Gear

MIDI Gear

Identify the model of your MIDI instrument:

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

 

How it works

In this demo, we send the ID Request SysEx (f0 7e 7f 06 01 f7) to each MIDI Out, and wait for the ID Response SysEx (f0 7e xx 06 02 xx ... xx f7) from MIDI In-s.

If your device is not recognized, please send us the response string and the model of your device for we could update our scripts to recognize it in the future.

Some MIDI devices dont send ID Response.

See a newer example implemented with JZZ.js.

Page source

<!DOCTYPE html>
<html>
<head>
<title>MIDI Gear</title>
<meta http-equiv="X-UA-Compatible" content="requiresActiveX=true"/>

<script src="JZZ.Midi.js"></script>
<script src="JZZ.MidiGear.js"></script>
<script src="MidiPool.js"></script>

<style type="text/css">
p.noresp {
 color:#888;
 margin-left:6em;
}
p.resp {
 color:#00c;
 margin-left:6em;
}
p.modelid {
 color:#888;
 margin-left:8em;
}
p.model {
 color:#888;
 margin-left:8em;
}
p.modelid span {
 color:#000;
 font-size:1.1em;
}
p.model span {
 color:#000;
 font-size:1.5em;
 font-weight:bold;
}
</style>
</head>

<body>
<!header>

<h1>MIDI Gear</h1>

<button onclick='test();'>Test</button>
<div id=result>&nbsp;</div>

<script><!--
var Pool;
var ins;
var outs;
var res=document.getElementById('result');

try{
 Pool=new MidiPool;
 ins=Pool.MidiInList();
 outs=Pool.MidiOutList();

 for(var i in outs) Pool.OpenMidiOut(outs[i]);
 for(var i in ins) Pool.OpenMidiIn(ins[i]);
}
catch(err){ alert(err);}

function midi_out(name,msg){
 Pool.MidiOut(name,msg);
}
var count;
var sent=0;
var resp=0;
function test(){
 count=0;
 res.innerHTML='';
 for(var i=0;i<ins.length;i++) Pool.ClearMidiIn(ins[i]);
 step();
}
function step(){
 for(var i=0;i<ins.length;i++){
  var msg;
  var sysex=[];
  while(msg=Pool.QueryMidiIn(ins[i])){

   msg.shift(); // don't care about time stamp

   if(!sysex.length && msg[0]!=0xf0) continue;

   sysex=sysex.concat(msg);
   for(var j=1;j<sysex.length;j++){
    if(sysex[j]>=0x80){
     sysex=sysex.slice(0,sysex[j]==0xf7?j+1:j);
     resp+=report(ins[i],sysex);
     sysex=[];
    }
   }
  }
  if(sysex.length) resp+report(ins[i],sysex);
 }
 if(sent && !resp)res.innerHTML=res.innerHTML+'<p class=noresp>&lt;== no response</p>';

 while(outs[count]=='Microsoft GS Wavetable Synth' || outs[count]=='Apple DLS Synth') count++;
 if(count>=outs.length){ sent=0; return;}
 res.innerHTML=res.innerHTML+'<p>sending request ==&gt; '+outs[count]+'</p>';
 Pool.MidiOut(outs[count],[0xF0,0x7E,0x7F,0x06,0x01,0xF7]);
 count++;
 sent=1; resp=0;
 window.setTimeout(step,200);
}
function report(dev,msg){
 if(msg[1]!=0x7e || msg[3]!=0x06 || msg[4]!=0x02) return 0;
 var gear=JZZ_.MidiGear(msg);
 var str='';
 var model='unidentified';
 if(gear.brand){
  model=gear.brand;
  if(gear.model){
   model+=' '+gear.model+' '+gear.descr;
  }
  else model+=', unidentified model';
 }
 for(var i in msg) str+=(msg[i]<16 ? '0' : '')+msg[i].toString(16)+' ';
 res.innerHTML=res.innerHTML+'<p class=resp> &lt;== '+dev+'</p><p class=modelid>response: <span>'+str+'</span></p><p class=model>Model: <span>'+model+'</span></p>';
 return 1;
}
--></script>

</body>
</html>

MidiPool.js

// Jazz-Soft.net
// This code is totally free to copy, modify and distribute.

function MidiPool(){
 var place;
 var arr=[];
 var inputs={};
 var outputs={};
 if(arguments.length){
  if(arguments[0].isJazz){
   place=arguments[0].parentNode;
   arr[0]={plugin:arguments[0]};
  }
  else{
   try{ // if this is a good location to create plugins
    var tmp=create_plugin(arguments[0]);
    arr[0]={plugin:tmp};
    place=arguments[0];
   }
   catch(err){}
  }
 }
 if(place===undefined){ // otherwise create plugins at where the current script is
  var scripts=document.getElementsByTagName('script');
  place=scripts[scripts.length-1].parentNode;
 }
 if(!arr.length) arr[0]={plugin:create_plugin(place)};

 if(navigator.appName=='Microsoft Internet Explorer'){ document.onfocusin=onFocusIE; document.onfocusout=onBlurIE;}
 else{ window.onfocus=connectMidi; window.onblur=disconnectMidi;}

 function create_plugin(where){
  var obj=document.createElement('object');
  obj.classid="CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90";
  if(!obj.isJazz) obj.type="audio/x-jazz";
  obj.style.visibility='hidden';
  obj.style.width='0px'; obj.style.height='0px';
  where.appendChild(obj);
  if(obj.isJazz) return obj;
  where.removeChild(obj);
  throw "Cannot create Jazz-Plugin";
 }
 function connectMidi(){
  try{
   for(i=0;i<arr.length;i++){
    if(arr[i].in){
     if(arr[i].func) arr[i].plugin.MidiInOpen(arr[i].in,arr[i].func);
     else arr[i].plugin.MidiInOpen(arr[i].in);
    }
    if(i && arr[i].out) arr[i].plugin.MidiOutOpen(arr[i].out);
   }
  }
  catch(err){res.innerHTML=res.innerHTML+' ERR: '+err;}
 }
 function disconnectMidi(){
  try{
   for(i=0;i<arr.length;i++){
    if(arr[i].in) arr[i].plugin.MidiInClose();
    if(i && arr[i].out) arr[i].plugin.MidiOutClose(); // don't close the default out
   }
  }
  catch(err){}
 }
 function onFocusIE(){
  active_element=document.activeElement;
  connectMidi();
 }
 var active_element;
 function onBlurIE(){
  if(active_element!=document.activeElement){ active_element=document.activeElement; return;}
  disconnectMidi();
 }

 this.MidiOutList=function(){ return arr[0].plugin.MidiOutList();}
 this.MidiInList=function(){ return arr[0].plugin.MidiInList();}
 this.MidiOut=function(name,msg){ if(outputs[name]) outputs[name].plugin.MidiOutLong(msg);}
 this.ClearMidiIn=function(name){ if(inputs[name]) inputs[name].plugin.ClearMidiIn();}
 this.QueryMidiIn=function(name){ if(inputs[name]) return inputs[name].plugin.QueryMidiIn();}
 this.OpenMidiOut=function(name){
  if(outputs[name]) return;
  var i;
  for(i=0;i<arr.length;i++) if(!arr[i].out) break;
  if(i==arr.length){
   arr[i]={plugin:create_plugin(place)};
  }
  arr[i].out=name;
  arr[i].plugin.MidiOutOpen(name);
  outputs[name]=arr[i];
 }
 this.OpenMidiIn=function(name,func){
  if(!inputs[name]){
   var i;
   for(i=0;i<arr.length;i++) if(!arr[i].in) break;
   if(i==arr.length){
    arr[i]={plugin:create_plugin(place)};
   }
   arr[i].in=name;
   inputs[name]=arr[i];
  }
  if(func) inputs[name].plugin.MidiInOpen(name,func); else inputs[name].plugin.MidiInOpen(name);
  inputs[name].func=func;
 }
}

See also