Esempio n. 1
0
        MIDI; //requiring would form a circular dependency :(

    //Set up prototype interface object and inheritance chain
    function MIDIOutput(name) {
        MIDIPort.call(this, name, 'output');

        //now is a good time to load in the MIDI depedency
        if (MIDI === undefined) {
            //require lookup is expensive
            MIDI = require('interfaces/MIDI');
        }
    }
Esempio n. 2
0
    function MIDIInput(name) {
        MIDIPort.call(this, name, 'input');
        var self = this,
            eventHandler = null,
            attributes = {
                onmessage: {
                    set: function (aFunction) {
                        //clear prevously set event handler
                        if (eventHandler !== null) {
                            this.removeEventListener('message', eventHandler, false);
                            eventHandler = null;
                        }
                        //check if callable
                        if (aFunction.call && typeof aFunction.call === 'function') {
                            this.addEventListener('message', aFunction, false);
                            eventHandler = aFunction;
                        }
                        return eventHandler;
                    },
                    get: function () {
                        return eventHandler;
                    },
                    enumerable: false,
                    configurable: false
                }
            };

        function messageCallback(timestamp, data) {
            var e = new MIDIEvent('message', {
                data: new Uint8Array(data),
                port: self
            });
            self.dispatchEvent(e);
        }
        if (MIDI === undefined) {
            MIDI = require('interfaces/MIDI');
        }
        Object.defineProperties(this, attributes);
        //Listen for messages
        MIDI.midiInOpen(name, messageCallback);
    }