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

index 892e7658a93343943721748edf1af73a189d4303..ab055a9a1959046e361f0f16b219b6596023070d 100644 (file)
@@ -139,6 +139,7 @@ public class MooMenu extends JMenuBar implements ActionListener {
                if(command == "New") {
                        Moosique.clearSequence();
                } else if (command == "Open...") {
+                       // Shows a file chooser. If shown previously, starts in the current directory.
                        if (directory != null) {
                                chooser = new JFileChooser(directory);
                        } else {
@@ -146,13 +147,17 @@ public class MooMenu extends JMenuBar implements ActionListener {
                        }
                        chooser.addChoosableFileFilter(new MidiFileFilter());
                        int returnVal = chooser.showOpenDialog(this);
-                       if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
+
+                       // Stores the current directory and loads the selected file.
+                       File file = chooser.getSelectedFile();
+                       if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
                                directory = chooser.getSelectedFile().getParentFile();
                                Moosique.load(chooser.getSelectedFile().getAbsolutePath());
                        }
                } else if (command == "Save") {
                        Moosique.save();
                } else if (command == "Save as...") {
+                       // Shows a file chooser. If shown previously, starts in the current directory.
                        if (directory != null) {
                                chooser = new JFileChooser(directory);
                        } else {
@@ -160,9 +165,12 @@ public class MooMenu extends JMenuBar implements ActionListener {
                        }
                        chooser.addChoosableFileFilter(new MidiFileFilter());
                        int returnVal = chooser.showSaveDialog(this);
-                       if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
-                               directory = chooser.getSelectedFile().getParentFile();
-                               Moosique.saveAs(chooser.getSelectedFile().getAbsolutePath());
+
+                       // Stores the current directory and loads the selected file.
+                       File file = chooser.getSelectedFile();
+                       if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
+                               directory = file.getParentFile();
+                               Moosique.saveAs(file.getAbsolutePath());
                        }
                } else if (command == "Exit") {
                        Moosique.quit();
index 0449e86defed1375c30627c8e4db06dfdface6ea..3e66dab1c4aa10bf2d23674bd84b1940b1502f6b 100644 (file)
@@ -142,6 +142,6 @@ public class MooNote extends MidiEvent {
         * @return      the note off MidiEvent
         */
        public boolean hasNoteOffEvent() {
-               return noteOffEvent == null;
+               return noteOffEvent != null;
        }
 }
\ No newline at end of file
index a9ec10bd09b9a79d53e33b6689fb8c0d80cd93de..eb8ca43f304215539548383b8bd1466e36969405 100644 (file)
@@ -43,12 +43,9 @@ public class MooToolbar extends JToolBar {
                measure = createLabel("Msr", 10);
                beats = createLabel("Beat", 10);
                ticks = createLabel("Tick", 10);
-               measureValue = createLabel("1", 16);
-               measureValue.setBorder(BorderFactory.createLineBorder(Color.black));
-               beatsValue = createLabel("1", 16);
-               beatsValue.setBorder(BorderFactory.createLineBorder(Color.black));
-               ticksValue = createLabel("1", 16);
-               ticksValue.setBorder(BorderFactory.createLineBorder(Color.black));
+               measureValue = formatProgInd(createLabel("1", 16));
+               beatsValue = formatProgInd(createLabel("1", 16));
+               ticksValue = formatProgInd(createLabel("1", 16));
                JPanel spacenorth = new JPanel();
                spacenorth.setBackground(bgColor);
                JPanel spacesouth = new JPanel();
@@ -85,11 +82,8 @@ public class MooToolbar extends JToolBar {
                ticksValue.setText(Long.toString(ticks));
        }
 
-       /**
+       /*
         * Creates a button with the specified image and tooltip.
-        * @param imagelocation         the imagelacation of the the image displayed in the button
-        * @param tooltip               the tooltip associated with this button
-        * @return button               the button to be attached to the toolbar
         */
        private JButton createButton(String imagelocation, String tooltip) {
                JButton button = new JButton (new ImageIcon(imagelocation));
@@ -98,10 +92,8 @@ public class MooToolbar extends JToolBar {
                return button;
        }
        
-       /**
+       /*
         * Creates labels with the specified text and font size. 
-        * @param title         the titel displayed on the label
-        * @param fontsize      the fontzise of the text displayed on the label
         */
        private JLabel createLabel(String title, int fontSize){
                JLabel label = new JLabel(title,JLabel.CENTER);
@@ -109,6 +101,15 @@ public class MooToolbar extends JToolBar {
                return label;
        }
 
+       /*
+        * Formats the given label for the progress indicator.
+        */
+       private JLabel formatProgInd(JLabel label){
+               label.setBorder(BorderFactory.createLineBorder(Color.black));
+               label.setBackground(Color.white);
+               return label;
+       }
+
        class MooMouseAdapter extends MouseAdapter {
                public void mouseClicked(MouseEvent e) {
                        if (((JButton)e.getSource()).getToolTipText() == "Play") {
index 0b4618d7a65cce2a875467c19df7421e1d98f7ca..16d396f2e0a845053e83843e51707dceed42f862 100644 (file)
@@ -67,7 +67,6 @@ public class MooTrackView extends JPanel implements ActionListener {
                private int trackLength;
 
                public NoteArea(Track track) {
-                       System.out.println("Creating track view...");
                        setLayout(null);
                        trackLength = 140;
                        setPreferredSize(new Dimension(200,140*NOTE_HEIGHT));
@@ -89,7 +88,6 @@ public class MooTrackView extends JPanel implements ActionListener {
                                        y = insets.top + (int)(mn.getTick() / 24) * NOTE_HEIGHT;
                                        height = NOTE_HEIGHT;
                                        // height = (mn.getDuration() / 24) * NOTE_HEIGHT;
-                                       // System.out.println("Comp at: " + x + ", " + y + " is: " + findComponentAt(x + 10, y + 10));
                                        while(findComponentAt(x, y) instanceof MooNoteElement ||
                                              findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_WIDTH;
                                        elem.setBounds(x, y, NOTE_WIDTH, height);
index b21cf29058850c885a58e89f33216dcc63cae30a..3f088bd5930f801d27e5adfafb3efa4b1ed0f256 100644 (file)
@@ -30,10 +30,28 @@ public class MooView extends JScrollPane {
         * @param tracks        the tracks for which to add views
         */
        public void setTracks(Track[] tracks) {
-               trackPanel.removeAll();
-               trackPanel.setLayout(new GridLayout(1,tracks.length));
-               for (int i = 0; i < tracks.length; i++) {
-                       trackPanel.add(new MooTrackView(tracks[i]));
+               if (tracks.length == 1) {
+                       // If MIDI file is of type 0, creates a view for the track.
+                       trackPanel.add(new MooTrackView(tracks[0]));
+               } else {
+                       // Creates dialog for progress bar.
+                       JDialog progressDialog = new JDialog(Moosique.getGUI(), "Visualizing MIDI file...", false);
+                       JProgressBar progressBar = new JProgressBar(0, tracks.length);
+                       progressBar.setValue(0);
+                       progressBar.setStringPainted(true);
+                       progressDialog.getContentPane().add(progressBar);
+                       progressDialog.pack();
+                       progressDialog.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - progressDialog.getWidth()) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - progressDialog.getHeight()) / 2);
+                       progressDialog.setVisible(true);
+       
+                       // Starts filling the track panel with track views, while updating the progress bar.
+                       trackPanel.removeAll();
+                       trackPanel.setLayout(new GridLayout(1,tracks.length));
+                       for (int i = 1; i < tracks.length; i++) {
+                               trackPanel.add(new MooTrackView(tracks[i]));
+                               progressBar.setValue(i+1);
+                       }
+                       progressDialog.dispose();
                }
                trackPanel.validate();
        }
index 1c14a0fbe92ce0d558103c4bd011a85b5e6f4301..bc821ba034bf49f69fc9ee4c33c7dcfd9d43b089 100644 (file)
@@ -22,7 +22,7 @@ public class Moosique {
 
        private static String filename, fileArg;
        private static long position;
-       private static boolean makeGUI = true;
+       private static boolean makeGUI = true, isEdited;
 
        /** 
         * Starts the application.
@@ -177,21 +177,36 @@ public class Moosique {
        }
 
        /** 
-        * Rewinds the current sequence the given number of measures.
-        * @param measures      the number of measures to rewind
+        * Returns the current tick position of the sequencer.
+        * @return the tick position
         */
        public static long getPosition() {
                return position;
        }
 
        /** 
-        * Rewinds the current sequence the given number of measures.
-        * @param measures      the number of measures to rewind
+        * Sets the current tick position of the sequencer.
+        * @param ticks         the tick position
         */
        public static void setPosition(long ticks) {
                position = ticks;
        }
 
+       /** 
+        * Returns true if the current sequence has been edited.
+        * @return the tick position
+        */
+       public static boolean isEdited() {
+               return isEdited;
+       }
+
+       /** 
+        * Sets the current sequence as edited, which implies prompts when loading a new sequence.
+        */
+       public static void setEdited() {
+               isEdited = true;
+       }
+
        /** 
         * Rewinds the current sequence the given number of measures.
         * @param measures      the number of measures to rewind
@@ -222,13 +237,8 @@ public class Moosique {
                } catch (IOException e) {
                        return false;
                }
-
-               // Sends sequence to GUI and sequencer
-               if (gui != null) gui.setSequence(seq);
-               try {
-                       sequencer.setSequence(seq);
-               } catch (InvalidMidiDataException e) {}
-
+               isEdited = false;
+               
                // Searches the sequence for NoteOn events
                Track[] tracks = seq.getTracks();
                MidiEvent noteOn, noteOff = null, nextEvent;
@@ -269,6 +279,11 @@ public class Moosique {
                                }
                        }
                }
+               // Sends sequence to GUI and sequencer, then returns
+               if (gui != null) gui.setSequence(seq);
+               try {
+                       sequencer.setSequence(seq);
+               } catch (InvalidMidiDataException e) {}
                return true;
        }
 
index 8d026dc37a46270b0a13f906573f7a7a0b91e11b..f13bcb3561c3667a08dc62b869b488b2736f4f0a 100644 (file)
--- a/To Do.txt
+++ b/To Do.txt
@@ -8,36 +8,17 @@ Bj
 Rolle: MooTrackView(16)
 
 \f
-VIKTIGT! Implementera playfunktionens beteende. När play aktiveras ska följande loop köras:
-
-       while(sequencer.isRunning()) {
-               Moosique.getGUI().update();
-       }
-
-       i View:
-
-       public void update() {
-               // Calls on each track view to update itself.
-               for (int i = 0; i < trackViews.length; i++) {
-                       trackViews[i].update();
-               }
-       }
-
-       i GUI:
-       public void update(){
-               view.update();
-               // Calls on the toolbar to update the progress indicator.
-               toolbar.updateProgInd();
-       }
-
+VIKTIGT! Implementera playfunktionens beteende.
        När låten är slut återställes play-knappen.
-
        Göra detta som en tråd?!?
 
 \f
-x Fixa en progress indicator till filladdningen om den tänker ta så lång tid.
 x Scrollningen?!? Horisontell behövs på både MooView och MooTrackView, men vertikal bara på MooView. Hur göra?
 x Får Moosique vara statisk? Fult?
+x Spara konfiguration?
+       Arbetskatalog
+       Fem senast öppnade filerna
+       Valda MIDI-enheter
 
 \f
 MIDI Messages