lib/file/parser/event.js
function parseMetaEvent(delay, cursor) {
    var type, specs = {}, length, value, rates;

    rates = [24, 25, 30, 30];
    type = cursor.readUInt8();
    length = parseVarInt(cursor);

    switch (type) {
    case MetaEvent.TYPE.SEQUENCE_NUMBER:
        specs.number = cursor.readUInt16LE();
        break;
    case MetaEvent.TYPE.TEXT:
    case MetaEvent.TYPE.COPYRIGHT_NOTICE:
    case MetaEvent.TYPE.SEQUENCE_NAME:
    case MetaEvent.TYPE.INSTRUMENT_NAME:
    case MetaEvent.TYPE.LYRICS:
    case MetaEvent.TYPE.MARKER:
    case MetaEvent.TYPE.CUE_POINT:
    case MetaEvent.TYPE.PROGRAM_NAME:
    case MetaEvent.TYPE.DEVICE_NAME:
        specs.text = cursor.toString('utf8', length);
        break;
    case MetaEvent.TYPE.MIDI_CHANNEL:
        specs.channel = cursor.readUInt8();
        break;
    case MetaEvent.TYPE.MIDI_PORT:
        specs.port = cursor.readUInt8();
        break;
    case MetaEvent.TYPE.END_OF_TRACK:
        break;
    case MetaEvent.TYPE.SET_TEMPO:
        specs.tempo = 60000000 / ((cursor.readUInt8() << 16) +
                      (cursor.readUInt8() << 8) +
                       cursor.readUInt8());
        break;
    case MetaEvent.TYPE.SMPTE_OFFSET:
        value = cursor.readUInt8();

        specs.rate = rates[value >> 6];
        specs.hours = value & 0x3F;
        specs.minutes = cursor.readUInt8();
        specs.seconds = cursor.readUInt8();
        specs.frames = cursor.readUInt8();
        specs.subframes = cursor.readUInt8();
        break;
    case MetaEvent.TYPE.TIME_SIGNATURE:
        specs.numerator = cursor.readUInt8();
        specs.denominator = Math.pow(2, cursor.readUInt8());
        specs.metronome = cursor.readUInt8();
        specs.clockSignalsPerBeat = (192 / cursor.readUInt8());
        break;
    case MetaEvent.TYPE.KEY_SIGNATURE:
        specs.note = cursor.readInt8();
        specs.major = !cursor.readUInt8();
        break;
    case MetaEvent.TYPE.SEQUENCER_SPECIFIC:
        specs.data = cursor.slice(length).buffer;
        break;
    default:
        throw new error.MIDIParserError(
            type,
            'known MetaEvent type',
            cursor.tell()
        );
    }

    return new MetaEvent(type, specs, delay);
}
function parseMetaEvent(delay, cursor) {
    var type, specs = {}, length, value, rates;

    rates = [24, 25, 30, 30];
    type = cursor.readUInt8();
    length = parseVarInt(cursor);

    switch (type) {
    case MetaEvent.TYPE.SEQUENCE_NUMBER:
        specs.number = cursor.readUInt16LE();
        break;
    case MetaEvent.TYPE.TEXT:
    case MetaEvent.TYPE.COPYRIGHT_NOTICE:
    case MetaEvent.TYPE.SEQUENCE_NAME:
    case MetaEvent.TYPE.INSTRUMENT_NAME:
    case MetaEvent.TYPE.LYRICS:
    case MetaEvent.TYPE.MARKER:
    case MetaEvent.TYPE.CUE_POINT:
    case MetaEvent.TYPE.PROGRAM_NAME:
    case MetaEvent.TYPE.DEVICE_NAME:
        specs.text = cursor.toString('utf8', length);
        break;
    case MetaEvent.TYPE.MIDI_CHANNEL:
        specs.channel = cursor.readUInt8();
        break;
    case MetaEvent.TYPE.MIDI_PORT:
        specs.port = cursor.readUInt8();
        break;
    case MetaEvent.TYPE.END_OF_TRACK:
        break;
    case MetaEvent.TYPE.SET_TEMPO:
        specs.tempo = 60000000 / ((cursor.readUInt8() << 16) +
                      (cursor.readUInt8() << 8) +
                       cursor.readUInt8());
        break;
    case MetaEvent.TYPE.SMPTE_OFFSET:
        value = cursor.readUInt8();

        specs.rate = rates[value >> 6];
        specs.hours = value & 0x3F;
        specs.minutes = cursor.readUInt8();
        specs.seconds = cursor.readUInt8();
        specs.frames = cursor.readUInt8();
        specs.subframes = cursor.readUInt8();
        break;
    case MetaEvent.TYPE.TIME_SIGNATURE:
        specs.numerator = cursor.readUInt8();
        specs.denominator = Math.pow(2, cursor.readUInt8());
        specs.metronome = cursor.readUInt8();
        specs.clockSignalsPerBeat = (192 / cursor.readUInt8());
        break;
    case MetaEvent.TYPE.KEY_SIGNATURE:
        specs.note = cursor.readInt8();
        specs.major = !cursor.readUInt8();
        break;
    case MetaEvent.TYPE.SEQUENCER_SPECIFIC:
        specs.data = cursor.slice(length).buffer;
        break;
    default:
        throw new error.MIDIParserError(
            type,
            'known MetaEvent type',
            cursor.tell()
        );
    }

    return new MetaEvent(type, specs, delay);
}
function parseMetaEvent ( delay , cursor ) { var type , specs = { } , length , value , rates ; rates = [ 24 , 25 , 30 , 30 ] ; type = cursor . readUInt8 ( ) ; length = parseVarInt ( cursor ) ; switch ( type ) { case MetaEvent . TYPE . SEQUENCE_NUMBER : specs . number = cursor . readUInt16LE ( ) ; break ; case MetaEvent . TYPE . TEXT : case MetaEvent . TYPE . COPYRIGHT_NOTICE : case MetaEvent . TYPE . SEQUENCE_NAME : case MetaEvent . TYPE . INSTRUMENT_NAME : case MetaEvent . TYPE . LYRICS : case MetaEvent . TYPE . MARKER : case MetaEvent . TYPE . CUE_POINT : case MetaEvent . TYPE . PROGRAM_NAME : case MetaEvent . TYPE . DEVICE_NAME : specs . text = cursor . toString ( 'utf8' , length ) ; break ; case MetaEvent . TYPE . MIDI_CHANNEL : specs . channel = cursor . readUInt8 ( ) ; break ; case MetaEvent . TYPE . MIDI_PORT : specs . port = cursor . readUInt8 ( ) ; break ; case MetaEvent . TYPE . END_OF_TRACK : break ; case MetaEvent . TYPE . SET_TEMPO : specs . tempo = 60000000 / ( ( cursor . readUInt8 ( ) << 16 ) + ( cursor . readUInt8 ( ) << 8 ) + cursor . readUInt8 ( ) ) ; break ; case MetaEvent . TYPE . SMPTE_OFFSET : value = cursor . readUInt8 ( ) ; specs . rate = rates [ value >> 6 ] ; specs . hours = value & 0x3F ; specs . minutes = cursor . readUInt8 ( ) ; specs . seconds = cursor . readUInt8 ( ) ; specs . frames = cursor . readUInt8 ( ) ; specs . subframes = cursor . readUInt8 ( ) ; break ; case MetaEvent . TYPE . TIME_SIGNATURE : specs . numerator = cursor . readUInt8 ( ) ; specs . denominator = Math . pow ( 2 , cursor . readUInt8 ( ) ) ; specs . metronome = cursor . readUInt8 ( ) ; specs . clockSignalsPerBeat = ( 192 / cursor . readUInt8 ( ) ) ; break ; case MetaEvent . TYPE . KEY_SIGNATURE : specs . note = cursor . readInt8 ( ) ; specs . major = ! cursor . readUInt8 ( ) ; break ; case MetaEvent . TYPE . SEQUENCER_SPECIFIC : specs . data = cursor . slice ( length ) . buffer ; break ; default : throw new error . MIDIParserError ( type , 'known MetaEvent type' , cursor . tell ( ) ) ; } return new MetaEvent ( type , specs , delay ) ; }
Parse a meta MIDI event

@private
@param {number} delay Event delay in ticks
@param {module:buffercursor} cursor Buffer to parse
@throws {module:midijs/lib/error~MIDIParserError}
Failed to parse the meta event
@return {module:midijs/lib/file/event~MetaEvent} Parsed meta event
Parse a meta MIDI event