X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooNoteElement.java;h=8e5a3bde40b9d6fff8d1632211b3ff1fe2c2ae1e;hb=8cf7c1250a6734bf43381550728a1d8620d294dc;hp=3b08887000f07f515cbbcfab170972ef6fb0cfe3;hpb=5380690b9fc56b683d15765382669d79c50d3414;p=moosique.git diff --git a/MooNoteElement.java b/MooNoteElement.java index 3b08887..8e5a3bd 100644 --- a/MooNoteElement.java +++ b/MooNoteElement.java @@ -14,6 +14,8 @@ public class MooNoteElement extends JPanel { private MooNote note; private int columns; private boolean selected; + private Rectangle pitchRect, veloRect; + public static final Color bgColor = new Color(160, 218, 255); /** * Creates a new note element. @@ -22,7 +24,13 @@ public class MooNoteElement extends JPanel { */ public MooNoteElement (MooNote mn) { note = mn; - columns = mn.getDuration() / 24; + columns = mn.getDuration() / (Moosique.getSequence().getResolution() / 4); + setBorder(BorderFactory.createLineBorder(Color.black)); + setBackground(bgColor); + addMouseListener(new MAdapter()); + + pitchRect = new Rectangle(0, 0, 15, 10); + veloRect = new Rectangle(20, 0, 40, 10); } /** @@ -47,26 +55,27 @@ public class MooNoteElement extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); - if (note == null || !(g instanceof Graphics2D)) return; Graphics2D g2 = (Graphics2D)g; + g2.setFont(new Font("Helvetica", Font.PLAIN, 8)); String n = ""; int pitch = note.getPitch(); switch (pitch % 12) { - case 0: n = "C"; break; - case 1: n = "C#"; break; - case 2: n = "D"; break; - case 3: n = "D#"; break; - case 4: n = "E"; break; - case 5: n = "F"; break; - case 6: n = "F#"; break; - case 7: n = "G"; break; - case 8: n ="G#"; break; - case 9: n = "A"; break; + case 0: n = "C"; break; + case 1: n = "C#"; break; + case 2: n = "D"; break; + case 3: n = "D#"; break; + case 4: n = "E"; break; + case 5: n = "F"; break; + case 6: n = "F#"; break; + case 7: n = "G"; break; + case 8: n = "G#"; break; + case 9: n = "A"; break; case 10: n = "A#"; break; - case 11: n = "B"; break; + case 11: n = "B"; break; } + n += pitch / 12; /* switch(columns) { @@ -76,8 +85,30 @@ public class MooNoteElement extends JPanel { } */ - g2.setFont(new Font("Helvetica", Font.PLAIN, 8)); - n = n +(pitch/12); - g2.drawString(n + " "+ note.getVelocity(), 1, 9); + g2.drawString(n, 1, 9); + g2.drawString("" + note.getVelocity(), 21, 9); + } + + class MAdapter extends MouseAdapter { + public void mouseClicked(MouseEvent e) { + if (pitchRect.contains(e.getPoint())) { + if (SwingUtilities.isRightMouseButton(e)) { + note.setPitch(note.getPitch() + 1); + } else if (SwingUtilities.isLeftMouseButton(e)) { + note.setPitch(note.getPitch() - 1); + } + } else if (veloRect.contains(e.getPoint())) { + if (SwingUtilities.isRightMouseButton(e)) { + note.setVelocity(note.getVelocity() + 1); + } else if (SwingUtilities.isLeftMouseButton(e)) { + note.setVelocity(note.getVelocity() - 1); + } + } + e.getComponent().repaint(); + } + + public void mousePressed(MouseEvent e) {} + + public void mouseReleased(MouseEvent e) {} } } \ No newline at end of file