X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=Moosique.java;fp=Moosique.java;h=8da5285f4ed2e7ad2e731bb075143df4f2ca9a96;hp=90ad9a0aeea4eb9f0bbba829fcdf928298abce83;hb=e7289eb46e09ee6ed3bc5bb4a814f59902d885cb;hpb=f7097bc07b6688d1629e6894c1c42dc06485dc12 diff --git a/Moosique.java b/Moosique.java index 90ad9a0..8da5285 100644 --- a/Moosique.java +++ b/Moosique.java @@ -46,7 +46,6 @@ public class Moosique { 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]; } @@ -432,29 +431,11 @@ public class Moosique { } } - // 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(); } @@ -713,16 +694,39 @@ public class Moosique { */ 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(); } } }