lib/connect/driver.js
function Driver(native) {
    var outputs = [], inputs = [], length, i;

    EventEmitter.call(this);
    this.native = native;

    length = native.outputs.size;

    for (i = 0; i < length; i += 1) {
        outputs[i] = new Output(native.outputs.get(i));
    }

    length = native.inputs.size;

    for (i = 0; i < length; i += 1) {
        inputs[i] = new Input(native.inputs.get(i));
    }

    this.outputs = outputs;
    this.output = null;
    this.inputs = inputs;
    this.input = null;

    native.onconnect = function (event) {
        var port = event.port;

        if (port.type === 'input') {
            port = new Input(port);
            this.inputs.push(port);
        } else {
            port = new Output(port);
            this.outputs.push(port);
        }

        this.emit('connect', port);
    }.bind(this);

    native.ondisconnect = function (event) {
        var port = event.port;

        if (port.type === 'input') {
            port = new Input(port);
            this.inputs = this.inputs.filter(function (input) {
                return (input.id !== port.id);
            });
        } else {
            port = new Output(port);
            this.outputs = this.outputs.filter(function (output) {
                return (output.id !== port.id);
            });
        }

        this.emit('disconnect', port);
    }.bind(this);
}
function Driver(native) {
    var outputs = [], inputs = [], length, i;

    EventEmitter.call(this);
    this.native = native;

    length = native.outputs.size;

    for (i = 0; i < length; i += 1) {
        outputs[i] = new Output(native.outputs.get(i));
    }

    length = native.inputs.size;

    for (i = 0; i < length; i += 1) {
        inputs[i] = new Input(native.inputs.get(i));
    }

    this.outputs = outputs;
    this.output = null;
    this.inputs = inputs;
    this.input = null;

    native.onconnect = function (event) {
        var port = event.port;

        if (port.type === 'input') {
            port = new Input(port);
            this.inputs.push(port);
        } else {
            port = new Output(port);
            this.outputs.push(port);
        }

        this.emit('connect', port);
    }.bind(this);

    native.ondisconnect = function (event) {
        var port = event.port;

        if (port.type === 'input') {
            port = new Input(port);
            this.inputs = this.inputs.filter(function (input) {
                return (input.id !== port.id);
            });
        } else {
            port = new Output(port);
            this.outputs = this.outputs.filter(function (output) {
                return (output.id !== port.id);
            });
        }

        this.emit('disconnect', port);
    }.bind(this);
}
function Driver ( native ) { var outputs = [ ] , inputs = [ ] , length , i ; EventEmitter . call ( this ) ; this . native = native ; length = native . outputs . size ; for ( i = 0 ; i < length ; i += 1 ) { outputs [ i ] = new Output ( native . outputs . get ( i ) ) ; } length = native . inputs . size ; for ( i = 0 ; i < length ; i += 1 ) { inputs [ i ] = new Input ( native . inputs . get ( i ) ) ; } this . outputs = outputs ; this . output = null ; this . inputs = inputs ; this . input = null ; native . onconnect = function ( event ) { var port = event . port ; if ( port . type === 'input' ) { port = new Input ( port ) ; this . inputs . push ( port ) ; } else { port = new Output ( port ) ; this . outputs . push ( port ) ; } this . emit ( 'connect' , port ) ; } . bind ( this ) ; native . ondisconnect = function ( event ) { var port = event . port ; if ( port . type === 'input' ) { port = new Input ( port ) ; this . inputs = this . inputs . filter ( function ( input ) { return ( input . id !== port . id ) ; } ) ; } else { port = new Output ( port ) ; this . outputs = this . outputs . filter ( function ( output ) { return ( output . id !== port . id ) ; } ) ; } this . emit ( 'disconnect' , port ) ; } . bind ( this ) ; }
Construct a new Driver

@class Driver
@extends events.EventEmitter
@classdesc Enable you to access all the plugged-in MIDI
devices and to control them

@param {MIDIAccess} native Native MIDI access
Construct a new Driver