lib/file/encoder/event.js
function encodeEvent(event, runningStatus) {
    var delay, eventData, cursor;

    delay = encodeVarInt(event.delay);

    if (event instanceof MetaEvent) {
        eventData = encodeMetaEvent(event);
    } else if (event instanceof SysexEvent) {
        eventData = encodeSysexEvent(event);
    } else if (event instanceof ChannelEvent) {
        eventData = encodeChannelEvent(event);
    } else {
        throw new error.MIDIEncoderError(
            event.constructor.name,
            'known Event type'
        );
    }

    // if current type is the same as the last one,
    // we don't include it
    // (sysex events cancel the running status and
    //  meta events ignore it)
    if (event instanceof ChannelEvent) {
        if (runningStatus === eventData[0]) {
            eventData = eventData.slice(1);
        } else {
            runningStatus = eventData[0];
        }
    } else if (event instanceof SysexEvent) {
        runningStatus = null;
    }

    cursor = new BufferCursor(new buffer.Buffer(
        delay.length + eventData.length
    ));

    cursor.copy(delay);
    cursor.copy(eventData);

    return {
        runningStatus: runningStatus,
        data: cursor.buffer
    };
}
function encodeEvent(event, runningStatus) {
    var delay, eventData, cursor;

    delay = encodeVarInt(event.delay);

    if (event instanceof MetaEvent) {
        eventData = encodeMetaEvent(event);
    } else if (event instanceof SysexEvent) {
        eventData = encodeSysexEvent(event);
    } else if (event instanceof ChannelEvent) {
        eventData = encodeChannelEvent(event);
    } else {
        throw new error.MIDIEncoderError(
            event.constructor.name,
            'known Event type'
        );
    }

    // if current type is the same as the last one,
    // we don't include it
    // (sysex events cancel the running status and
    //  meta events ignore it)
    if (event instanceof ChannelEvent) {
        if (runningStatus === eventData[0]) {
            eventData = eventData.slice(1);
        } else {
            runningStatus = eventData[0];
        }
    } else if (event instanceof SysexEvent) {
        runningStatus = null;
    }

    cursor = new BufferCursor(new buffer.Buffer(
        delay.length + eventData.length
    ));

    cursor.copy(delay);
    cursor.copy(eventData);

    return {
        runningStatus: runningStatus,
        data: cursor.buffer
    };
}
function encodeEvent ( event , runningStatus ) { var delay , eventData , cursor ; delay = encodeVarInt ( event . delay ) ; if ( event instanceof MetaEvent ) { eventData = encodeMetaEvent ( event ) ; } else if ( event instanceof SysexEvent ) { eventData = encodeSysexEvent ( event ) ; } else if ( event instanceof ChannelEvent ) { eventData = encodeChannelEvent ( event ) ; } else { throw new error . MIDIEncoderError ( event . constructor . name , 'known Event type' ) ; } // if current type is the same as the last one, // we don't include it // (sysex events cancel the running status and //  meta events ignore it) if ( event instanceof ChannelEvent ) { if ( runningStatus === eventData [ 0 ] ) { eventData = eventData . slice ( 1 ) ; } else { runningStatus = eventData [ 0 ] ; } } else if ( event instanceof SysexEvent ) { runningStatus = null ; } cursor = new BufferCursor ( new buffer . Buffer ( delay . length + eventData . length ) ) ; cursor . copy ( delay ) ; cursor . copy ( eventData ) ; return { runningStatus : runningStatus , data : cursor . buffer } ; }
Encode a MIDI event

@param {module:midijs/lib/file/event~Event} event Event to encode
@param {number} [runningStatus] Previous status if applicable
@throws {module:midijs/lib/error~MIDIInvalidArgument}
Unknown event encountered
@return {Object} Encoded data and new running status
Encode a MIDI event