]> ruin.nu Git - moosique.git/commitdiff
*** empty log message ***
authorEinar Pehrson <einarp@itstud.chalmers.se>
Tue, 13 May 2003 15:17:42 +0000 (15:17 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Tue, 13 May 2003 15:17:42 +0000 (15:17 +0000)
MooNoteElement.java
MooToolbar.java
MooTrackView.java
MooView.java
Moosique.java

index 3b08887000f07f515cbbcfab170972ef6fb0cfe3..c502b4d568cd47e6269e0fb79e0cd3ff1f753ec9 100644 (file)
@@ -23,6 +23,7 @@ public class MooNoteElement extends JPanel {
        public MooNoteElement (MooNote mn) {
                note = mn;
                columns = mn.getDuration() / 24;
+               setBorder(BorderFactory.createLineBorder(Color.black));
        }
 
        /** 
index 54b90db40f83a871e82fc4b3a666436fa2900ee9..92bf3457e083b11f79269e02e91590b02fc21dd3 100644 (file)
@@ -12,6 +12,7 @@ public class MooToolbar extends JToolBar {
 
        private JButton rewind, playpause, stop, fastforward;
        private JLabel measure, beats, ticks, measureValue, beatsValue, ticksValue;
+       private JPanel progIndPanel;
        private ImageIcon playIcon, pauseIcon;
        private MooMouseAdapter mouseAdapter;
        public static final Color bgColor = new Color(192, 224, 255);
@@ -52,7 +53,7 @@ public class MooToolbar extends JToolBar {
                spacesouth.setBackground(bgColor);
 
                // Creates progress indicator panel and adds components
-               JPanel progIndPanel = new JPanel();
+               progIndPanel = new JPanel();
                progIndPanel.setMaximumSize(new Dimension(120,27));
                progIndPanel.setLayout(new GridLayout(2,4));
                progIndPanel.add(spacenorth);
@@ -77,9 +78,9 @@ public class MooToolbar extends JToolBar {
                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));
+               measureValue.setText(Long.toString(1 + measures));
+               beatsValue.setText(Long.toString(1 + beats));
+               ticksValue.setText(Long.toString(1 + ticks));
        }
 
        /*
index cba92728796318289308ea79601c293a6989fdf0..d33f3c1f1d3191418a390e8d882fafe31cf32405 100644 (file)
@@ -21,14 +21,14 @@ public class MooTrackView extends JPanel implements ActionListener {
        private JPopupMenu notePopup;
        private JMenuItem menuItem;
        protected static int viewLength = 0;
-       
+       public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200;
 
        public MooTrackView (Track track) {
                super(true);
                this.track = track;
                //setPreferredSize(new Dimension(200, 9000));
                setLayout(new BorderLayout());
-               this.setBorder(BorderFactory.createLineBorder(Color.black));
+               // setBorder(BorderFactory.createLineBorder(Color.black));
 
                //title = new MooTrackTitle(track);
                //title.setBorder(BorderFactory.createLineBorder(Color.black));
@@ -68,17 +68,14 @@ public class MooTrackView extends JPanel implements ActionListener {
        }
 
        class NoteArea extends JPanel {
-               public static final int NOTE_HEIGHT = 10;
-               public static final int NOTE_WIDTH = 40;
-               private int trackLength;
+               public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200;
                private ArrayList rects;
 
                public NoteArea(Track track) {
                        // Configuring panel
                        super(true);
                        setLayout(null);
-                       trackLength = 140;
-                       setPreferredSize(new Dimension(200, 140 * NOTE_HEIGHT));
+                       setPreferredSize(new Dimension(VIEW_WIDTH, 140 * NOTE_HEIGHT));
 
                        // Creating temporary variables
                        MidiEvent note;
@@ -106,11 +103,8 @@ public class MooTrackView extends JPanel implements ActionListener {
                                        elem.setBounds(r);
                                        rects.add(r);
                                        if (viewLength < (y + height)) viewLength = y + height;
-
-                                       // while(findComponentAt(x, y) instanceof MooNoteElement ||
-                                       //       findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_WIDTH;
                                }
-                               setPreferredSize(new Dimension(200, viewLength));
+                               setPreferredSize(new Dimension(VIEW_WIDTH, viewLength));
                        }
                        validate();
                }
@@ -126,8 +120,8 @@ public class MooTrackView extends JPanel implements ActionListener {
                public void paintComponent(Graphics g) {
                        super.paintComponent(g);
                        Graphics2D g2 = (Graphics2D)g;
-                       for (int c = 0; c < viewLength ; c += NOTE_HEIGHT) {
-                               for (int r = 0; r < (10*NOTE_WIDTH); r += NOTE_WIDTH) {
+                       for (int c = 0; c < viewLength || c < getHeight(); c += NOTE_HEIGHT) {
+                               for (int r = 0; r < (10 * NOTE_WIDTH); r += NOTE_WIDTH) {
                                        box = new Rectangle(r, c, NOTE_WIDTH, NOTE_HEIGHT);
                                        g2.setColor(Color.gray);
                                        g2.draw(box);
index 3323540b55ae4cda0af8ac21659730ecd64a4bae..ca9d68db48ad49fb5fa0732489532a92b2bb512e 100644 (file)
@@ -29,7 +29,6 @@ public class MooView extends JScrollPane {
                JViewport columnHeader = new JViewport();
                columnHeader.setView(titlePanel);
                setColumnHeaderView(columnHeader);
-               numberOfTracks = tracks.length;
                setTracks(tracks);
        }
 
@@ -38,7 +37,8 @@ public class MooView extends JScrollPane {
         * @param tracks        the tracks for which to add views
         */
        public void setTracks(Track[] tracks) {
-               if (tracks.length == 1) {
+               numberOfTracks = tracks.length;
+               if (numberOfTracks == 1) {
                        // If MIDI file is of type 0, creates a view for the track.
                        trackPanel.add(new MooTrackView(tracks[0]));
                        titlePanel.add(new MooTrackTitle(tracks[0]));
@@ -55,7 +55,7 @@ public class MooView extends JScrollPane {
        
                        // Starts filling the track panel with track views, while updating the progress bar.
                        trackPanel.removeAll();
-                       trackPanel.setLayout(new GridLayout(1,tracks.length));
+                       trackPanel.setLayout(new GridLayout(1,numberOfTracks));
                        for (int i = 1; i < tracks.length; i++) {
                                trackPanel.add(new MooTrackView(tracks[i]));
                                titlePanel.add(new MooTrackTitle(tracks[i]));
@@ -63,6 +63,16 @@ public class MooView extends JScrollPane {
                        }
                        progressDialog.dispose();
                }
+/*             JPanel filler = new JPanel();
+               int totalViewLength = trackPanel.getComponents().length * MooTrackView.VIEW_WIDTH;
+               if (totalViewLength < getWidth()) {
+                       System.out.println("Adding filler since width = " + getWidth() + " and tracks = " + totalViewLength);
+                       ((GridLayout)trackPanel.getLayout()).setColumns(numberOfTracks + 1);
+                       filler.setPreferredSize(new Dimension(getWidth() - totalViewLength, 140 * MooTrackView.NOTE_HEIGHT));
+                       trackPanel.add(filler);
+                       setPreferredSize(new Dimension(getWidth(), getHeight()));
+               }
+*/
                trackPanel.validate();
                setViewportView(trackPanel);
        }
index b4c4259e0b02a6be66ef48f63c821f7229f65c4d..531e4f511886dcc96c10c7ed9d614f9da83d6bf0 100644 (file)
@@ -24,6 +24,7 @@ public class Moosique {
        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.
@@ -140,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.
@@ -153,7 +154,6 @@ public class Moosique {
        public static void play() {
                sequencer.setTickPosition(position);
                resume();
-               
        }
 
        /** 
@@ -176,7 +176,8 @@ public class Moosique {
                // Creates the visualization thread and starts it.
                player = new Thread () {
                        public void run() {
-                               gui.update(sequencer.getTickPosition());
+                               while(sequencer.isRunning()) gui.update(sequencer.getTickPosition());
+                               Moosique.stop();
                        }
                };
                player.start();
@@ -188,7 +189,7 @@ public class Moosique {
        public static void stop() {
                sequencer.stop();
                sequencer.setTickPosition(position);
-               player.destroy();
+               player.interrupt();
                gui.update((long)0);
        }