X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooTrackView.java;h=c1d8b5878cdb66b4f4b0d1ceef38a3f62c499f83;hb=fa159bea01bba1b1294fcc5ed14546b7510dcd3d;hp=a591d374853bd246647f16dd0c087ce38f58e335;hpb=6154ba318198471a2b94391df6aab6f2b6cd9b29;p=moosique.git diff --git a/MooTrackView.java b/MooTrackView.java index a591d37..c1d8b58 100644 --- a/MooTrackView.java +++ b/MooTrackView.java @@ -22,7 +22,8 @@ public class MooTrackView extends JPanel { private JMenuItem popupAdd, popupPaste; private JMenuItem selPopupCopy, selPopupCut, selPopupRemove, selPopupTranspUpOct, selPopupTranspDownOct; - private ArrayList coords, selection, copyBuffer; + private ArrayList coords, copyBuffer; + private TreeSet selection; private Insets insets; private int ticksPerSixteenth, popupY = 0; private boolean leftMouseButtonPressed = false; @@ -43,7 +44,7 @@ public class MooTrackView extends JPanel { // Creates instance variables insets = getInsets(); coords = new ArrayList(track.size() / 2); - selection = new ArrayList(); + selection = new TreeSet(); copyBuffer = new ArrayList(); // Creates temporary variables @@ -134,7 +135,7 @@ public class MooTrackView extends JPanel { // Calculates coordinates. x = insets.left; - y = insets.top + (int)(mn.getTick() / ticksPerSixteenth) * NOTE_HEIGHT; + y = insets.top + Math.round(mn.getTick() / ticksPerSixteenth) * NOTE_HEIGHT; height = (mn.getDuration() / ticksPerSixteenth) * NOTE_HEIGHT; if (height == 0) height = NOTE_HEIGHT; r = new Rectangle(x, y, NOTE_WIDTH, height); @@ -233,7 +234,7 @@ public class MooTrackView extends JPanel { * @param the note to deselect */ public void deselectNote(MooNoteElement elem) { - selection.remove(selection.indexOf(elem)); + selection.remove(elem); } /** @@ -268,7 +269,7 @@ public class MooTrackView extends JPanel { while(it.hasNext()) { copyBuffer.add(((MooNoteElement)it.next()).getNote().clone()); } - Collections.sort(copyBuffer, new Moosique.NoteComparator()); + Collections.sort(copyBuffer); } /** @@ -318,6 +319,39 @@ public class MooTrackView extends JPanel { } } + /** + * Moves the current selection the given number of ticks. + * @param ticks the number of ticks to move the selection. + */ + public void moveSelectedNotes(int ticks) { + if (ticks > 0) { + // If the selection should be moved downwards, traverses the list in the natural order. + Iterator it = selection.iterator(); + while(it.hasNext()) { + MooNoteElement elem = (MooNoteElement)it.next(); + elem.getNote().setTick(elem.getNote().getTick() + ticks); + layoutElement(elem, true); + } + } else { + // If the selection should be moved upwards, traverses the list in the opposite order. + ArrayList selectedList = new ArrayList(selection); + ListIterator it = selectedList.listIterator(selectedList.size()); + while(it.hasPrevious()) { + MooNoteElement elem = (MooNoteElement)it.previous(); + elem.getNote().setTick(elem.getNote().getTick() + ticks); + 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)); + } + /** * Shows a popup-menu with options for the current selection of note elements. * @param c the component over which to display the menu @@ -380,13 +414,6 @@ public class MooTrackView extends JPanel { maybeShowPopup(e); } - /** - * Selects the notes within the area that was selected. - */ - public void mouseDragged(MouseEvent e) { - - } - /** * Shows the menu if an OS-specific popup-trigger was activated. */