X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=MooTrackView.java;h=8133cda05f372feff297b0718db8b6e0853abef2;hp=bd7d7bb0b9c5a88aaf1d9909f046b27f3e0e8cc5;hb=1f2ba8a0848ee0c5f0ea94f7bc40ea502c0dff74;hpb=a8dda23889d7c48a8b3313e2a141ed378bf8ff1c diff --git a/MooTrackView.java b/MooTrackView.java index bd7d7bb..8133cda 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 @@ -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); } /** @@ -319,23 +320,26 @@ public class MooTrackView extends JPanel { } /** - * Moves the current selection, if the mouse was pressed on a note element - * and then released in another row. - * @param srcY the y-coordinate of the point in which the mouse button was pressed - * @param destY the y-coordinate of the point in which the mouse button was released + * Moves the current selection the given number of ticks. + * @param ticks the number of ticks to move the selection. */ - public void maybeMoveSelectedNotes(int srcY, int destY) { - int srcRow = (srcY - insets.top) / NOTE_HEIGHT; - int destRow = (destY - insets.top) / NOTE_HEIGHT; - long timeDiff = (long)(ticksPerSixteenth * (destRow - srcRow)); + public void moveSelectedNotes(int ticks) { Iterator it = selection.iterator(); while(it.hasNext()) { MooNoteElement elem = (MooNoteElement)it.next(); - elem.getNote().setTick(elem.getNote().getTick() + timeDiff); + 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