]> ruin.nu Git - moosique.git/blobdiff - MooTrackView.java
no message
[moosique.git] / MooTrackView.java
index 916e8fc387335f9cf1dac22d516a3606665696e4..1c7abe4a979bab0b6294131b4b556f132ef3508e 100644 (file)
@@ -18,20 +18,20 @@ public class MooTrackView extends JPanel {
        private MooKeyboard keyboard;
 
        private JPopupMenu popup, selPopup;
-       private JMenu selPopupTranspUp, selPopupTranspDown;
-       private JMenuItem popupAdd, popupPaste;
+       private JMenu popupAdd, selPopupTranspUp, selPopupTranspDown;
+       private JMenuItem popupAddItemsCustom, popupAddItemsLast, popupPaste;
+       private JMenuItem popupAddItemsWhole, popupAddItemsHalf, popupAddItemsQuarter, popupAddItemsEighth, popupAddItemsSixteenth;
        private JMenuItem selPopupCopy, selPopupCut, selPopupRemove;
        private JMenuItem[] selPopupTranspUpItems, selPopupTranspDownItems;
 
        private ArrayList coords; 
-       private TreeSet selection;
        private Insets insets;
        private Rectangle box;
-       private int ticksPerSixteenth, popupY = 0;
+       private int ticksPerSixteenth, popupY = 0, lastNoteLength = 2;
        private boolean leftMouseButtonPressed = false;
        private static boolean snapToSixteenths = true;
-       protected static int viewLength = 0;
-       protected static int extraHeight = 0;
+       private static int viewLength = 0;
+       private static int extraHeight = 0;
        public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200;
 
        /**
@@ -48,7 +48,6 @@ public class MooTrackView extends JPanel {
                ticksPerSixteenth = Moosique.getSequence().getResolution() / 4;
                insets = getInsets();
                coords = new ArrayList(track.size() / 2);
-               selection = new TreeSet();
 
                // Configures panel
                setBackground(Color.white);
@@ -76,7 +75,16 @@ public class MooTrackView extends JPanel {
 
                // Creates panel pop-up menu.
                popup = new JPopupMenu();
-               popupAdd = addMenuItem(popup, "Add note...");
+               popupAdd = new JMenu("Add note");
+               popup.add(popupAdd);
+               popupAddItemsCustom = addMenuItem(popupAdd, "Custom...");
+               popupAddItemsLast = addMenuItem(popupAdd, "As last added");
+               popupAdd.addSeparator();
+               popupAddItemsWhole = addMenuItem(popupAdd, "Whole");
+               popupAddItemsHalf = addMenuItem(popupAdd, "Half");
+               popupAddItemsQuarter = addMenuItem(popupAdd, "Quarter");
+               popupAddItemsEighth = addMenuItem(popupAdd, "Eighth");
+               popupAddItemsSixteenth = addMenuItem(popupAdd, "Sixteenth");
                popupPaste = addMenuItem(popup, "Paste");
 
                // Creates selection pop-up menu.
@@ -209,10 +217,11 @@ public class MooTrackView extends JPanel {
        /**
         * Adds a standard note to this track.
         */
-       private void addStandardNote() {
+       private void addNoteAtClickY(int length) {
+               lastNoteLength = length;
                int row = (popupY - insets.top) / NOTE_HEIGHT;
                long timestamp = (long)(ticksPerSixteenth * row);
-               addNote(new MooNote(title.getChannel(), 60, 100, timestamp, Moosique.getSequence().getResolution() / 4));
+               addNote(new MooNote(title.getChannel(), 60, 100, timestamp, ticksPerSixteenth * length));
        }
 
        /** 
@@ -230,49 +239,11 @@ public class MooTrackView extends JPanel {
                repaint();
        }
 
-       /**
-        * Selects the given note
-        * @param the note to select
-        */
-       public void selectNote(MooNoteElement elem) {
-               selection.add(elem);
-       }
-
-       /**
-        * Deselects the given note
-        * @param the note to deselect
-        */
-       public void deselectNote(MooNoteElement elem) {
-               selection.remove(elem);
-       }
-
-       /**
-        * Deselects all notes.
-        */
-       public void deselectAllNotes() {
-               Iterator it = selection.iterator();
-               while(it.hasNext()) {
-                       ((MooNoteElement)it.next()).deselect();
-               }
-               selection.clear();
-       }
-
-       /**
-        * Determines if the given MooNoteElement is the only one in the track view that is selected.
-        * @return if the given element is the only selected one
-        */
-       public boolean isTheOnlySelected(MooNoteElement elem) {
-               Iterator it = selection.iterator();
-               while(it.hasNext()) {
-                       if (!it.next().equals(elem)) return false;
-               }
-               return true;
-       }
-
        /**
         * Copies the current selection.
         */
        public void copySelectedNotes() {
+               TreeSet selection = Moosique.getSelection();
                ArrayList copyBuffer = new ArrayList(selection.size());
                Iterator it = selection.iterator();
                while(it.hasNext()) {
@@ -306,6 +277,7 @@ public class MooTrackView extends JPanel {
                                mn.setChannel(title.getChannel());
                                addNote(mn);
                        }
+                       Moosique.setEdited();
                }
        }
 
@@ -313,22 +285,26 @@ public class MooTrackView extends JPanel {
         * Removes the current selection.
         */
        public void removeSelectedNotes() {
+               TreeSet selection = Moosique.getSelection();
                Iterator it = selection.iterator();
                while(it.hasNext()) {
                        removeNote((MooNoteElement)it.next());
                }
                selection.clear();
+               Moosique.setEdited();
        }
 
        /**
         * Transposes all selected notes the given number of halftones.
         */
        private void transposeSelectedNotes(int halftones) {
+               TreeSet selection = Moosique.getSelection();
                Iterator it = selection.iterator();
                while(it.hasNext()) {
                        MooNoteElement elem = (MooNoteElement)it.next();
                        elem.transpose(halftones);
                }
+               Moosique.setEdited();
        }
 
        /**
@@ -336,6 +312,7 @@ public class MooTrackView extends JPanel {
         * @param ticks         the number of ticks to move the selection.
         */
        public void moveSelectedNotes(int ticks) {
+               TreeSet selection = Moosique.getSelection();
                if (ticks < 0) {
                        // If the selection should be moved upwards, traverses the list in the natural order.
                        Iterator it = selection.iterator();
@@ -354,14 +331,7 @@ public class MooTrackView extends JPanel {
                                layoutElement(elem, true);
                        }
                }
-       }
-
-       /**
-        * Moves the current selection, depending on the given delta y.
-        * @param y     the number of pixels the selection is moved.
-        */
-       public void maybeMoveSelectedNotes(int y) {
-               moveSelectedNotes(ticksPerSixteenth * (y / NOTE_HEIGHT));
+               Moosique.setEdited();
        }
 
        /**
@@ -456,10 +426,10 @@ public class MooTrackView extends JPanel {
                 */
                public void mouseClicked(MouseEvent e) {
                        if (SwingUtilities.isLeftMouseButton(e)) {
-                               deselectAllNotes();
+                               Moosique.deselectAllNotes();
                                if (e.getClickCount() == 2) {
                                        popupY = e.getY();
-                                       addStandardNote();
+                                       addNoteAtClickY(lastNoteLength);
                                }
                        }
                }
@@ -500,8 +470,23 @@ public class MooTrackView extends JPanel {
                public void actionPerformed(ActionEvent e) {
                        Object source = e.getSource();
                        // Handling panel popup actions.
-                       if (source == popupAdd) {
-                               addStandardNote();
+                       if (source == popupAddItemsLast) {
+                               addNoteAtClickY(lastNoteLength);
+                       } else if (source == popupAddItemsCustom) {
+                               /* Show the user a dialog (identical to note preferences...
+                               then call       addNote(new MooNote(
+                               title.getChannel(), pitch, velocity, timestamp, duration));
+                               */
+                       } else if (source == popupAddItemsWhole) {
+                               addNoteAtClickY(16);
+                       } else if (source == popupAddItemsHalf) {
+                               addNoteAtClickY(8);
+                       } else if (source == popupAddItemsQuarter) {
+                               addNoteAtClickY(4);
+                       } else if (source == popupAddItemsEighth) {
+                               addNoteAtClickY(2);
+                       } else if (source == popupAddItemsSixteenth) {
+                               addNoteAtClickY(1);
                        } else if (source == popupPaste) {
                                pasteCopiedNotes();
                        // Handling selection popup actions.