+ /**
+ * Adds a standard note to this track.
+ */
+ 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, ticksPerSixteenth * length));
+ }
+
+ /**
+ * Removes the given note element from the view and its note from the current track.
+ * @param elem the note element to remove
+ */
+ public void removeNote(MooNoteElement elem) {
+ elem.getNote().removeFrom(track);
+ remove(elem);
+ Rectangle r = new Rectangle();
+ r = elem.getBounds(r);
+ coords.remove(r);
+ Moosique.setEdited();
+ validate();
+ repaint();
+ }
+
+ /**
+ * Copies the current selection.
+ */
+ public void copySelectedNotes() {
+ TreeSet selection = Moosique.getSelection();
+ ArrayList copyBuffer = new ArrayList(selection.size());
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ copyBuffer.add(((MooNoteElement)it.next()).getNote().clone());
+ }
+ Collections.sort(copyBuffer);
+ Moosique.setCopyBuffer(copyBuffer);
+ }
+
+ /**
+ * Cuts the current selection.
+ */
+ public void cutSelectedNotes() {
+ copySelectedNotes();
+ removeSelectedNotes();
+ }
+
+ /**
+ * Pastes the current copy buffer at the given timestamp.
+ */
+ public void pasteCopiedNotes() {
+ int row = (popupY - insets.top) / NOTE_HEIGHT;
+ long timestamp = (long)(ticksPerSixteenth * row);
+ ArrayList copyBuffer = Moosique.getCopyBuffer();
+ if (copyBuffer.size() > 0) {
+ long startTime = ((MooNote)copyBuffer.get(0)).getTick();
+ Iterator it = copyBuffer.iterator();
+ while(it.hasNext()) {
+ MooNote mn = (MooNote)((MooNote)it.next()).clone();
+ mn.setTick(mn.getTick() - startTime + timestamp);
+ mn.setChannel(title.getChannel());
+ addNote(mn);
+ }
+ Moosique.setEdited();
+ }
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * Moves the current selection the given number of ticks.
+ * @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();
+ 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 downwards, 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);