import javax.sound.midi.*;
/**
- * Functional representation of a MIDI note, which adds functionality to the existent MidiEvent class.
+ * Functional representation of a MIDI note, which adds functionality to the existing MidiEvent class.
* Also provides a reference to the corresponding NoteOff event.
*
* @author Einar Pehrson
noteOffMsg = (ShortMessage)noteOffEvent.getMessage();
try {
noteOnMsg.setMessage(ShortMessage.NOTE_ON, channel, pitch, velocity);
- noteOffMsg.setMessage(ShortMessage.NOTE_OFF, channel, pitch, 0);
+ noteOffMsg.setMessage(ShortMessage.NOTE_OFF, channel, pitch, 64);
} catch (InvalidMidiDataException e) {System.out.println("Invalid data!");}
}
* @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
*/
public int compareTo(Object o) {
- return (int)(getTick() - ((MidiEvent)o).getTick());
+ int diff = (int)(getTick() - ((MidiEvent)o).getTick());
+ if (diff != 0) return diff;
+ return (noteOnMsg.getData1() - ((ShortMessage)((MidiEvent)o).getMessage()).getData1());
}
}