]> ruin.nu Git - moosique.git/commitdiff
Fixed some bugs
authorEinar Pehrson <einarp@itstud.chalmers.se>
Sun, 11 May 2003 23:41:47 +0000 (23:41 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Sun, 11 May 2003 23:41:47 +0000 (23:41 +0000)
MooGUI.java
MooMenu.java
MooNoteElement.java
MooToolbar.java
MooTrackView.java
MooView.java
MooViewCounter.java
Moosique.java
To Do.txt

index 146ca6daa8483350c78cbc2fcea6557d67a05121..32285ac5191375271ec0ba593f2dddfb8cb45ac6 100644 (file)
@@ -39,7 +39,7 @@ public class MooGUI extends JFrame {
                pane.add(toolbar, BorderLayout.NORTH);
 
                // Adds main view.
-               view = new MooView(seq);
+               view = new MooView(seq.getTracks());
                pane.add(view, BorderLayout.CENTER);
 
                // Adds status bar.
@@ -55,18 +55,22 @@ public class MooGUI extends JFrame {
                statusBar.setBackground(bgColor);
                view.setBackground(bgColor);
 
+               // Sets up global key listener
                ActionMap am = getRootPane().getActionMap();
 
                Action playAction = new AbstractAction() {
                        public void actionPerformed(ActionEvent ae) {
-                               Moosique.resumepause();
+                               if (!Moosique.getSequencer().isRunning()) {
+                                       Moosique.play();
+                               } else {
+                                       Moosique.stop();
+                               }
                        }};
-               am.put("play", playAction);
+               am.put("Play", playAction);
 
                InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
                KeyStroke playKey = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
-               im.put(playKey, "play");
-
+               im.put(playKey, "Play");
 
                // Configures window.
                addWindowListener(new MooGUICloser());
@@ -94,7 +98,7 @@ public class MooGUI extends JFrame {
         */
        public void setSequence(Sequence sequence) {
                seq = sequence;
-               view.setSequence(seq);
+               view.setTracks(seq.getTracks());
        }
 
        /** 
@@ -106,12 +110,12 @@ public class MooGUI extends JFrame {
        }
 
        /**
-        * Update the view.
+        * Calls on the main view to update the track views,
+        * and on the toolbar to update the progress indicator.
         */
        public void update(){
                view.update();
-               // Calls on the toolbar to update the progress indicator.
-               //toolbar.updateProgInd();
+               toolbar.updateProgInd();
        }
 
        class MooGUICloser extends WindowAdapter {
index 2403a373551f07828d5bc0fd2c1d76fc5552e567..141fd93f87320054204ea2f486efdebab9542ed0 100644 (file)
@@ -141,7 +141,6 @@ public class MooMenu extends JMenuBar implements ActionListener {
                        if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
                                Moosique.saveAs(chooser.getSelectedFile().getAbsolutePath());
                        }
-               
                } else if (command == "Exit") {
                        Moosique.quit();
                } else if (command == "Copy") {
@@ -157,21 +156,13 @@ public class MooMenu extends JMenuBar implements ActionListener {
                } else if (command == "Preferences...") {
 
                } else if (command == "Play") {
-                       if (Moosique.getSequencer().isRunning()) {
-                               Moosique.pause();
-                       } else {
-                               Moosique.play();
-                       }
+                       if (!Moosique.getSequencer().isRunning()) Moosique.play();
                } else if (command == "Pause") {
-                       if (Moosique.getSequencer().isRunning()) {
-                               Moosique.resume();
-                       } else {
-                               Moosique.pause();
-                       }
+                       if (Moosique.getSequencer().isRunning()) Moosique.pause();
                } else if (command == "Stop") {
                        Moosique.stop();
                } else if (command == "Jump...") {
-               
+                       
                } else if (command == "Add track...") {
                        Moosique.getSequence().createTrack();
                } else if (command == "Delete track...") {
index c39d2b58804af037d5f355bd5744e451d421661e..e854a44fd030a0f211635a8b5b715623097c9bff 100644 (file)
@@ -9,7 +9,7 @@ import java.awt.event.*;
  * @version 1
  */
  
-public class MooNoteElement extends JPanel{
+public class MooNoteElement extends JPanel {
 
        private MooNote note;
        private boolean selected;
index a2f55712fac336c7e0df85fbc0ae85e190b9f55d..c1244f575e81b717e8db764427727b2d0362fd06 100644 (file)
@@ -11,7 +11,7 @@ import javax.sound.midi.*;
 public class MooToolbar extends JToolBar {
 
        private JButton rewind, playpause, stop, fastforward;
-       private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
+       private JLabel measure, beats, ticks, measureValue, beatsValue, ticksValue;
        private ImageIcon playIcon, pauseIcon;
        private MooMouseAdapter mouseAdapter;
        public static final Color bgColor = new Color(192, 224, 255);
@@ -21,50 +21,64 @@ public class MooToolbar extends JToolBar {
         */
        
        public MooToolbar() {
+               // setAlignmentX(LEFT_ALIGNMENT);
                setFloatable(false);
                mouseAdapter = new MooMouseAdapter();
 
                // Creates playback buttons
                rewind = createButton("images/rewind.gif", "Rewind");
-               add(rewind);
                playpause = createButton("images/play.gif", "Play");
-               add(playpause);
+               stop = createButton("images/stop.gif", "Stop");
+               fastforward = createButton("images/forward.gif", "Fast forward");
                playIcon = new ImageIcon("images/play.gif");
                pauseIcon = new ImageIcon("images/pause.gif");
-               stop = createButton("images/stop.gif", "Stop");
+
+               // Adds playback buttons
+               add(rewind);
+               add(playpause);
                add(stop);
-               fastforward = createButton("images/forward.gif", "Fast forward");
                add(fastforward);
                
                // Creates progress indicator
+               measure = createLabel("Msr", 10);
+               beats = createLabel("Beat", 10);
+               ticks = createLabel("Tick", 10);
+               measureValue = createLabel("1", 16);
+               beatsValue = createLabel("1", 16);
+               ticksValue = createLabel("1", 16);
+               JPanel spacenorth = new JPanel();
+               spacenorth.setBackground(bgColor);
+               JPanel spacesouth = new JPanel();
+               spacesouth.setBackground(bgColor);
+
+               // Creates progress indicator panel and adds components
                JPanel progIndPanel = new JPanel();
                progIndPanel.setMaximumSize(new Dimension(120,27));
                progIndPanel.setLayout(new GridLayout(2,4));
-               measure = createLabel("Mrs",10);
-               beats = createLabel("Beat",10);
-               ticks = createLabel("Tick",10);
-               measurevalue = createLabel("1", 16);
-               beatsvalue = createLabel("1",16);
-               ticksvalue = createLabel("1",16);
-               
-               JPanel spacenorth = new JPanel();
-               spacenorth.setBackground(bgColor);
                progIndPanel.add(spacenorth);
-               
                progIndPanel.add(measure);
                progIndPanel.add(beats);
                progIndPanel.add(ticks);
-               
-               JPanel spacesouth = new JPanel();
-               spacesouth.setBackground(bgColor);
                progIndPanel.add(spacesouth);
-               
-               progIndPanel.add(measurevalue);
-               progIndPanel.add(beatsvalue);
-               progIndPanel.add(ticksvalue);
+               progIndPanel.add(measureValue);
+               progIndPanel.add(beatsValue);
+               progIndPanel.add(ticksValue);
                add(progIndPanel);
+
        }
-               
+
+       /**
+        * Updates the progress indicator.
+        */
+       public void updateProgInd() {
+               int pos = Moosique.getSequencer().getTickPosition();
+               int ticksPerBeat = Moosique.getSequencer().getResolution();
+               int beatsPerMeasure = 4;
+               measureValue.setText(pos / (beatsPerMeasure * ticksPerBeat));
+               beatsValue.setText((pos - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat);
+               ticksValue.setText(pos - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat);
+       }
+
        /**
         * Creates a button with the specified image and tooltip.
         * @param imagelocation         the imagelacation of the the image displayed in the button
@@ -84,17 +98,12 @@ public class MooToolbar extends JToolBar {
         * @param fontsize      the fontzise of the text displayed on the label
         */
        private JLabel createLabel(String title, int fontSize){
-               JLabel value = new JLabel(title,JLabel.CENTER);
-               value.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
-               value.setBorder(BorderFactory.createLineBorder(Color.black));
-               return value;
+               JLabel label = new JLabel(title,JLabel.CENTER);
+               label.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
+               label.setBorder(BorderFactory.createLineBorder(Color.black));
+               return label;
        }
-       
-       // int pos = Moosique.getSequencer().getTickPosition();
-       // int measures = pos / (4 * Moosique.getSequence.get)
-       // int beats = (pos - measures * 4 * 96) / 96;
-       // int ticks = (pos - measures*4*96 - beats*96);
-       
+
        class MooMouseAdapter extends MouseAdapter {
                public void mouseClicked(MouseEvent e) {
                        if (((JButton)e.getSource()).getToolTipText() == "Play") {
@@ -126,4 +135,4 @@ public class MooToolbar extends JToolBar {
 
                public void mouseReleased(MouseEvent e) {}
        }
-}
+}
\ No newline at end of file
index bf6e31f7554872d79baaed367476889b34e51482..4e4f0027161da12374c71d308f5124438d1bcd3b 100644 (file)
@@ -29,7 +29,7 @@ public class MooTrackView extends JPanel implements ActionListener {
                title.setBorder(BorderFactory.createLineBorder(Color.black));
                add(title, BorderLayout.NORTH);
 
-               notes = new NoteArea(); 
+               notes = new NoteArea(track);    
                notes.setBackground(Color.white);
                notes.setBorder(BorderFactory.createLineBorder(Color.black));
 
@@ -52,16 +52,23 @@ public class MooTrackView extends JPanel implements ActionListener {
        }
 
        class NoteArea extends JPanel {
-               public void RectanglePanel() {
-                       setPreferredSize(new Dimension(20, 20));
+
+               public NoteArea(Track track) {
+                       MidiEvent note;
+                       for (int i = 0; i < track.size(); i++) {
+                               note = track.get(i);
+                               if (note instanceof MooNote) {
+                                       add(new MooNoteElement((MooNote)note));
+                               }
+                       }
+                       validate();
                }
 
                public void paintComponent(Graphics g) {
                        super.paintComponent(g);
                        Graphics2D g2 = (Graphics2D)g;
                        for (int c = 0; c < 1000; c += 20) {
-                               int r=0;
-                               for (r = 0; r < 200; r += 20) {
+                               for (int r = 0; r < 200; r += 20) {
                                        box = new Rectangle(r, c, 20, 20);
                                        g2.setColor(Color.gray);
                                        g2.draw(box);
@@ -85,4 +92,4 @@ public class MooTrackView extends JPanel implements ActionListener {
                        }
                }
        }
-}
+}
\ No newline at end of file
index 4f36de3ce0a5d06e20b894cdfbac6d6035579a4f..76391f9d20caf3d170c3a90fc29509e7eca5ee92 100644 (file)
@@ -11,61 +11,58 @@ import java.awt.event.*;
 
 public class MooView extends JScrollPane {
 
-       private Track[] tracks;
-       private MooTrackView[] trackViews;
        private JPanel trackPanel;
 
        /** 
         * Creates the main view
         */
-       public MooView(Sequence seq) {
+       public MooView(Track[] tracks) {
                super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED);
-               tracks = seq.getTracks();
-
-
                trackPanel = new JPanel(new GridLayout(1,3), true);
-               createTrackViews();
+               setTracks(tracks);
                setViewportView(trackPanel);
        }
 
        /** 
         * Fills the track panel with track views for all tracks in the current sequence.
+        * @param tracks        the tracks for which to add views
         */
-       private void createTrackViews() {
+       public void setTracks(Track[] tracks) {
                trackPanel.removeAll();
                ((GridLayout)trackPanel.getLayout()).setColumns(tracks.length);
-               trackViews = new MooTrackView[tracks.length];
                for (int i = 0; i < tracks.length; i++) {
-                       trackViews[i] = new MooTrackView(tracks[i]);
                        trackPanel.add(new MooTrackView(tracks[i]));
                }
                trackPanel.validate();
+               validate();
        }
 
-       public void setSequence(Sequence seq) {
-               tracks = seq.getTracks();
-               createTrackViews();
-       }
-
+       /** 
+        * Calls on each track view to update itself.
+        */
        public void update() {
-               // Calls on each track view to update itself.
-               for (int i = 0; i < trackViews.length; i++) {
-                       //trackViews[i].update();
+               Component[] comps = c.getComponents();
+               for (int i = 0; i < comps.length; i++) {
+                       ((MooTrackView)comps[i]).update();
                }
        }
+
        /** 
         * Creates a view for the given track and adds it to the main view.
         * @param track         the track for which to add a view
+        * @param index         the index at which to insert the view
         */
-       public void addTrackView(Track track) {
-               
+       public void addTrackView(Track track, int index) {
+               add(new MooTrackView(track), index);
+               validate();
        }
 
        /** 
         * Removes the view for the given track.
-        * @param track         the track for which to remove the view
+        * @param index         the index of the track for which to remove the view
         */
-       public void removeTrackView(Track track) {
-               
+       public void removeTrackView(int index) {
+               remove(index);
+               validate();
        }
-}
+}
\ No newline at end of file
index aea79444a2e36e44b5255e1598d59f9a4d192b5e..ce69af266226c03a02a3b9f6cc978b6bb06bd1ff 100644 (file)
@@ -1,4 +1,5 @@
 import javax.swing.*;
+import java.awt.*;
 
 /**
  * 
@@ -7,12 +8,25 @@ import javax.swing.*;
  * @version 1
  */
  
-public class MooViewCounter {
+public class MooViewCounter extends JPanel {
 
        /** 
         * Creates 
         */
        public MooViewCounter () {
+       
+       }
+
+       public void paintComponent(Graphics g) {
+               super.paintComponent(g);
 
+               if (!(g instanceof Graphics2D)) return;
+               Graphics2D g2 = (Graphics2D)g;
+               
+               for (int i = 0; i < 10; i++) {
+                       for (int j = 0; j < 10; j++) {
+                               // g2.drawLine(0,i*20, 
+                       }
+               }
        }
 }
index 5ee3bccea394dd8819cba008c3627d8e7139972e..5d6ed9716b569d472141910edfb0e41358c21d74 100644 (file)
@@ -1,6 +1,6 @@
 import javax.sound.midi.*;
-import javax.swing.*;
 import java.io.*;
+import javax.swing.*;
 
 /**
  * Moosique - The MIDI Tracker
@@ -22,7 +22,6 @@ public class Moosique {
        private static String filename, fileArg;
        private static long position;
        private static boolean makeGUI = true;
-       private static boolean playing = false;
 
        /** 
         * Starts the application.
@@ -68,9 +67,12 @@ public class Moosique {
                        clearSequence();
                }
 
-               // If n-flag is set, plays song and then exits. Otherwise builds GUI.
+               // Builds GUI, unless n-flag is set.
                if (makeGUI) {
                        System.out.print("Building GUI...");
+                       try {
+                               UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+                       } catch (Exception e) {}
                        gui = new MooGUI(seq);
                        System.out.println("Done");
                } else {
@@ -147,7 +149,6 @@ public class Moosique {
         * Starts playback of the current sequence.
         */
        public static void play() {
-               playing = true;
                sequencer.setTickPosition(position);
                sequencer.start();
        }
@@ -156,7 +157,6 @@ public class Moosique {
         * Pauses playback of the current sequence.
         */
        public static void pause() {
-               playing = false;
                sequencer.stop();
        }
 
@@ -164,7 +164,6 @@ public class Moosique {
         * Resumes playback of the current sequence.
         */
        public static void resume() {
-               playing = true;
                sequencer.start();
        }
 
@@ -172,22 +171,10 @@ public class Moosique {
         * Stops playback of the current sequence.
         */
        public static void stop() {
-               playing = false;
                sequencer.stop();
                sequencer.setTickPosition(position);
        }
 
-       /**
-        * Pauses if playing and resumes if stopped.
-        */
-       public static void resumepause()
-       {
-               if (playing)
-                       pause();
-               else
-                       resume();
-       }
-
        /** 
         * Rewinds the current sequence the given number of measures.
         * @param measures      the number of measures to rewind
@@ -232,7 +219,6 @@ public class Moosique {
                } catch (InvalidMidiDataException e) {
                        return false;
                } catch (IOException e) {
-                       JOptionPane.showMessageDialog(null, "Error 404", "File Not Found", JOptionPane.ERROR_MESSAGE); 
                        return false;
                }
 
@@ -304,4 +290,4 @@ public class Moosique {
                if (synthesizer.isOpen()) synthesizer.close();
                System.exit(0);
        }
-}
+}
\ No newline at end of file
index b5f64bb093ef06fe24fcb6acc02d456b806c5040..8d026dc37a46270b0a13f906573f7a7a0b91e11b 100644 (file)
--- a/To Do.txt
+++ b/To Do.txt
@@ -56,8 +56,7 @@ Track
 \f
 MooMenu
 
-       * Inställningar
-               - MIDI-enhet     Öppna en dialogruta med innehållet i getMidiDeviceInfo() och låt användaren välja.
+x Kom ihåg sökväg vid Open
 
        Musikrelaterade menyer i Midisoft Recording Session:
        
@@ -147,6 +146,20 @@ Moosique
 
        * getPosition och setPosition - kvar?
 
+\f
+Skräp
+
+               // Prints the number of notes in each track
+               int count;
+               Track[] tracks = seq.getTracks();
+               for (int k = 0; k < tracks.length; k++) {
+                       count = 0;
+                       for (int j = 0; j < tracks[k].size(); j++) {
+                               if (tracks[k].get(j) instanceof MooNote) count++;
+                       }
+                       System.out.println("Track " + k + ": " + count + " notes.");
+               }
+
 \f
 MooNoteProp
        * textfält som gör att man bara kan skriva in siffror?