jsPlayCommand Demo

Demonstration of jsPlayCommand.

HTML

<script src="http://www.kreativekorp.com/lib/jsPlayCommand/WebMIDIAPI.js"></script>
<script src="http://www.kreativekorp.com/lib/jsPlayCommand/jsPlayCommand.js"></script>
<div id="loading">
    Loading...
</div>
<div id="demo">
    <p>Select MIDI Device:</p>
    <div id="output"></div>
    <button id="scale">Play Scale</button>
    <button id="inigo">Play Inigo's Song</button>
    <button id="birthday">Invite Lawsuit</button>
</div>
<div id="error">
    Could not get access to MIDI devices.
</div>

CSS

div {
    font-family: sans-serif;
}
input {
    margin-right: 5px;
}
button {
    display: block;
    margin-top: 20px;
}

JavaScript

$('#loading').show();
$('#demo').hide();
$('#error').hide();

jsPlayCommand.start(function() {
    $('#scale').click(function() {
        jsPlayCommand.play('harpsichord', 'ch d e f g a b c5w');
    });
    $('#inigo').click(function() {
        jsPlayCommand.play('harpsichord', 'c4 a3 f c4 a3 f c4 d c c c');
    });
    $('#birthday').click(function() {
        jsPlayCommand.play('music box', 'c4e c dq c f eh');
    });
    jsPlayCommand.outputs().forEach(function(output) {
        var radio = $('<input>');
        radio.attr('type', 'radio');
        radio.attr('name', 'outputs');
        radio.attr('value', output.name);
        if (output.name == jsPlayCommand.getDefaultOutput().name) {
            radio.attr('checked', 'checked');
        }
        var label = $('<label>');
        label.append(radio);
        label.append($('<span>').text(output.name));
        $('#output').append($('<div>').append(label));
        radio.change(function() {
            jsPlayCommand.setDefaultOutput(output);
        });
    });
    $('#demo').show();
    $('#loading').hide();
}, function() {
    $('#error').show();
    $('#loading').hide();
});