From 3a88b12bc1aa4b5fd98013e0eb340fc26aa71270 Mon Sep 17 00:00:00 2001 From: fourthline Date: Fri, 4 Apr 2014 22:38:09 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=83=8D=E3=83=AB=E3=81=AE=E7=B6=99?= =?UTF-8?q?=E6=89=BF=E9=96=A2=E4=BF=82=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mabiicco/ui/AbstractMMLView.java | 41 ----------------- src/fourthline/mabiicco/ui/ColumnPanel.java | 2 +- src/fourthline/mabiicco/ui/IMMLView.java | 10 +++++ src/fourthline/mabiicco/ui/KeyboardView.java | 22 +++++----- src/fourthline/mabiicco/ui/MMLSeqView.java | 4 +- src/fourthline/mabiicco/ui/PianoRollView.java | 44 ++++++++++++++----- 6 files changed, 59 insertions(+), 64 deletions(-) delete mode 100644 src/fourthline/mabiicco/ui/AbstractMMLView.java create mode 100644 src/fourthline/mabiicco/ui/IMMLView.java diff --git a/src/fourthline/mabiicco/ui/AbstractMMLView.java b/src/fourthline/mabiicco/ui/AbstractMMLView.java deleted file mode 100644 index 9f9a4db2..00000000 --- a/src/fourthline/mabiicco/ui/AbstractMMLView.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2013-2014 たんらる - */ - -package fourthline.mabiicco.ui; - -import javax.swing.JPanel; - - - -public abstract class AbstractMMLView extends JPanel { - private static final long serialVersionUID = -701943909797286599L; - public static final int OCTNUM = 9; - public static final int HEIGHT_C = 6; - - /** - * Panel上のy座標をnote番号に変換します. - * @param y - * @return - */ - public final int convertY2Note(int y) { - int note = -1; - if (y >= 0) { - note = (OCTNUM*12-(y/HEIGHT_C)) -1; - } - - return note; - } - - /** - * note番号をPanel上のy座標に変換します. - * @param note - * @return - */ - public final int convertNote2Y(int note) { - int y = OCTNUM*12 - note - 1; - y *= HEIGHT_C; - - return y; - } -} diff --git a/src/fourthline/mabiicco/ui/ColumnPanel.java b/src/fourthline/mabiicco/ui/ColumnPanel.java index 45eda48f..ae96f129 100644 --- a/src/fourthline/mabiicco/ui/ColumnPanel.java +++ b/src/fourthline/mabiicco/ui/ColumnPanel.java @@ -32,7 +32,7 @@ import fourthline.mmlTools.MMLTempoEvent; -public class ColumnPanel extends AbstractMMLView implements MouseListener, ActionListener { +public class ColumnPanel extends JPanel implements MouseListener, ActionListener { private static final long serialVersionUID = -6609938350741425221L; private static final Color BEAT_BORDER_COLOR = new Color(0.4f, 0.4f, 0.4f); diff --git a/src/fourthline/mabiicco/ui/IMMLView.java b/src/fourthline/mabiicco/ui/IMMLView.java new file mode 100644 index 00000000..ff9abe70 --- /dev/null +++ b/src/fourthline/mabiicco/ui/IMMLView.java @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2013-2014 たんらる + */ + +package fourthline.mabiicco.ui; + +public interface IMMLView { + public static final int OCTNUM = 9; + public static final int HEIGHT_C = 6; +} diff --git a/src/fourthline/mabiicco/ui/KeyboardView.java b/src/fourthline/mabiicco/ui/KeyboardView.java index b16103d8..fcabcc79 100644 --- a/src/fourthline/mabiicco/ui/KeyboardView.java +++ b/src/fourthline/mabiicco/ui/KeyboardView.java @@ -13,27 +13,29 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; +import javax.swing.JPanel; + import fourthline.mabiicco.midi.MabiDLS; -public class KeyboardView extends AbstractMMLView { +public class KeyboardView extends JPanel implements IMMLView { private static final long serialVersionUID = -3850112420986284800L; private int playNote = -1; private final int width = 60; private final int PLAY_CHANNEL = 0; - IMMLManager mmlManager; + private final IMMLManager mmlManager; /** * Create the panel. */ - public KeyboardView(IMMLManager manager) { + public KeyboardView(IMMLManager manager, final PianoRollView pianoRollView) { setPreferredSize(new Dimension(width, 649)); this.mmlManager = manager; this.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - int note = convertY2Note( e.getY() ); + int note = pianoRollView.convertY2Note( e.getY() ); playNote( note ); } @Override @@ -44,7 +46,7 @@ public void mouseReleased(MouseEvent e) { this.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { - int note = convertY2Note( e.getY() ); + int note = pianoRollView.convertY2Note( e.getY() ); playNote( note ); } }); @@ -97,7 +99,7 @@ private void paintPlayNote(Graphics2D g) { if ( isWhiteKey(playNote) ) { x += 20; } - int y = getHeight() - ((playNote -11) * AbstractMMLView.HEIGHT_C) + yAdd[playNote%12]; + int y = getHeight() - ((playNote -11) * HEIGHT_C) + yAdd[playNote%12]; g.setColor(Color.RED); g.fillOval(x, y, 4, 4); } @@ -107,7 +109,7 @@ private void paintOctPianoLine(Graphics2D g, int pos, char posText) { // ド~シのしろ鍵盤 g.setColor(new Color(0.3f, 0.3f, 0.3f)); - int startY = 12 * AbstractMMLView.HEIGHT_C * pos; + int startY = 12 * HEIGHT_C * pos; int y = startY; for (int i = 0; i < white_wigth.length; i++) { g.drawRect(0, y, 40, white_wigth[i]); @@ -127,10 +129,10 @@ private void paintOctPianoLine(Graphics2D g, int pos, char posText) { y = (black_posIndex[i]*10+5)+startY+posOffset[i]; g.setColor(new Color(0.0f, 0.0f, 0.0f)); - g.fillRect(0, y, 20, AbstractMMLView.HEIGHT_C); + g.fillRect(0, y, 20, HEIGHT_C); g.setColor(new Color(0.3f, 0.3f, 0.3f)); - g.drawRect(0, y, 20, AbstractMMLView.HEIGHT_C); + g.drawRect(0, y, 20, HEIGHT_C); } // グリッド @@ -141,7 +143,7 @@ private void paintOctPianoLine(Graphics2D g, int pos, char posText) { // オクターブ char o_char[] = { 'o', posText }; g.setFont(new Font("Arial", Font.PLAIN, 12)); - y = startY + (12 * AbstractMMLView.HEIGHT_C); + y = startY + (12 * HEIGHT_C); g.drawChars(o_char, 0, o_char.length, 42, y); g.drawLine(40, y, width, y); } diff --git a/src/fourthline/mabiicco/ui/MMLSeqView.java b/src/fourthline/mabiicco/ui/MMLSeqView.java index 4224524b..71fe04ef 100644 --- a/src/fourthline/mabiicco/ui/MMLSeqView.java +++ b/src/fourthline/mabiicco/ui/MMLSeqView.java @@ -71,12 +71,12 @@ public MMLSeqView() { // Scroll View (KeyboardView, PianoRollView) - CENTER pianoRollView = new PianoRollView(); - keyboardView = new KeyboardView(this); + keyboardView = new KeyboardView(this, pianoRollView); scrollPane = new JScrollPane(pianoRollView); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); - scrollPane.getVerticalScrollBar().setUnitIncrement(AbstractMMLView.HEIGHT_C); + scrollPane.getVerticalScrollBar().setUnitIncrement(IMMLView.HEIGHT_C); add(scrollPane, BorderLayout.CENTER); pianoRollView.setViewportAndParent(scrollPane.getViewport(), this); diff --git a/src/fourthline/mabiicco/ui/PianoRollView.java b/src/fourthline/mabiicco/ui/PianoRollView.java index 46692eb3..547ffc18 100644 --- a/src/fourthline/mabiicco/ui/PianoRollView.java +++ b/src/fourthline/mabiicco/ui/PianoRollView.java @@ -12,6 +12,7 @@ import java.awt.Rectangle; import java.util.List; +import javax.swing.JPanel; import javax.swing.JViewport; import javax.swing.event.MouseInputListener; @@ -28,7 +29,7 @@ /** * ピアノロール表示を行うためのビューです. */ -public class PianoRollView extends AbstractMMLView { +public class PianoRollView extends JPanel implements IMMLView { private static final long serialVersionUID = -7229093886476553295L; private double wideScale = 6; // ピアノロールの拡大/縮小率 (1~6) @@ -76,7 +77,6 @@ public class PianoRollView extends AbstractMMLView { private static final Color barBorder = new Color(0.5f, 0.5f, 0.5f); private static final Color darkBarBorder = new Color(0.3f, 0.2f, 0.3f); - /** * Create the panel. */ @@ -166,6 +166,32 @@ public int convertTicktoX(long tick) { return (int)(tick / wideScale); } + /** + * Panel上のy座標をnote番号に変換します. + * @param y + * @return + */ + public final int convertY2Note(int y) { + int note = -1; + if (y >= 0) { + note = (OCTNUM*12-(y/HEIGHT_C)) -1; + } + + return note; + } + + /** + * note番号をPanel上のy座標に変換します. + * @param note + * @return + */ + public final int convertNote2Y(int note) { + int y = OCTNUM*12 - note - 1; + y *= HEIGHT_C; + + return y; + } + public long getSequencePossition() { return sequencePosition; } @@ -221,8 +247,8 @@ public void paintComponent(Graphics g) { updateViewWidthTrackLength(); Graphics2D g2 = (Graphics2D)g.create(); - for (int i = 0; i < AbstractMMLView.OCTNUM; i++) { - paintOctPianoLine(g2, i, (char)('0'+AbstractMMLView.OCTNUM-i-1)); + for (int i = 0; i < OCTNUM; i++) { + paintOctPianoLine(g2, i, (char)('0'+OCTNUM-i-1)); } paintMeasure(g2); @@ -240,16 +266,14 @@ public void paintComponent(Graphics g) { paintActiveTrack(g2); paintSelectedNote(g2); paintSelectingArea(g2); - paintSequenceLine(g2, convertNote2Y(-1)); g2.dispose(); } - private void paintOctPianoLine(Graphics2D g, int pos, char posText) { - int startY = 12 * AbstractMMLView.HEIGHT_C * pos; - int octave = AbstractMMLView.OCTNUM - pos - 1; + int startY = 12 * HEIGHT_C * pos; + int octave = OCTNUM - pos - 1; // グリッド int y = startY; @@ -261,7 +285,7 @@ private void paintOctPianoLine(Graphics2D g, int pos, char posText) { fillColor = noSoundColor; } g.setColor(fillColor); - g.fillRect(0, i*HEIGHT_C+y, width, AbstractMMLView.HEIGHT_C); + g.fillRect(0, i*HEIGHT_C+y, width, HEIGHT_C); if (i == 0) { g.setColor(darkBarBorder); } else { @@ -345,7 +369,7 @@ private void drawNote(Graphics2D g, MMLNoteEvent noteEvent, Color rectColor, Col int x = convertTicktoX(offset); int y = convertNote2Y(note) +1; int width = convertTicktoX(tick) -1; - int height = AbstractMMLView.HEIGHT_C-2; + int height = HEIGHT_C-2; if (width > 1) width--; g.setColor(fillColor);