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

Select MIDI Out

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

How it works

If you have an external MIDI instrument connected to your computer, you will see its name in the drop-down list above. Select the instrument and press the button to play C chord on it.

Notice the try{...} block in the end of the script. It is required to get rid of error messages if the user has an old version of the plugin, or no plugin installed.

Alternative condition check if(Jazz.MidiOutList){...} does not work well with VBA controls in Microsoft Internet Explorer.

Page source

<!DOCTYPE html>
<html>
<head>
<title>Select MIDI Out</title>

<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>Select MIDI Out</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=selectmididiv class="hidden"><p>MIDI Out: <select id=selectmidi onchange='changemidi();'></select></p></div>
<p><button onmousedown='play();' onmouseup='stop();'> Press to play... </button></p>

<script><!--
var Jazz = document.getElementById("Jazz1"); if(!Jazz || !Jazz.isJazz) Jazz = document.getElementById("Jazz2");
function play(){
 if(Jazz.isJazz){
  Jazz.MidiOut(0x90,60,100);
  Jazz.MidiOut(0x90,64,100);
  Jazz.MidiOut(0x90,67,100);
 }
}
function stop(){
 if(Jazz.isJazz){
  Jazz.MidiOut(0x80,60,0);
  Jazz.MidiOut(0x80,64,0);
  Jazz.MidiOut(0x80,67,0);
 }
}
function changemidi(){
 Jazz.MidiOutOpen(select.options[select.selectedIndex].value);
}
var select=document.getElementById('selectmidi');
try{
 var list=Jazz.MidiOutList();
 for(var i in list){
  select[i]=new Option(list[i],list[i],i==0,i==0);
 }
 document.getElementById('selectmididiv').className='';
}
catch(err){}
--></script>

</body>
</html>

See also