<commit_before>/*
 * SimpleMidiInput.js
 * v1.1.1
 * Author: <NAME>
 * License: MIT
 */

(function () {
    "use strict";

    /**
     * Returns whether a value is numeric
     * @param {*} value
     * @returns {boolean}
     */
    var isNumeric = function (value) {
        return !isNaN(parseFloat(value)) && isFinite(value);
    };

    /**
     * Returns whether a value is an array
     * @param {*} value
     * @returns {boolean}
     */
    var isArray = function (value) {
        return Object.prototype.toString.call(value) === '[object Array]';
    };

    /**
     * Returns whether a value is a MIDIInputMap
     * @param {*} value
     * @returns {boolean}
     */
    var isMIDIInputMap = function (value) {
        return Object.prototype.toString.call(value) === '[object MIDIInputMap]';
    };

    /**
     * Returns whether a value is a MIDIInput
     * @param {*} value
     * @returns {boolean}
     */
    var isMIDIInput = function (value) {
        return Object.prototype.toString.call(value) === '[object MIDIInput]';
    };

    /**
     * Returns whether a value is a MIDIAccess
     * @param {*} value
     * @returns {boolean}
     */
    var isMIDIAccess = function (value) {
        return Object.prototype.toString.call(value) === '[object MIDIAccess]';
    };

    /**
     * Returns whether a value is a function
     * @param {*} value
     * @returns {boolean}
     */
    var isFunction = function (value) {
        return typeof value === 'function';
    };

    /**
     * Returns whether a value is an iterator
     * @param {*} value
     * @returns {boolean}
     */
    var isIterator = function (value) {
        return Object.prototype.toString.call(value) === '[object Iterator]';
    };

    /**
     * Force whatever it receive to an array of MIDIInput when possible
     * @param {Function|Iterator|MIDIAccess|MIDIInputMap|MIDIInput|MIDIInput[]} source
     * @returns {MIDIInput[]} Array of MIDIInput
     */
    var normalizeInputs = function (source) {
        var inputs = [],
            input;

        if (isMIDIInput(source)) {
            inputs.push(source);
        } else {
            if (isMIDIAccess(source)) {
                source = source.inputs;
            }

            if (isFunction(source)) {
                source = source();
            } else if (isMIDIInputMap(source)) {
                source = source.values();
            }

            if (isArray(source)) {
                inputs = source;
            } else if (isIterator(source)) {
                while (input = source.next().value) {
                    inputs.push(input);
                }
            }
        }

        return inputs;
    };

    /**
     * Convert Variable Length Quantity to integer
     * @param {int} first LSB
     * @param {int} second MSB
     * @returns {int} Standard integer
     */
    var readVLQ = function (first, second) {
        return (second << 7) + (first & 0x7F);
    };

    /**
     * Instanciate a SimpleMidiInput object
     * @param {MIDIInput|MIDIInput[]} [midiInput]
     * @constructor
     */
    var SimpleMidiInput = function (midiInput) {
        this.events = {};
        this.innerEventListeners = {};

        if (midiInput) {
            this.attach(midiInput);
        }
    };

    SimpleMidiInput.prototype.filter = null;
    SimpleMidiInput.prototype.events = null;
    SimpleMidiInput.prototype.innerEventListeners = null;

    /**
     * Attach this instance to one or several MIDIInput
     * @param {MIDIAccess|MIDIInputMap|MIDIInput|MIDIInput[]} midiInput
     * @returns {SimpleMidiInput} Instance for method chaining
     */
    SimpleMidiInput.prototype.attach = function (midiInput) {
        var inputs = normalizeInputs(midiInput);

        for (var i = 0; i < inputs.length; i++) {
            this.attachIndividual(inputs[i]);
        }

        return this;
    };

    /**
     * Attach this instance to a given MIDIInput
     * @private
     * @param {MIDIInput} midiInput
     */
    SimpleMidiInput.prototype.attachIndividual = function (midiInput) {
        if (!this.innerEventListeners[midiInput.id]) {
            var self = this,
                listener = function (event) {
                    self.processMidiMessage(event.data);
                };

            midiInput.addEventListener("midimessage", listener);
            this.innerEventListeners[midiInput.id] = {
                input: midiInput,
                listener: listener
            };
        }
    };

    /**<commit_msg>Fix #3, addEventListener not working anymore<commit_after>/*
 * SimpleMidiInput.js
 * v1.1.1
 * Author: <NAME>
 * License: MIT
 */

(function () {
    "use strict";

    /**
     * Returns whether a value is numeric
     * @param {*} value
     * @returns {boolean}
     */
    var isNumeric = function (value) {
        return !isNaN(parseFloat(value)) && isFinite(value);
    };

    /**
     * Returns whether a value is an array
     * @param {*} value
     * @returns {boolean}
     */
    var isArray = function (value) {
        return Object.prototype.toString.call(value) === '[object Array]';
    };

    /**
     * Returns whether a value is a MIDIInputMap
     * @param {*} value
     * @returns {boolean}
     */
    var isMIDIInputMap = function (value) {
        return Object.prototype.toString.call(value) === '[object MIDIInputMap]';
    };

    /**
     * Returns whether a value is a MIDIInput
     * @param {*} value
     * @returns {boolean}
     */
    var isMIDIInput = function (value) {
        return Object.prototype.toString.call(value) === '[object MIDIInput]';
    };

    /**
     * Returns whether a value is a MIDIAccess
     * @param {*} value
     * @returns {boolean}
     */
    var isMIDIAccess = function (value) {
        return Object.prototype.toString.call(value) === '[object MIDIAccess]';
    };

    /**
     * Returns whether a value is a function
     * @param {*} value
     * @returns {boolean}
     */
    var isFunction = function (value) {
        return typeof value === 'function';
    };

    /**
     * Returns whether a value is an iterator
     * @param {*} value
     * @returns {boolean}
     */
    var isIterator = function (value) {
        return Object.prototype.toString.call(value) === '[object Iterator]';
    };

    /**
     * Force whatever it receive to an array of MIDIInput when possible
     * @param {Function|Iterator|MIDIAccess|MIDIInputMap|MIDIInput|MIDIInput[]} source
     * @returns {MIDIInput[]} Array of MIDIInput
     */
    var normalizeInputs = function (source) {
        var inputs = [],
            input;

        if (isMIDIInput(source)) {
            inputs.push(source);
        } else {
            if (isMIDIAccess(source)) {
                source = source.inputs;
            }

            if (isFunction(source)) {
                source = source();
            } else if (isMIDIInputMap(source)) {
                source = source.values();
            }

            if (isArray(source)) {
                inputs = source;
            } else if (isIterator(source)) {
                while (input = source.next().value) {
                    inputs.push(input);
                }
            }
        }

        return inputs;
    };

    /**
     * Convert Variable Length Quantity to integer
     * @param {int} first LSB
     * @param {int} second MSB
     * @returns {int} Standard integer
     */
    var readVLQ = function (first, second) {
        return (second << 7) + (first & 0x7F);
    };

    /**
     * Instanciate a SimpleMidiInput object
     * @param {MIDIInput|MIDIInput[]} [midiInput]
     * @constructor
     */
    var SimpleMidiInput = function (midiInput) {
        this.events = {};
        this.innerEventListeners = {};

        if (midiInput) {
            this.attach(midiInput);
        }
    };

    SimpleMidiInput.prototype.filter = null;
    SimpleMidiInput.prototype.events = null;
    SimpleMidiInput.prototype.innerEventListeners = null;

    /**
     * Attach this instance to one or several MIDIInput
     * @param {MIDIAccess|MIDIInputMap|MIDIInput|MIDIInput[]} midiInput
     * @returns {SimpleMidiInput} Instance for method chaining
     */
    SimpleMidiInput.prototype.attach = function (midiInput) {
        var inputs = normalizeInputs(midiInput);

        for (var i = 0; i < inputs.length; i++) {
            this.attachIndividual(inputs[i]);
        }

        return this;
    };

    /**
     * Attach this instance to a given MIDIInput
     * @private
     * @param {MIDIInput} midiInput
     */
    SimpleMidiInput.prototype.attachIndividual = function (midiInput) {
        if(!this.innerEventListeners[midiInput.id]) {
            var originalListener = midiInput.onmidimessage,
                listener,
                self = this;

            if (typeof originalListener === 'function') {
                listener = function (event) {
                    originalListener(event);
                    self.processMidiMessage(event.data);
                };
            } else {
                listener = function (event) {
                    self.processMidiMessage(event.data);
                };
            }

            midiInput.onmidimessage = listener;

            this.innerEventListeners[midiInput.id] = {
                input: midiInput,
                listener: listener
            };
        }
    };

    /**
{'fraction_non_alphanumeric': 0.12095147074439842, 'fraction_numerical': 0.0015928639694170119, 'mean_word_length': 1.8530748258103604, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3357557', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2681, 'n_words': 639}