]> ruin.nu Git - moosique.git/commitdiff
Fixed a play thread that almost works
authorEinar Pehrson <einarp@itstud.chalmers.se>
Tue, 13 May 2003 10:48:34 +0000 (10:48 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Tue, 13 May 2003 10:48:34 +0000 (10:48 +0000)
MooGUI.java
MooNoteElement.java
MooToolbar.java
MooTrackView.java
MooView.java
Moosique.java

index 17af222417e4ffb4b7dbdb3dfabdb6be7e130b74..065267eec3e8e04a48723d15311b4b2edef03d0c 100644 (file)
@@ -114,9 +114,9 @@ public class MooGUI extends JFrame {
         * Calls on the main view to update the track views,
         * and on the toolbar to update the progress indicator.
         */
-       public void update(){
-               view.update();
-               toolbar.updateProgInd();
+       public void update(long tickPosition){
+               view.update(tickPosition);
+               toolbar.updateProgInd(tickPosition);
        }
 
        class MooGUICloser extends WindowAdapter {
index dd31c86b800cc2b7cb1e8a1c077f12bee74f8ad2..3b08887000f07f515cbbcfab170972ef6fb0cfe3 100644 (file)
@@ -20,7 +20,7 @@ public class MooNoteElement extends JPanel {
         * @param mn    the note that will be graphically represented
         * @param rows  the number of rows that the note will occupy
         */
-       public MooNoteElement (MooNote mn, int rows) {
+       public MooNoteElement (MooNote mn) {
                note = mn;
                columns = mn.getDuration() / 24;
        }
index eb8ca43f304215539548383b8bd1466e36969405..54b90db40f83a871e82fc4b3a666436fa2900ee9 100644 (file)
@@ -69,14 +69,14 @@ public class MooToolbar extends JToolBar {
 
        /**
         * Updates the progress indicator.
+        * @param tickPosition  the tick position to visualize
         */
-       public void updateProgInd() {
-               long pos = Moosique.getSequencer().getTickPosition();
+       public void updateProgInd(long tickPosition) {
                int ticksPerBeat = Moosique.getSequence().getResolution();
                int beatsPerMeasure = 4;
-               long measures = pos / (beatsPerMeasure * ticksPerBeat);
-               long beats = (pos - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat;
-               long ticks = pos - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat;
+               long measures = tickPosition / (beatsPerMeasure * ticksPerBeat);
+               long beats = (tickPosition - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat;
+               long ticks = tickPosition - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat;
                measureValue.setText(Long.toString(measures));
                beatsValue.setText(Long.toString(beats));
                ticksValue.setText(Long.toString(ticks));
@@ -113,27 +113,21 @@ public class MooToolbar extends JToolBar {
        class MooMouseAdapter extends MouseAdapter {
                public void mouseClicked(MouseEvent e) {
                        if (((JButton)e.getSource()).getToolTipText() == "Play") {
-                                       Moosique.play();
                                        playpause.setIcon(pauseIcon);
                                        playpause.setToolTipText("Pause");
-                                       while(Moosique.getSequencer().isRunning()) {
-                                               Moosique.getGUI().update();
-                                       }
+                                       Moosique.play();
                        } else if (((JButton)e.getSource()).getToolTipText() == "Pause") {
-                                       Moosique.pause();
                                        playpause.setIcon(playIcon);
                                        playpause.setToolTipText("Resume");
+                                       Moosique.pause();
                        } else if (((JButton)e.getSource()).getToolTipText() == "Resume") {
-                                       Moosique.resume();
                                        playpause.setIcon(pauseIcon);
                                        playpause.setToolTipText("Pause");
-                                       while(Moosique.getSequencer().isRunning()) {
-                                               Moosique.getGUI().update();
-                                       }
+                                       Moosique.resume();
                        } else if (((JButton)e.getSource()).getToolTipText() == "Stop") {
-                               Moosique.stop();
                                playpause.setIcon(playIcon);
                                playpause.setToolTipText("Play");
+                               Moosique.stop();
                        }
                }
 
index 81384425b7289063262d4968546aab0033cdfb6b..c7850fe65b2eb4aeaed77d5d2f4b96028086641a 100644 (file)
@@ -59,7 +59,7 @@ public class MooTrackView extends JPanel implements ActionListener {
        /** 
         * Updates the track view.
         */
-       public void update() {
+       public void update(long tickPosition) {
                repaint();
        }
 
index 8223eca49e62ff4d28e3c5f3398778ba14fa08d8..a9679ffce84af3205f2f0634b0871640198f125a 100644 (file)
@@ -74,10 +74,10 @@ public class MooView extends JPanel {
        /** 
         * Calls on each track view to update itself.
         */
-       public void update() {
+       public void update(long tickPosition) {
                Component[] comps = getComponents();
                for (int i = 0; i < comps.length; i++) {
-                       if(comps[i] instanceof MooTrackView) ((MooTrackView)comps[i]).update();
+                       if(comps[i] instanceof MooTrackView) ((MooTrackView)comps[i]).update(tickPosition);
                }
        }
 
index bc821ba034bf49f69fc9ee4c33c7dcfd9d43b089..b4c4259e0b02a6be66ef48f63c821f7229f65c4d 100644 (file)
@@ -23,6 +23,7 @@ public class Moosique {
        private static String filename, fileArg;
        private static long position;
        private static boolean makeGUI = true, isEdited;
+       private static Thread player;
 
        /** 
         * Starts the application.
@@ -151,7 +152,8 @@ 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,17 @@ 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() {
+                               gui.update(sequencer.getTickPosition());
+                       }
+               };
+               player.start();
        }
 
        /** 
@@ -174,6 +188,8 @@ public class Moosique {
        public static void stop() {
                sequencer.stop();
                sequencer.setTickPosition(position);
+               player.destroy();
+               gui.update((long)0);
        }
 
        /**