]> ruin.nu Git - moosique.git/blobdiff - MooTrackView.java
Fixed accessors, encoders and decoders for tempo and time signature.
[moosique.git] / MooTrackView.java
index cb22b42def09d6aa15a1223891a317fc5df0e729..916e8fc387335f9cf1dac22d516a3606665696e4 100644 (file)
@@ -28,7 +28,8 @@ public class MooTrackView extends JPanel {
        private Insets insets;
        private Rectangle box;
        private int ticksPerSixteenth, popupY = 0;
-       private boolean leftMouseButtonPressed = false, quantizeRecording = false;
+       private boolean leftMouseButtonPressed = false;
+       private static boolean snapToSixteenths = true;
        protected static int viewLength = 0;
        protected static int extraHeight = 0;
        public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200;
@@ -44,7 +45,10 @@ public class MooTrackView extends JPanel {
                // Defines instance variables
                this.track = track;
                this.title = title;
+               ticksPerSixteenth = Moosique.getSequence().getResolution() / 4;
                insets = getInsets();
+               coords = new ArrayList(track.size() / 2);
+               selection = new TreeSet();
 
                // Configures panel
                setBackground(Color.white);
@@ -52,7 +56,23 @@ public class MooTrackView extends JPanel {
                setLayout(null);
                setPreferredSize(new Dimension(VIEW_WIDTH, 140 * NOTE_HEIGHT));
 
-               placeNoteElements(false);
+               // 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();
@@ -76,25 +96,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(boolean quantize) {
-               // Converts the track.
-               Moosique.convertTrack(track);
-
-               // 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;
@@ -102,8 +114,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));
        }       
 
        /**
@@ -126,21 +138,15 @@ public class MooTrackView extends JPanel {
                }
 
                // Creates temporary variables.
-               ticksPerSixteenth = Moosique.getSequence().getResolution() / 4;
                MooNote mn = elem.getNote();
                int x, y, height;
 
                // Calculates coordinates.
                x = insets.left;
-               if (quantizeRecording) {
-                       // Snap to nearest sixteenth
-                       y = insets.top + Math.round(mn.getTick() / ticksPerSixteenth) * NOTE_HEIGHT;
-                       height = (mn.getDuration() / ticksPerSixteenth) * NOTE_HEIGHT;
-               } else {
-                       y = insets.top + (int)((mn.getTick() * NOTE_HEIGHT) / ticksPerSixteenth);
-                       height = (mn.getDuration() * NOTE_HEIGHT) / ticksPerSixteenth;
-               }
+               y = insets.top + (int)((mn.getTick() * NOTE_HEIGHT) / ticksPerSixteenth);
+               height = (mn.getDuration() * NOTE_HEIGHT) / ticksPerSixteenth;
                if (height == 0) height = NOTE_HEIGHT;
+               if (snapToSixteenths && height < NOTE_HEIGHT) height = NOTE_HEIGHT;
                r = new Rectangle(x, y, NOTE_WIDTH, height);
 
                // Places the element in the appropriate place.