// -----------------------------
// Write each event in the track
// -----------------------------
for(int i=0; i<size; i++) {
MidiEvent event = track.get(i);
int status;
int eventtype;
int metatype;
int data1, data2;
int length;
byte data[] = null;
ShortMessage shortMessage = null;
MetaMessage metaMessage = null;
SysexMessage sysexMessage = null;
// get the tick
// $$jb: this gets easier if we change all system-wide time to delta ticks
eventTick = event.getTick();
deltaTick = event.getTick() - currentTick;
currentTick = event.getTick();
// get the status byte
status = event.getMessage().getStatus();
eventtype = getType( status );
switch( eventtype ) {
case ONE_BYTE:
shortMessage = (ShortMessage) event.getMessage();
data1 = shortMessage.getData1();
bytesWritten += writeVarInt( deltaTick );
if(status!=runningStatus) {
runningStatus=status;
tddos.writeByte(status); bytesWritten += 1;
}
tddos.writeByte(data1); bytesWritten += 1;
break;
case TWO_BYTE:
shortMessage = (ShortMessage) event.getMessage();
data1 = shortMessage.getData1();
data2 = shortMessage.getData2();
bytesWritten += writeVarInt( deltaTick );
if(status!=runningStatus) {
runningStatus=status;
tddos.writeByte(status); bytesWritten += 1;
}
tddos.writeByte(data1); bytesWritten += 1;
tddos.writeByte(data2); bytesWritten += 1;
break;
case SYSEX:
sysexMessage = (SysexMessage) event.getMessage();
length = sysexMessage.getLength();
data = sysexMessage.getMessage();
bytesWritten += writeVarInt( deltaTick );
// $$jb: 04.08.99: always write status for sysex
runningStatus=status;
tddos.writeByte( data[0] ); bytesWritten += 1;
// $$jb: 10.18.99: we don't maintain length in
// the message data for SysEx (it is not transmitted
// over the line), so write the calculated length
// minus the status byte
bytesWritten += writeVarInt( (data.length-1) );
// $$jb: 10.18.99: now write the rest of the
// message
tddos.write(data, 1, (data.length-1));
bytesWritten += (data.length-1);
break;
case META:
metaMessage = (MetaMessage) event.getMessage();
length = metaMessage.getLength();
data = metaMessage.getMessage();
bytesWritten += writeVarInt( deltaTick );
// $$jb: 10.18.99: getMessage() returns the