lib/file/encoder/event.js
function encodeChannelEvent(event) {
    var cursor, eventData, value;

    switch (event.type) {
    case ChannelEvent.TYPE.NOTE_OFF:
        eventData = new BufferCursor(new buffer.Buffer(2));

        eventData.writeUInt8(event.note);
        eventData.writeUInt8(event.velocity);
        break;
    case ChannelEvent.TYPE.NOTE_ON:
        eventData = new BufferCursor(new buffer.Buffer(2));

        eventData.writeUInt8(event.note);
        eventData.writeUInt8(event.velocity);
        break;
    case ChannelEvent.TYPE.NOTE_AFTERTOUCH:
        eventData = new BufferCursor(new buffer.Buffer(2));

        eventData.writeUInt8(event.note);
        eventData.writeUInt8(event.pressure);
        break;
    case ChannelEvent.TYPE.CONTROLLER:
        eventData = new BufferCursor(new buffer.Buffer(2));

        eventData.writeUInt8(event.controller);
        eventData.writeUInt8(event.value);
        break;
    case ChannelEvent.TYPE.PROGRAM_CHANGE:
        eventData = new BufferCursor(new buffer.Buffer(1));
        eventData.writeUInt8(event.program);
        break;
    case ChannelEvent.TYPE.CHANNEL_AFTERTOUCH:
        eventData = new BufferCursor(new buffer.Buffer(1));
        eventData.writeUInt8(event.pressure);
        break;
    case ChannelEvent.TYPE.PITCH_BEND:
        value = event.value + 8192;

        eventData = new BufferCursor(new buffer.Buffer(2));
        eventData.writeUInt8(value & 0x7F);
        eventData.writeUInt8(value >> 7);
        break;
    default:
        throw new error.MIDIEncoderError(
            event.type,
            'known ChannelEvent type'
        );
    }

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

    cursor.writeUInt8((event.type << 4) + event.channel);
    cursor.copy(eventData.buffer);

    return cursor.buffer;
}
function encodeChannelEvent(event) {
    var cursor, eventData, value;

    switch (event.type) {
    case ChannelEvent.TYPE.NOTE_OFF:
        eventData = new BufferCursor(new buffer.Buffer(2));

        eventData.writeUInt8(event.note);
        eventData.writeUInt8(event.velocity);
        break;
    case ChannelEvent.TYPE.NOTE_ON:
        eventData = new BufferCursor(new buffer.Buffer(2));

        eventData.writeUInt8(event.note);
        eventData.writeUInt8(event.velocity);
        break;
    case ChannelEvent.TYPE.NOTE_AFTERTOUCH:
        eventData = new BufferCursor(new buffer.Buffer(2));

        eventData.writeUInt8(event.note);
        eventData.writeUInt8(event.pressure);
        break;
    case ChannelEvent.TYPE.CONTROLLER:
        eventData = new BufferCursor(new buffer.Buffer(2));

        eventData.writeUInt8(event.controller);
        eventData.writeUInt8(event.value);
        break;
    case ChannelEvent.TYPE.PROGRAM_CHANGE:
        eventData = new BufferCursor(new buffer.Buffer(1));
        eventData.writeUInt8(event.program);
        break;
    case ChannelEvent.TYPE.CHANNEL_AFTERTOUCH:
        eventData = new BufferCursor(new buffer.Buffer(1));
        eventData.writeUInt8(event.pressure);
        break;
    case ChannelEvent.TYPE.PITCH_BEND:
        value = event.value + 8192;

        eventData = new BufferCursor(new buffer.Buffer(2));
        eventData.writeUInt8(value & 0x7F);
        eventData.writeUInt8(value >> 7);
        break;
    default:
        throw new error.MIDIEncoderError(
            event.type,
            'known ChannelEvent type'
        );
    }

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

    cursor.writeUInt8((event.type << 4) + event.channel);
    cursor.copy(eventData.buffer);

    return cursor.buffer;
}
function encodeChannelEvent ( event ) { var cursor , eventData , value ; switch ( event . type ) { case ChannelEvent . TYPE . NOTE_OFF : eventData = new BufferCursor ( new buffer . Buffer ( 2 ) ) ; eventData . writeUInt8 ( event . note ) ; eventData . writeUInt8 ( event . velocity ) ; break ; case ChannelEvent . TYPE . NOTE_ON : eventData = new BufferCursor ( new buffer . Buffer ( 2 ) ) ; eventData . writeUInt8 ( event . note ) ; eventData . writeUInt8 ( event . velocity ) ; break ; case ChannelEvent . TYPE . NOTE_AFTERTOUCH : eventData = new BufferCursor ( new buffer . Buffer ( 2 ) ) ; eventData . writeUInt8 ( event . note ) ; eventData . writeUInt8 ( event . pressure ) ; break ; case ChannelEvent . TYPE . CONTROLLER : eventData = new BufferCursor ( new buffer . Buffer ( 2 ) ) ; eventData . writeUInt8 ( event . controller ) ; eventData . writeUInt8 ( event . value ) ; break ; case ChannelEvent . TYPE . PROGRAM_CHANGE : eventData = new BufferCursor ( new buffer . Buffer ( 1 ) ) ; eventData . writeUInt8 ( event . program ) ; break ; case ChannelEvent . TYPE . CHANNEL_AFTERTOUCH : eventData = new BufferCursor ( new buffer . Buffer ( 1 ) ) ; eventData . writeUInt8 ( event . pressure ) ; break ; case ChannelEvent . TYPE . PITCH_BEND : value = event . value + 8192 ; eventData = new BufferCursor ( new buffer . Buffer ( 2 ) ) ; eventData . writeUInt8 ( value & 0x7F ) ; eventData . writeUInt8 ( value >> 7 ) ; break ; default : throw new error . MIDIEncoderError ( event . type , 'known ChannelEvent type' ) ; } cursor = new BufferCursor ( new buffer . Buffer ( 1 + eventData . length ) ) ; cursor . writeUInt8 ( ( event . type << 4 ) + event . channel ) ; cursor . copy ( eventData . buffer ) ; return cursor . buffer ; }
Encode a channel event

@private
@param {module:midijs/lib/file/event~ChannelEvent} event Channel event
@throws {module:midijs/lib/error~MIDIEncoderError}
Failed to encode the channel event
@return {Buffer} Encoded channel event
Encode a channel event