X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Moosique.java;h=531e4f511886dcc96c10c7ed9d614f9da83d6bf0;hb=fe67e0acf0d44c09dcfbbfd1a02a91f43d2cf60e;hp=bc821ba034bf49f69fc9ee4c33c7dcfd9d43b089;hpb=ffc69c8cc2cc9cdfe3841c77c1e680dee2225c63;p=moosique.git diff --git a/Moosique.java b/Moosique.java index bc821ba..531e4f5 100644 --- a/Moosique.java +++ b/Moosique.java @@ -23,6 +23,8 @@ public class Moosique { private static String filename, fileArg; private static long position; private static boolean makeGUI = true, isEdited; + private static Thread player; + public static final int RESOLUTION = 96, DEFAULT_TRACKS = 4; /** * Starts the application. @@ -139,7 +141,7 @@ public class Moosique { public static void clearSequence() { // Creates a new sequence and sends it to the sequencer. try { - seq = new Sequence(Sequence.PPQ, 96, 3); + seq = new Sequence(Sequence.PPQ, RESOLUTION, DEFAULT_TRACKS); sequencer.setSequence(seq); } catch (InvalidMidiDataException e) {} // Sends sequence to GUI. @@ -151,7 +153,7 @@ public class Moosique { */ public static void play() { sequencer.setTickPosition(position); - sequencer.start(); + resume(); } /** @@ -159,6 +161,7 @@ public class Moosique { */ public static void pause() { sequencer.stop(); + player.destroy(); } /** @@ -166,6 +169,18 @@ public class Moosique { */ public static void resume() { sequencer.start(); + + // Disables input to volatile components + // gui.disable(); + + // Creates the visualization thread and starts it. + player = new Thread () { + public void run() { + while(sequencer.isRunning()) gui.update(sequencer.getTickPosition()); + Moosique.stop(); + } + }; + player.start(); } /** @@ -174,6 +189,8 @@ public class Moosique { public static void stop() { sequencer.stop(); sequencer.setTickPosition(position); + player.interrupt(); + gui.update((long)0); } /**