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

Hello MIDI

How it works

Click the button above to hear the C-major chord.

This is the most basic example of how to play MIDI via Javascript.

See the same example implemented purely with Jazz-Plugin.

Page source

<!DOCTYPE html>
<html>
<head>
<title>Hello MIDI!</title>
<meta http-equiv="X-UA-Compatible" content="requiresActiveX=true"/>
<script src="JZZ.js"></script>
<script src="JZZ.synth.Tiny.js"></script>
</head>

<body>
<h1>Hello MIDI!</h1>

<script><!--
JZZ.synth.Tiny.register('Synth');
var port = JZZ().openMidiOut().or(function(){alert('Cannot open MIDI port!');});

function play(){
  port.send([0x90,60,100]).send([0x90,64,100]).send([0x90,67,100]);
}

function stop(){
  port.send([0x80,60,0]).send([0x80,64,0]).send([0x80,67,0]);
}
--></script>

<button onmousedown='play();' onmouseup='stop();'> Press to play... </button>

</body>
</html>

See also