- // timeSignatures = ts.toArray(timeSignatures);
- // tempoChanges = tc.toArray(tempoChanges);
-
- // Wraps each NoteOn event with its NoteOff event in a MooNote
- ArrayList noteOns, noteOffs;
- for (int i = 0; i < tracks.length; i++) {
- // Searches the sequence for NoteOn and NoteOff events
- noteOns = new ArrayList(tracks[i].size() / 2);
- noteOffs = new ArrayList(tracks[i].size() / 2);
- for (int j = 0; j < tracks[i].size(); j++) {
- event = tracks[i].get(j);
- if (event.getMessage().getStatus() >= 144 &&
- event.getMessage().getStatus() < 160) noteOns.add(event);
- if (event.getMessage().getStatus() >= 128 &&
- event.getMessage().getStatus() < 144) noteOffs.add(event);
- }
- noteOns.trimToSize();
- noteOffs.trimToSize();
- if (noteOns.size() == 0) emptyTracks.add(tracks[i]);
-
- // Sorts the note lists by tick position.
- Comparator c = new Comparator() {
- public int compare(Object o1, Object o2) {
- return (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick());
- }
- };
- Collections.sort(noteOns, c);
- Collections.sort(noteOffs, c);
-
- // Replaces each NoteOn event it with a MooNote containing a reference to the NoteOff event.
- Iterator iOn = noteOns.iterator(), iOff;
- MidiEvent on, off = null, nextOff;
- ShortMessage onMsg, nextOffMsg;
- while(iOn.hasNext()) {
- on = (MidiEvent)iOn.next();
+ noteOns.trimToSize();
+ noteOffs.trimToSize();
+ if (noteOns.size() == 0) emptyTracks.add(track);
+
+ // Sorts the note lists by tick position.
+ Comparator c = new MidiEventComparator();
+ Collections.sort(noteOns, c);
+ Collections.sort(noteOffs, c);
+
+ // Replaces each NoteOn event it with a MooNote containing a reference to the NoteOff event.
+ Iterator iOn = noteOns.iterator(), iOff;
+ MidiEvent on, off = null, nextOff;
+ ShortMessage onMsg, nextOffMsg;
+ while(iOn.hasNext()) {
+ on = (MidiEvent)iOn.next();
+ if (!(on instanceof MooNote)) {