lib/file/parser/event.js
function parseEvent(cursor, runningStatus) {
    var delay, status, result;

    delay = parseVarInt(cursor);
    status = cursor.readUInt8();

    // if the most significant bit is not set,
    // we use the last status
    if ((status & 0x80) === 0) {
        if (!runningStatus) {
            throw new error.MIDIParserError(
                'undefined event status',
                cursor.tell()
            );
        }

        status = runningStatus;
        cursor.seek(cursor.tell() - 1);
    } else {
        runningStatus = status;
    }

    if (status === 0xFF) {
        result = parseMetaEvent(delay, cursor);
    } else if (status === 0xF0 || status === 0xF7) {
        result = parseSysexEvent(delay, status & 0xF, cursor);
    } else if (status >= 0x80 && status < 0xF0) {
        result = parseChannelEvent(delay, status >> 4, status & 0xF, cursor);
    } else {
        throw new error.MIDIParserError(
            status,
            'known status type',
            cursor.tell()
        );
    }

    return {
        runningStatus: runningStatus,
        event: result
    };
}
function parseEvent(cursor, runningStatus) {
    var delay, status, result;

    delay = parseVarInt(cursor);
    status = cursor.readUInt8();

    // if the most significant bit is not set,
    // we use the last status
    if ((status & 0x80) === 0) {
        if (!runningStatus) {
            throw new error.MIDIParserError(
                'undefined event status',
                cursor.tell()
            );
        }

        status = runningStatus;
        cursor.seek(cursor.tell() - 1);
    } else {
        runningStatus = status;
    }

    if (status === 0xFF) {
        result = parseMetaEvent(delay, cursor);
    } else if (status === 0xF0 || status === 0xF7) {
        result = parseSysexEvent(delay, status & 0xF, cursor);
    } else if (status >= 0x80 && status < 0xF0) {
        result = parseChannelEvent(delay, status >> 4, status & 0xF, cursor);
    } else {
        throw new error.MIDIParserError(
            status,
            'known status type',
            cursor.tell()
        );
    }

    return {
        runningStatus: runningStatus,
        event: result
    };
}
function parseEvent ( cursor , runningStatus ) { var delay , status , result ; delay = parseVarInt ( cursor ) ; status = cursor . readUInt8 ( ) ; // if the most significant bit is not set, // we use the last status if ( ( status & 0x80 ) === 0 ) { if ( ! runningStatus ) { throw new error . MIDIParserError ( 'undefined event status' , cursor . tell ( ) ) ; } status = runningStatus ; cursor . seek ( cursor . tell ( ) - 1 ) ; } else { runningStatus = status ; } if ( status === 0xFF ) { result = parseMetaEvent ( delay , cursor ) ; } else if ( status === 0xF0 || status === 0xF7 ) { result = parseSysexEvent ( delay , status & 0xF , cursor ) ; } else if ( status >= 0x80 && status < 0xF0 ) { result = parseChannelEvent ( delay , status >> 4 , status & 0xF , cursor ) ; } else { throw new error . MIDIParserError ( status , 'known status type' , cursor . tell ( ) ) ; } return { runningStatus : runningStatus , event : result } ; }
Parse any type of MIDI event

@param {BufferCursor} cursor Buffer to parse
@param {number} [runningStatus] Previous status if applicable
@throws {module:midijs/lib/error~MIDIParserError}
Unknown event status encountered or running status undefined
while being requested by this event's data
@return {Object} Parsed event and new running status
Parse any type of MIDI event