dis.readInt();
}
// loop variables
int status, oldStatus = 0, eventLength = 0;
// Start gathering event data
Event event = null;
while (true) {
try {
// get variable length timestamp
deltaTime = MidiUtil.readVarLength(dis);
// mark stream so we can return if we need running status
dis.mark(2);
status = dis.readUnsignedByte();
// decide on running status
if (status < 0x80) { // set running status
status = oldStatus;
// return stream to before status read
dis.reset();
}
// create default event of correct type
if (status >= 0xFF) { // Meta Event
int type = dis.readUnsignedByte();
eventLength = MidiUtil.readVarLength(dis);
event = jm.midi.MidiUtil.createMetaEvent(type);
} else if (status >= 0xF0) { // System Exclusive --- NOT
// SUPPORTED
eventLength = MidiUtil.readVarLength(dis);
} else if (status >= 0x80) { // MIDI voice event
short selection = (short) (status / 0x10);
short midiChannel = (short) (status - (selection * 0x10));
VoiceEvt evt = (VoiceEvt) MidiUtil.createVoiceEvent(selection);
if (evt == null) {
throw new IOException("MIDI file read error: invalid voice event type!");
}
evt.setMidiChannel(midiChannel);
event = evt;
}
oldStatus = status;
} catch (EOFException ex) {
logger.warn("EOFException (" + ex.getMessage() + ") encountered in SMFTools");
} catch (Exception e) {
throw new IllegalStateException(e);
}
if (event != null) {
// read data into the new event and
// add the new event to the Track object
event.setTime(deltaTime);
event.read(dis);
track.addEvent(event);
// event.print();
if (event instanceof EndTrack)
break;
} else {