Home

abudaan edited this page May 1, 2012 · 24 revisions

Basic example:

window.addEventListener('load', function() {

    midiBridge.init(function(MIDIAccess){

        //get the first MIDI input
        var input = MIDIAccess.getInput(MIDIAccess.enumerateInputs()[0]);

        //get the first MIDI output    
        var output = MIDIAccess.getOutput(MIDIAccess.enumerateOutputs()[0]);

        input.addEventListener('midimessage',function(e){
            //send the messages from the input to the output
            output.sendMIDIMessage(e);

            console.log(e.toString());
            //e.g. NOTE ON | CHAN:0 | NOTE:75 | VELOCITY:49 | STATUS:144 | TIME:2126966
        });            
    });           
});

Check the online examples, you can find the code of the examples in the /examples folder of the repository.

  1. Basic example. code | launch

  2. Connects your your computer keyboard to a MIDI output. code | launch

  3. Example that lets you select a MIDI input and a MIDI output. Incoming MIDI messages are displayed. code | launch

  4. Same example as above, but the MIDI output gets connected directly in Java which results in better playback performance. If your application does a lot of graphical updates on incoming MIDI events, you should use this method. code | launch

  5. Select a MIDI file on your local hard drive and play it back on a MIDI output. You can change the instrument as well. code | launch

  6. Same example as above, but the MIDI output gets connected directly in Java. code | launch

  7. Example of how you can send MIDI events generated in Javascript to a MIDI output. code | launch


Below are links to pages that describe the various parts of the MIDIBridge:

MIDIBridge

MIDIAccess

MIDIDevice

MIDIMessage

Sequencer

Sequence

Track

License