Skip to content

Commit

Permalink
パネルの継承関係を修正しました.
Browse files Browse the repository at this point in the history
  • Loading branch information
fourthline committed Apr 4, 2014
1 parent 1a3d018 commit 3a88b12
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 64 deletions.
41 changes: 0 additions & 41 deletions src/fourthline/mabiicco/ui/AbstractMMLView.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/fourthline/mabiicco/ui/ColumnPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/fourthline/mabiicco/ui/IMMLView.java
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 12 additions & 10 deletions src/fourthline/mabiicco/ui/KeyboardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );
}
});
Expand Down Expand Up @@ -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);
}
Expand All @@ -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]);
Expand All @@ -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);
}

// グリッド
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/fourthline/mabiicco/ui/MMLSeqView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 34 additions & 10 deletions src/fourthline/mabiicco/ui/PianoRollView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3a88b12

Please sign in to comment.