X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=MooNoteElement.java;h=7ea74227d0be3a456226583adfa3fe9a8bed560f;hp=f6bda05e3b447642af0acffa007f5083e6eaf915;hb=6154ba318198471a2b94391df6aab6f2b6cd9b29;hpb=078f6f3d4afcd990dadf7cf5f05b2af39ea7b3a9 diff --git a/MooNoteElement.java b/MooNoteElement.java index f6bda05..7ea7422 100644 --- a/MooNoteElement.java +++ b/MooNoteElement.java @@ -14,7 +14,7 @@ public class MooNoteElement extends JPanel { private MooTrackView mtv; private MooNote note; private JPopupMenu popup; - private JMenuItem popupRemove, popupProp, popupTransposeOctUp, popupTransposeOctDown; + private JMenuItem popupRemove, popupProp, popupTranspOctUp, popupTranspOctDown; private Rectangle pitchRect, veloRect; private String notePitch, noteVelocity; private boolean selected = false; @@ -25,7 +25,7 @@ public class MooNoteElement extends JPanel { /** * Creates a new note element. * @param parent The MooTrackView that this element will be painted on. - * @param mn the note that will be graphically represented + * @param mn the note that will be graphically represented */ public MooNoteElement (MooTrackView parent, MooNote mn) { mtv = parent; @@ -49,12 +49,12 @@ public class MooNoteElement extends JPanel { popupRemove = new JMenuItem("Remove"); popupRemove.addActionListener(pList); popup.add(popupRemove); - popupTransposeOctUp = new JMenuItem("Transpose one octave up"); - popupTransposeOctUp.addActionListener(pList); - popup.add(popupTransposeOctUp); - popupTransposeOctDown = new JMenuItem("Transpose one octave down"); - popupTransposeOctDown.addActionListener(pList); - popup.add(popupTransposeOctDown); + popupTranspOctUp = new JMenuItem("Transpose one octave up"); + popupTranspOctUp.addActionListener(pList); + popup.add(popupTranspOctUp); + popupTranspOctDown = new JMenuItem("Transpose one octave down"); + popupTranspOctDown.addActionListener(pList); + popup.add(popupTranspOctDown); } /** @@ -70,7 +70,7 @@ public class MooNoteElement extends JPanel { */ public void select() { selected = true; - mtv.addSelected(this); + mtv.selectNote(this); setBackground(invBgColor); textColor = Color.white; repaint(); @@ -81,12 +81,21 @@ public class MooNoteElement extends JPanel { */ public void deselect() { selected = false; - // mtv.removeSelected(this); + // mtv.deselectNote(this); setBackground(bgColor); textColor = Color.black; repaint(); } + /** + * Transposes the current note element the given number of halftones. + * @param halftones the number of halftones to transpose - positive for up, negative for down + */ + public void transpose(int halftones) { + note.transpose(halftones); + update(); + } + /** * Draws the string that shows the note's properties. * @param g The Graphics object used to draw the strings. @@ -134,7 +143,7 @@ public class MooNoteElement extends JPanel { case 10: notePitch = "A#"; break; case 11: notePitch = "B"; break; } - notePitch += pitch / 12; + notePitch += pitch / 12 - 1; noteVelocity = ""+note.getVelocity(); } @@ -147,16 +156,32 @@ public class MooNoteElement extends JPanel { } /** - * layout this changed elemnt + * Updates the graphical content of the element and repaints it. + */ + public void update() { + calculateString(); + repaint(); + } + + /** + * Layout this changed elemnt. */ protected void newLayout(){ mtv.layoutElement(this,true); } + /** * Listener that checks the mouse actions on this element. */ class MAdapter extends MouseAdapter { + /** + * Selects the note if + */ + public void mouseEntered(MouseEvent e) { + if (mtv.isLeftMouseButtonPressed()) select(); + } + /** * If left mouse button is clicked, selects the note and plays it. */ @@ -177,9 +202,9 @@ public class MooNoteElement extends JPanel { if (e.isControlDown()) { if (pitchRect.contains(e.getPoint())) { if (SwingUtilities.isRightMouseButton(e)) { - note.setPitch(note.getPitch() + 1); + note.transpose(1); } else if (SwingUtilities.isLeftMouseButton(e)) { - note.setPitch(note.getPitch() - 1); + note.transpose(-1); } Moosique.setEdited(); calculateString(); @@ -223,19 +248,11 @@ public class MooNoteElement extends JPanel { newLayout(); } else if (source == popupRemove) { remove(); - } else if (source == popupTransposeOctUp) { - note.setPitch(note.getPitch() + 12); - update(); - } else if (source == popupTransposeOctDown) { - note.setPitch(note.getPitch() - 12); - update(); + } else if (source == popupTranspOctUp) { + transpose(12); + } else if (source == popupTranspOctDown) { + transpose(-12); } } - - private void update() { - calculateString(); - repaint(); - } - } }