]> ruin.nu Git - moosique.git/commitdiff
no message
authorEinar Pehrson <einarp@itstud.chalmers.se>
Thu, 22 May 2003 12:39:32 +0000 (12:39 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Thu, 22 May 2003 12:39:32 +0000 (12:39 +0000)
MooMenu.java
MooNote.java
MooToolbar.java
MooTrackTitle.java
MooTrackView.java
Moosique.java
To Do.txt

index d30d181d20541aae81695a48401d2b2d9232bfa0..7c6be00a766fee802ffa044934d5bba82a61a177 100644 (file)
@@ -221,13 +221,10 @@ public class MooMenu extends JMenuBar implements ActionListener {
                
                } else if (command == "Set tempo...") {
                        MooDialog newDialog = new MooDialog(MooDialog.SET_TEMPO);
-               
                } else if (command == "Scale velocity...") {
                        MooDialog newDialog = new MooDialog(MooDialog.SCALE_VELOCITY);
-               
                } else if (command == "Transpose...") {
                        MooDialog newDialog = new MooDialog(MooDialog.TRANSPOSE);
-               
                } else if (command == "User manual") {
                        MooDialog manual = new MooDialog(MooDialog.MANUAL);
                } else if (command == "About") {
index 57cf86c8529c9fef5ce0e59726b6c944f83ebc04..34b0f2f25686e58404dea954116036ea482050d1 100644 (file)
@@ -175,6 +175,8 @@ public class MooNote extends MidiEvent implements Cloneable, Comparable {
         * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
         */
        public int compareTo(Object o) {
-               return (int)(getTick() - ((MidiEvent)o).getTick());
+               int diff = (int)(getTick() - ((MidiEvent)o).getTick());
+               if (diff != 0) return diff;
+               return (noteOnMsg.getData1() - ((ShortMessage)((MidiEvent)o).getMessage()).getData1());
        }
 }
index 1ea47ab08f5e3af9becb759089bc58889cdda5ef..5be8fdb77a29d0ddfd251bce0fd60433c9c79333 100644 (file)
@@ -93,12 +93,11 @@ public class MooToolbar extends JToolBar {
         * Resets the progress indicator.
         */
        public void resetProgInd() {
-                       measuresValue.setText("1");
-                       beatsValue.setText("1");
-                       ticksValue.setText("1");
-                       playpause.setIcon(playIcon);
-                       playpause.setToolTipText("Play");
-                       ticksPerBeat = Moosique.getSequence().getResolution();
+               measuresValue.setText("1");
+               beatsValue.setText("1");
+               ticksValue.setText("1");
+               updatePlayButton("Play", playIcon);
+               ticksPerBeat = Moosique.getSequence().getResolution();
        }
 
        /**
@@ -131,32 +130,37 @@ public class MooToolbar extends JToolBar {
                return label;
        }
 
+       /**
+        * Updates the play button with the given command and icon.
+        */
+       private void updatePlayButton(String command, Icon icon) {
+               playpause.setIcon(icon);
+               playpause.setActionCommand(command);
+               playpause.setToolTipText(command);
+       }
+
        class MAdapter extends MouseAdapter {
                public void mouseClicked(MouseEvent e) {
                        if (e.getSource() instanceof JButton) {
                                String command = ((JButton)e.getSource()).getActionCommand();
                                if (command == "Play") {
-                                       playpause.setIcon(pauseIcon);
-                                       playpause.setActionCommand("Pause");
-                                       playpause.setToolTipText("Pause");
+                                       updatePlayButton("Pause", pauseIcon);
                                        Moosique.play();
                                } else if (command == "Pause") {
-                                       playpause.setIcon(playIcon);
-                                       playpause.setActionCommand("Resume");
-                                       playpause.setToolTipText("Resume");
+                                       updatePlayButton("Resume", playIcon);
                                        Moosique.pause();
                                } else if (command == "Resume") {
-                                       playpause.setIcon(pauseIcon);
-                                       playpause.setActionCommand("Pause");
-                                       playpause.setToolTipText("Pause");
+                                       updatePlayButton("Pause", pauseIcon);
                                        Moosique.resume();
                                } else if (command == "Rewind") {
+                                       System.out.println("Rewound!");
                                        // Different implementation, perhaps?
+                                       updatePlayButton("Play", playIcon);
                                        Moosique.setEditPosition(0);
                                        Moosique.stop();
                                } else if (command == "Fast forward") {
-
                                } else if (command == "Stop") {
+                                       updatePlayButton("Play", playIcon);
                                        Moosique.stop();
                                }
                        } else if (e.getSource() instanceof JLabel) {
@@ -185,7 +189,7 @@ public class MooToolbar extends JToolBar {
                        }
                }
 
-               public void mousePressed(MouseEvent e) {
+/*             public void mousePressed(MouseEvent e) {
                        if (e.getSource() instanceof JButton) {
                                if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
                                        Moosique.rewind(beatsPerMeasure * ticksPerBeat);
@@ -196,5 +200,5 @@ public class MooToolbar extends JToolBar {
                }
 
                public void mouseReleased(MouseEvent e) {}
-       }
+*/     }
 }
index 8bec94bc2495c2a65d5f730b03b910f986cd999b..4079e4503ef0fe19814af56cecf95a49b3be1f53 100644 (file)
@@ -194,8 +194,8 @@ public class MooTrackTitle extends JPanel {
                                        mtv.disableKeyboardRecording();
                                        sequencer.stopRecording();
                                        sequencer.recordDisable(track);
-                                       Moosique.convertTrack(track, quantize);
-                                       mtv.placeNoteElements();
+                                       java.util.List newNotes = Moosique.convertTrack(track, quantize);
+                                       mtv.placeNewNotes(newNotes);
                                }
                        }
                }
index 2f96085e25f6a362ea22b4d34e28045ac7177736..126ee6306d22d7ae672502c35ce4cd30977da12d 100644 (file)
@@ -46,6 +46,8 @@ public class MooTrackView extends JPanel {
                this.track = track;
                this.title = title;
                insets = getInsets();
+               coords = new ArrayList(track.size() / 2);
+               selection = new TreeSet();
 
                // Configures panel
                setBackground(Color.white);
@@ -53,7 +55,23 @@ public class MooTrackView extends JPanel {
                setLayout(null);
                setPreferredSize(new Dimension(VIEW_WIDTH, 140 * NOTE_HEIGHT));
 
-               placeNoteElements();
+               // Creates temporary variables
+               MidiEvent note;
+               MooNoteElement elem;
+               extraHeight = Toolkit.getDefaultToolkit().getScreenSize().height - 150;
+
+               // Places note elements
+               for (int i = 0; i < track.size(); i++) {
+                       note = track.get(i);
+                       if (note instanceof MooNote) {
+                               // Adds the note element to the note area and moves it to the appropriate place.
+                               MooNote mn = (MooNote)note;
+                               elem = new MooNoteElement(this, mn);
+                               add(elem);
+                               layoutElement(elem, false);
+                       }
+               }
+               setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight));
 
                // Creates panel pop-up menu.
                popup = new JPopupMenu();
@@ -77,22 +95,17 @@ public class MooTrackView extends JPanel {
        }
 
        /**
-        * Creates note elements for all MooNotes in the track, and places them in the appropriate place.
+        * Creates note elements for all MooNotes in the given list, and places them in the appropriate place.
         */
-       public void placeNoteElements() {
-               // Empties the container
-               removeAll();
-               coords = new ArrayList(track.size() / 2);
-               selection = new TreeSet();
-
+       public void placeNewNotes(java.util.List notes) {
                // Creates temporary variables
                MidiEvent note;
                MooNoteElement elem;
                extraHeight = Toolkit.getDefaultToolkit().getScreenSize().height - 150;
 
                // Places note elements
-               for (int i = 0; i < track.size(); i++) {
-                       note = track.get(i);
+               for (int i = 0; i < notes.size(); i++) {
+                       note = (MidiEvent)notes.get(i);
                        if (note instanceof MooNote) {
                                // Adds the note element to the note area and moves it to the appropriate place.
                                MooNote mn = (MooNote)note;
@@ -100,8 +113,8 @@ public class MooTrackView extends JPanel {
                                add(elem);
                                layoutElement(elem, false);
                        }
-                       setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight));
                }
+               setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight));
        }       
 
        /**
index 90ad9a0aeea4eb9f0bbba829fcdf928298abce83..8da5285f4ed2e7ad2e731bb075143df4f2ca9a96 100644 (file)
@@ -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();
                }
        }
 }
index 137caaf852478a193b077fe75dc9f44f120f3031..47f606846a0d5f02820135cdb23bd9336accf2e4 100644 (file)
--- a/To Do.txt
+++ b/To Do.txt
@@ -11,6 +11,7 @@ Rolle Spara konfiguration
 
 \f
 BUGGAR
+x Play-knappen ändras inte till Pause.
 x Varför ritar den ut de tomma spåren i en ny fil? Rätt, men hur?
 x Varför hänger sig Play om man ändrar duration på en not?
 x Kopiera/flytta spår, möjligt?