try {
int magic = dis.readInt();
if( !(magic == MThd_MAGIC) ) {
// not MIDI
throw new InvalidMidiDataException("not a valid MIDI file");
}
// read header length
int bytesRemaining = dis.readInt() - 6;
type = dis.readShort();
numtracks = dis.readShort();
int timing = dis.readShort();
// decipher the timing code
if (timing > 0) {
// tempo based timing. value is ticks per beat.
divisionType = Sequence.PPQ;
resolution = timing;
} else {
// SMPTE based timing. first decipher the frame code.
int frameCode = (-1 * timing) >> 8;
switch(frameCode) {
case 24:
divisionType = Sequence.SMPTE_24;
break;
case 25:
divisionType = Sequence.SMPTE_25;
break;
case 29:
divisionType = Sequence.SMPTE_30DROP;
break;
case 30:
divisionType = Sequence.SMPTE_30;
break;
default:
throw new InvalidMidiDataException("Unknown frame code: " + frameCode);
}
// now determine the timing resolution in ticks per frame.
resolution = timing & 0xFF;
}
if (smfParser != null) {