String fileArg = null;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-n")) makeGUI = false;
- else if (args[i].equals("-m")) initSound = false;
else if (fileArg == null) fileArg = args[i];
}
}
}
-
// Disables input to volatile components
// gui.disable();
// Creates the visualisation thread and starts it.
- player = new Thread () {
- public void run() {
- while(sequencer.isRunning()) {
- // Updates the GUI with the current tick position.
- gui.update(sequencer.getTickPosition());
-
- // Puts the thread to sleep for as long as it takes
- // the sequencer to reach the next sixteenth.
- try {
- //sleep((long)((15000 / getTempo()) * (tickDiff / ticksPerSixteenth)));
- sleep (10);
- } catch (InterruptedException e) {
- Moosique.stop();
- }
- }
- Moosique.stop();
- }
- };
+ player = new PlayThread();
player.start();
}
*/
public static class MidiEventComparator implements Comparator {
public int compare(Object o1, Object o2) {
- return (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick());
+ int diff = (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick());
+ if (diff != 0 || !(((MidiEvent)o1).getMessage() instanceof ShortMessage) || !(((MidiEvent)o2).getMessage() instanceof ShortMessage)) return diff;
+ return (((ShortMessage)((MidiEvent)o1).getMessage()).getData1() - ((ShortMessage)((MidiEvent)o2).getMessage()).getData1());
+ }
+ }
+
+ /**
+ * The thread that updates the GUI during playback.
+ */
+ public static class PlayThread extends Thread {
+ public void run() {
+ // Updates the GUI with the current tick position.
+ gui.update(sequencer.getTickPosition());
+
+ // Puts the thread to sleep for as long as it takes
+ // the sequencer to reach the next sixteenth.
+ try {
+ //sleep((long)((15000 / getTempo()) * (tickDiff / ticksPerSixteenth)));
+ sleep (10);
+ } catch (InterruptedException e) {
+ Moosique.stop();
+ }
}
}
/**
* A listener for detecting the end of the sequence.
*/
- public static void class SongEndListener implements MetaEventListener {
+ public static class SongEndListener implements MetaEventListener {
public void meta(MetaMessage event) {
- if (event.getType() == 47 ) sequencer.stop(); // End of stream
+ if (event.getType() == 47)
+ // End of sequence
+ stop();
}
}
}