lib/file/parser/header.js
function parseHeader(cursor) {
    var chunk, fileType, trackCount, timeDivision;

    try {
        chunk = parseChunk('MThd', cursor);
    } catch (e) {
        if (e instanceof error.MIDIParserError) {
            throw new error.MIDINotMIDIError();
        }
    }
    fileType = chunk.readUInt16BE();
    trackCount = chunk.readUInt16BE();

    timeDivision = chunk.readUInt16BE();

    if ((timeDivision & 0x8000) === 0) {
        timeDivision = timeDivision & 0x7FFF;
    } else {
        throw new error.MIDINotSupportedError(
            'Expressing time in SMPTE format is not supported yet'
        );
    }

    return new Header(fileType, trackCount, timeDivision);
}
function parseHeader(cursor) {
    var chunk, fileType, trackCount, timeDivision;

    try {
        chunk = parseChunk('MThd', cursor);
    } catch (e) {
        if (e instanceof error.MIDIParserError) {
            throw new error.MIDINotMIDIError();
        }
    }
    fileType = chunk.readUInt16BE();
    trackCount = chunk.readUInt16BE();

    timeDivision = chunk.readUInt16BE();

    if ((timeDivision & 0x8000) === 0) {
        timeDivision = timeDivision & 0x7FFF;
    } else {
        throw new error.MIDINotSupportedError(
            'Expressing time in SMPTE format is not supported yet'
        );
    }

    return new Header(fileType, trackCount, timeDivision);
}
function parseHeader ( cursor ) { var chunk , fileType , trackCount , timeDivision ; try { chunk = parseChunk ( 'MThd' , cursor ) ; } catch ( e ) { if ( e instanceof error . MIDIParserError ) { throw new error . MIDINotMIDIError ( ) ; } } fileType = chunk . readUInt16BE ( ) ; trackCount = chunk . readUInt16BE ( ) ; timeDivision = chunk . readUInt16BE ( ) ; if ( ( timeDivision & 0x8000 ) === 0 ) { timeDivision = timeDivision & 0x7FFF ; } else { throw new error . MIDINotSupportedError ( 'Expressing time in SMPTE format is not supported yet' ) ; } return new Header ( fileType , trackCount , timeDivision ) ; }
Parse a MIDI header chunk

@param {module:buffercursor} cursor Buffer to parse
@throws {module:midijs/lib/error~MIDINotMIDIError}
If the file is not a MIDI file
@throws {module:midijs/lib/error~MIDIParserError}
If time is expressed in unsupported SMPTE format
@return {module:midijs/lib/file/header~Header} Parsed header
Parse a MIDI header chunk