OSDN Git Service

リファクタリング:調号選択GUIなど
authorAkiyoshi Kamide <kamide@yk.rim.or.jp>
Tue, 10 Jan 2017 16:16:38 +0000 (01:16 +0900)
committerAkiyoshi Kamide <kamide@yk.rim.or.jp>
Tue, 10 Jan 2017 16:16:38 +0000 (01:16 +0900)
src/camidion/chordhelper/ChordHelperApplet.java
src/camidion/chordhelper/midieditor/KeySignatureComboBox.java [new file with mode: 0644]
src/camidion/chordhelper/midieditor/KeySignatureSelecter.java
src/camidion/chordhelper/midieditor/MidiMessageForm.java
src/camidion/chordhelper/midieditor/MinorCheckBox.java [new file with mode: 0644]
src/camidion/chordhelper/music/Key.java
src/camidion/chordhelper/pianokeyboard/MidiKeyboardPanel.java
src/camidion/chordhelper/pianokeyboard/PianoKeyboard.java
src/camidion/chordhelper/pianokeyboard/PianoKeyboardPanel.java

index d0fe08e..18e0e03 100644 (file)
@@ -283,7 +283,7 @@ public class ChordHelperApplet extends JApplet {
         */
        public static class VersionInfo {
                public static final String      NAME = "MIDI Chord Helper";
-               public static final String      VERSION = "Ver.20170109.1";
+               public static final String      VERSION = "Ver.20170110.1";
                public static final String      COPYRIGHT = "Copyright (C) 2004-2017";
                public static final String      AUTHER = "@きよし - Akiyoshi Kamide";
                public static final String      URL = "http://www.yk.rim.or.jp/~kamide/music/chordhelper/";
@@ -451,7 +451,7 @@ public class ChordHelperApplet extends JApplet {
                                @Override
                                public void pianoKeyPressed(int n, InputEvent e) { chordDiagram.clear(); }
                        });
-                       keySelecter.keysigCombobox.addActionListener(new ActionListener() {
+                       keySelecter.getKeysigCombobox().addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                        chordMatrix.setKeySignature(keySelecter.getSelectedKey().transposedKey(-chordMatrix.capoSelecter.getCapo()));
diff --git a/src/camidion/chordhelper/midieditor/KeySignatureComboBox.java b/src/camidion/chordhelper/midieditor/KeySignatureComboBox.java
new file mode 100644 (file)
index 0000000..255376d
--- /dev/null
@@ -0,0 +1,36 @@
+package camidion.chordhelper.midieditor;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JComboBox;
+
+import camidion.chordhelper.music.Key;
+import camidion.chordhelper.music.Note;
+
+public class KeySignatureComboBox extends JComboBox<Key> implements ActionListener {
+       {
+               for(int co5 = -Key.MAX_SHARPS_OR_FLATS ; co5 <= Key.MAX_SHARPS_OR_FLATS ; co5++)
+                       addItem(new Key(co5));
+               setMaximumRowCount(getItemCount());
+               addActionListener(this);
+       }
+       @Override
+       public void actionPerformed(ActionEvent e) {
+               String text = "Key: ";
+               Key k = (Key) getSelectedItem();
+               text += k.toStringIn(Note.Language.NAME);
+               text += " "  + k.toStringIn(Note.Language.IN_JAPANESE);
+               text += " (" + k.signatureDescription() + ")";
+               setToolTipText(text);
+       }
+       @Override
+       public void setSelectedItem(Object anObject) {
+               if( anObject instanceof Key ) {
+                       Key k = (Key) anObject;
+                       if( k.majorMinor() != Key.MajorMinor.MAJOR_OR_MINOR )
+                               anObject = new Key(k.toCo5());
+               }
+               super.setSelectedItem(anObject);
+       }
+}
index e98415c..4ec13f5 100644 (file)
@@ -1,56 +1,31 @@
 package camidion.chordhelper.midieditor;
 
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 
 import camidion.chordhelper.music.Key;
-import camidion.chordhelper.music.Note;
 
 /**
  * 調性選択フォーム
  */
-public class KeySignatureSelecter extends JPanel implements ActionListener {
-       public JComboBox<Key> keysigCombobox = new JComboBox<Key>() {
-               {
-                       for(int co5 = -Key.MAX_SHARPS_OR_FLATS ; co5 <= Key.MAX_SHARPS_OR_FLATS ; co5++)
-                               addItem(new Key(co5));
-                       setMaximumRowCount(getItemCount());
-               }
-       };
-       JCheckBox minorCheckbox = null;
-
+public class KeySignatureSelecter extends JPanel {
+       public KeySignatureComboBox getKeysigCombobox() { return keysigCombobox; }
+       protected KeySignatureComboBox keysigCombobox = new KeySignatureComboBox();
+       protected MinorCheckBox minorCheckbox = null;
        /**
         * 調性選択フォームを構築します。
         * 初期値としてメジャー・マイナーの区別がある調を指定した場合、
         * メジャー・マイナーを選択できるminorチェックボックス付きで構築されます。
-        * @param key 調の初期値
+        * @param defaultKey 調の初期値
         */
-       public KeySignatureSelecter(Key key) {
+       public KeySignatureSelecter(Key defaultKey) {
                add(new JLabel("Key:"));
                add(keysigCombobox);
-               if(key.majorMinor() != Key.MajorMinor.MAJOR_OR_MINOR) {
-                       add(minorCheckbox = new JCheckBox("minor"));
-                       minorCheckbox.addActionListener(this);
+               if(defaultKey.majorMinor() != Key.MajorMinor.MAJOR_OR_MINOR) {
+                       add(minorCheckbox = new MinorCheckBox());
                }
-               keysigCombobox.addActionListener(this);
-               setSelectedKey(key);
-       }
-
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               Key key = (Key)keysigCombobox.getSelectedItem();
-               keysigCombobox.setToolTipText(
-                       "Key: " + key.toStringIn( Note.Language.NAME )
-                       + " "  + key.toStringIn( Note.Language.IN_JAPANESE )
-                       + " (" + key.signatureDescription() + ")"
-               );
+               setSelectedKey(defaultKey);
        }
-
        /**
         * 調の選択を、引数で指定された通りに変更します。
         * メジャー・マイナーの区別のない調が指定された場合、
@@ -59,8 +34,7 @@ public class KeySignatureSelecter extends JPanel implements ActionListener {
         * @param key 選択する調
         */
        public void setSelectedKey(Key key) {
-               setMajorMinor(key.majorMinor());
-               if( key.majorMinor() != Key.MajorMinor.MAJOR_OR_MINOR ) key = new Key(key.toCo5());
+               if( minorCheckbox != null ) minorCheckbox.setMajorMinor(key.majorMinor());
                keysigCombobox.setSelectedItem(key);
        }
        /**
@@ -70,16 +44,8 @@ public class KeySignatureSelecter extends JPanel implements ActionListener {
         * @return 選択されている調
         */
        public Key getSelectedKey() {
-               Key key = (Key)keysigCombobox.getSelectedItem();
-               return minorCheckbox == null ? key : new Key(key.toCo5(), getMajorMinor());
-       }
-
-       private void setMajorMinor(Key.MajorMinor majorMinor) {
-               if( minorCheckbox == null || majorMinor == Key.MajorMinor.MAJOR_OR_MINOR ) return;
-               minorCheckbox.setSelected(majorMinor == Key.MajorMinor.MINOR);
-       }
-       private Key.MajorMinor getMajorMinor() {
-               return minorCheckbox == null ? Key.MajorMinor.MAJOR_OR_MINOR :
-                       minorCheckbox.isSelected() ? Key.MajorMinor.MINOR : Key.MajorMinor.MAJOR;
+               Key key = (Key) keysigCombobox.getSelectedItem();
+               if( minorCheckbox == null ) return key;
+               return new Key(key.toCo5(), minorCheckbox.getMajorMinor());
        }
-}
\ No newline at end of file
+}
index 6c54d18..fc1b8af 100644 (file)
@@ -235,9 +235,6 @@ public class MidiMessageForm extends JPanel implements ActionListener {
         * 調号選択
         */
        private KeySignatureSelecter keysigSelecter = new KeySignatureSelecter(new Key("C")) {
-               private void update() {
-                       dataText.setValue(getSelectedKey().getBytes());
-               }
                {
                        keysigCombobox.addActionListener(new ActionListener() {
                                @Override
@@ -248,6 +245,7 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                                public void itemStateChanged(ItemEvent e) { update(); }
                        });
                }
+               private void update() { dataText.setValue(getSelectedKey().getBytes()); }
        };
 
        /**
diff --git a/src/camidion/chordhelper/midieditor/MinorCheckBox.java b/src/camidion/chordhelper/midieditor/MinorCheckBox.java
new file mode 100644 (file)
index 0000000..65fa907
--- /dev/null
@@ -0,0 +1,16 @@
+package camidion.chordhelper.midieditor;
+
+import javax.swing.JCheckBox;
+
+import camidion.chordhelper.music.Key;
+
+public class MinorCheckBox extends JCheckBox {
+       public MinorCheckBox() { super("minor"); }
+       public void setMajorMinor(Key.MajorMinor majorMinor) {
+               if( majorMinor == Key.MajorMinor.MAJOR_OR_MINOR ) return;
+               setSelected( majorMinor == Key.MajorMinor.MINOR );
+       }
+       public Key.MajorMinor getMajorMinor() {
+               return isSelected() ? Key.MajorMinor.MINOR : Key.MajorMinor.MAJOR;
+       }
+}
index 7240b3c..8f0a39b 100644 (file)
@@ -6,11 +6,10 @@ package camidion.chordhelper.music;
  *
  * <p>内部的には次の値を持っています。</p>
  * <ul>
- * <li>五度圏インデックス値。これは調号の♯の数(♭の数は負数)と同じです。</li>
+ * <li>五度圏インデックス値。この値は調号の♯の数(♭の数は負数)と同じで、
+ * MIDIメタメッセージの調号パラメータと互換性があります。</li>
  * <li>メジャー/マイナーの区別、区別なしの3値({@link MajorMinor}で定義)</li>
  * </ul>
- * <p>これらの値はMIDIのメタメッセージにある調号のパラメータに対応します。
- * </p>
  */
 public class Key {
        /**
@@ -73,7 +72,7 @@ public class Key {
        /**
         * 指定の五度圏インデックス値を持つ、メジャー・マイナーの区別を指定した調を構築します。
         *
-        * @param co5 五度圏インデックス値
+        * @param co5 五度圏インデックス値(Index based Circle Of 5th)
         * @param majorMinor メジャー・マイナーの区別
         */
        public Key(int co5, MajorMinor majorMinor) {
index 853bdda..367b762 100644 (file)
@@ -1,7 +1,6 @@
 package camidion.chordhelper.pianokeyboard;
 
 import java.awt.Color;
-import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.nio.charset.Charset;
 
@@ -13,6 +12,7 @@ import javax.swing.JButton;
 import javax.swing.JPanel;
 
 import camidion.chordhelper.ChordDisplayLabel;
+import camidion.chordhelper.ChordHelperApplet;
 import camidion.chordhelper.chordmatrix.ChordMatrix;
 import camidion.chordhelper.mididevice.VirtualMidiDevice;
 import camidion.chordhelper.midieditor.KeySignatureSelecter;
@@ -36,25 +36,20 @@ public class MidiKeyboardPanel extends JPanel {
        MidiChannelButtonSelecter midiChannelButtons;
        VelocitySelecter velocitySelecter;
 
-       private static final Insets ZERO_INSETS = new Insets(0,0,0,0);
-
        public MidiKeyboardPanel(ChordMatrix chordMatrix) {
                keyboardCenterPanel = new PianoKeyboardPanel();
                keyboardCenterPanel.keyboard.chordMatrix = chordMatrix;
                keyboardCenterPanel.keyboard.chordDisplay =
-                       new ChordDisplayLabel(
-                               "MIDI Keyboard", chordMatrix, keyboardCenterPanel.keyboard
-                       );
-               //
-               setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
+                       new ChordDisplayLabel("MIDI Keyboard", chordMatrix, keyboardCenterPanel.keyboard);
+               setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                add(keyboardChordPanel = new JPanel() {
                        {
                                setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
-                               add( Box.createHorizontalStrut(5) );
+                               add(Box.createHorizontalStrut(5));
                                add(velocitySelecter = new VelocitySelecter(keyboardCenterPanel.keyboard.velocityModel));
                                add(keySelecter = new KeySignatureSelecter(Key.C_MAJOR_OR_A_MINOR));
-                               add( keyboardCenterPanel.keyboard.chordDisplay );
-                               add( Box.createHorizontalStrut(5) );
+                               add(keyboardCenterPanel.keyboard.chordDisplay);
+                               add(Box.createHorizontalStrut(5));
                        }
                });
                add(keyboardCenterPanel);
@@ -86,7 +81,7 @@ public class MidiKeyboardPanel extends JPanel {
                                        );
                                }
                        }) {
-                               { setMargin(ZERO_INSETS); }
+                               { setMargin(ChordHelperApplet.ZERO_INSETS); }
                        });
                }});
        }
@@ -101,7 +96,7 @@ public class MidiKeyboardPanel extends JPanel {
                midiChannelCombobox.setBackground(col);
                midiChannelCombobox.comboBox.setBackground(col);
                keySelecter.setBackground(col);
-               keySelecter.keysigCombobox.setBackground(col);
+               keySelecter.getKeysigCombobox().setBackground(col);
                velocitySelecter.setBackground(col);
                keyboardCenterPanel.keyboard.chordDisplay.setDarkMode(isDark);
                sendEventButton.setBackground(col);
index 9f39e53..f5c1f6b 100644 (file)
@@ -49,7 +49,7 @@ import camidion.chordhelper.music.Note;
  * Piano Keyboard class for MIDI Chord Helper
  *
  * @author
- *     Copyright (C) 2004-2013 Akiyoshi Kamide
+ *     Copyright (C) 2004-2017 Akiyoshi Kamide
  *     http://www.yk.rim.or.jp/~kamide/music/chordhelper/
  */
 public class PianoKeyboard extends JComponent {
@@ -60,7 +60,7 @@ public class PianoKeyboard extends JComponent {
        /**
         * 最大オクターブ幅(切り上げ)
         */
-       public static final int MAX_OCTAVE_WIDTH = MIDISpec.MAX_NOTE_NO / 12 + 1;
+       public static final int MAX_OCTAVE_WIDTH = MIDISpec.MAX_NOTE_NO / Note.SEMITONES_PER_OCTAVE + 1;
        /**
         * 濃いピンク
         */
@@ -112,11 +112,11 @@ public class PianoKeyboard extends JComponent {
        /**
         * 調号(スケール判定用)
         */
-       private Key     keySignature = null;
+       private Key keySignature = null;
        /**
         * 表示中のコード
         */
-       private Chord   chord = null;
+       private Chord chord = null;
        /**
         * コードボタンマトリクス
         */
@@ -167,19 +167,12 @@ public class PianoKeyboard extends JComponent {
                @Override
                public void noteOff(int noteNumber) {
                        keyOff( channel, noteNumber );
-                       if( chordMatrix != null ) {
-                               if( ! isRhythmPart() )
-                                       chordMatrix.note(false, noteNumber);
-                       }
-                       if( midiChannelButtonSelecter != null ) {
-                               midiChannelButtonSelecter.repaint();
-                       }
+                       if(chordMatrix != null && ! isRhythmPart()) chordMatrix.note(false, noteNumber);
+                       if(midiChannelButtonSelecter != null) midiChannelButtonSelecter.repaint();
                }
                @Override
                public void noteOn(int noteNumber, int velocity) {
-                       if( velocity <= 0 ) {
-                               noteOff(noteNumber); return;
-                       }
+                       if( velocity <= 0 ) { noteOff(noteNumber); return; }
                        keyOn( channel, noteNumber );
                        if( midiChComboboxModel.getSelectedChannel() == channel ) {
                                if( chordDisplay != null ) {
@@ -194,19 +187,13 @@ public class PianoKeyboard extends JComponent {
                                                anoGakkiPane.start(PianoKeyboard.this, pienoKey.indicator);
                                }
                        }
-                       if( chordMatrix != null ) {
-                               if( ! isRhythmPart() )
-                                       chordMatrix.note(true, noteNumber);
-                       }
-                       if( midiChannelButtonSelecter != null ) {
-                               midiChannelButtonSelecter.repaint();
-                       }
+                       if(chordMatrix != null && ! isRhythmPart()) chordMatrix.note(true, noteNumber);
+                       if(midiChannelButtonSelecter != null) midiChannelButtonSelecter.repaint();
                }
                @Override
                public void allNotesOff() {
                        allKeysOff( channel, -1 );
-                       if( chordMatrix != null )
-                               chordMatrix.clearIndicators();
+                       if( chordMatrix != null ) chordMatrix.clearIndicators();
                }
                @Override
                public void setPitchBend(int bend) {
@@ -236,12 +223,9 @@ public class PianoKeyboard extends JComponent {
                        }
                }
                private void repaintNotes() {
-                       if( midiChComboboxModel.getSelectedChannel() != channel
-                               || channelNotes[channel] == null
-                       )
-                               return;
-                       if( channelNotes[channel].size() > 0 || selectedKeyNoteList.size() > 0 )
-                               repaint();
+                       if(midiChComboboxModel.getSelectedChannel() != channel) return;
+                       if(channelNotes[channel] == null ) return;
+                       if(channelNotes[channel].size() > 0 || selectedKeyNoteList.size() > 0) repaint();
                }
        }
        /**
@@ -318,16 +302,14 @@ public class PianoKeyboard extends JComponent {
                }
                int getNote(int chromaticOffset) {
                        int n = position + chromaticOffset;
-                       return (outOfBounds = ( n > MIDISpec.MAX_NOTE_NO )) ? -1 : n;
+                       return (outOfBounds = (n > MIDISpec.MAX_NOTE_NO)) ? -1 : n;
                }
                boolean paintKey(Graphics2D g2, boolean isPressed) {
                        if(outOfBounds) return false;
                        g2.fill3DRect(x, y, width, height, !isPressed);
                        return true;
                }
-               boolean paintKey(Graphics2D g2) {
-                       return paintKey(g2,false);
-               }
+               boolean paintKey(Graphics2D g2) { return paintKey(g2,false); }
                boolean paintKeyBinding(Graphics2D g2) {
                        if( bindedKeyChar == null ) return false;
                        g2.drawString( bindedKeyChar, x + width/3, indicator.y - 2 );
@@ -363,22 +345,16 @@ public class PianoKeyboard extends JComponent {
                        return true;
                }
                boolean paintIndicator(Graphics2D g2, boolean is_small) {
-                       return paintIndicator( g2, is_small, 0 );
+                       return paintIndicator(g2, is_small, 0);
                }
        }
 
-       private class MouseKeyListener
-               implements MouseListener, MouseMotionListener, KeyListener
-       {
+       private class MouseKeyListener implements MouseListener, MouseMotionListener, KeyListener {
                private void pressed(int c, int n, InputEvent e) {
-                       keyOn(c,n);
-                       noteOn(n);
-                       firePianoKeyPressed(n,e);
+                       keyOn(c,n); noteOn(n); firePianoKeyPressed(n,e);
                }
                private void released(int c, int n, InputEvent e) {
-                       keyOff(c,n);
-                       noteOff(n);
-                       firePianoKeyReleased(n,e);
+                       keyOff(c,n); noteOff(n); firePianoKeyReleased(n,e);
                }
                @Override
                public void mousePressed(MouseEvent e) {
@@ -395,15 +371,12 @@ public class PianoKeyboard extends JComponent {
                public void mouseReleased(MouseEvent e) {
                        int c = midiChComboboxModel.getSelectedChannel();
                        NoteList nl = channelNotes[c];
-                       if( ! nl.isEmpty() )
-                               released(c, nl.poll(), e);
+                       if( ! nl.isEmpty() ) released(c, nl.poll(), e);
                }
                @Override
-               public void mouseEntered(MouseEvent e) {
-               }
+               public void mouseEntered(MouseEvent e) { }
                @Override
-               public void mouseExited(MouseEvent e) {
-               }
+               public void mouseExited(MouseEvent e) { }
                @Override
                public void mouseDragged(MouseEvent e) {
                        int n = getNote(e.getPoint());
@@ -411,16 +384,13 @@ public class PianoKeyboard extends JComponent {
                        int c = midiChComboboxModel.getSelectedChannel();
                        NoteList nl = channelNotes[c];
                        if( nl.contains(n) ) return;
-                       if( ! nl.isEmpty() )
-                               released(c, nl.poll(), e);
+                       if( ! nl.isEmpty() ) released(c, nl.poll(), e);
                        pressed(c,n,e);
                }
                @Override
-               public void mouseMoved(MouseEvent e) {
-               }
+               public void mouseMoved(MouseEvent e) { }
                @Override
-               public void mouseClicked(MouseEvent e) {
-               }
+               public void mouseClicked(MouseEvent e) { }
                @Override
                public void keyPressed(KeyEvent e) {
                        int kc = e.getKeyCode();
@@ -446,8 +416,7 @@ public class PianoKeyboard extends JComponent {
                        released(c,n,e);
                }
                @Override
-               public void keyTyped(KeyEvent e) {
-               }
+               public void keyTyped(KeyEvent e) { }
        }
 
        /**
@@ -465,16 +434,16 @@ public class PianoKeyboard extends JComponent {
                addMouseMotionListener(mkl);
                addKeyListener(mkl);
                int octaves = getPerferredOctaves();
-               octaveSizeModel = new DefaultBoundedRangeModel(
-                       octaves, 0, MIN_OCTAVE_WIDTH, MAX_OCTAVE_WIDTH
-               ) {{
-                       addChangeListener(new ChangeListener() {
-                               public void stateChanged(ChangeEvent e) {
-                                       fireOctaveResized(e);
-                                       octaveSizeChanged();
-                               }
-                       });
-               }};
+               octaveSizeModel = new DefaultBoundedRangeModel(octaves, 0, MIN_OCTAVE_WIDTH, MAX_OCTAVE_WIDTH) {
+                       {
+                               addChangeListener(new ChangeListener() {
+                                       public void stateChanged(ChangeEvent e) {
+                                               fireOctaveResized(e);
+                                               octaveSizeChanged();
+                                       }
+                               });
+                       }
+               };
                octaveRangeModel = new DefaultBoundedRangeModel(
                        (MAX_OCTAVE_WIDTH - octaves) / 2, octaves, 0, MAX_OCTAVE_WIDTH
                ) {{
@@ -497,8 +466,7 @@ public class PianoKeyboard extends JComponent {
                        new ListDataListener() {
                                public void contentsChanged(ListDataEvent e) {
                                        int c = midiChComboboxModel.getSelectedChannel();
-                                       for( int n : channelNotes[c] )
-                                               if( autoScroll(n) ) break;
+                                       for( int n : channelNotes[c] ) if( autoScroll(n) ) break;
                                        repaint();
                                }
                                public void intervalAdded(ListDataEvent e) {}
@@ -507,59 +475,63 @@ public class PianoKeyboard extends JComponent {
                );
        }
        public void paint(Graphics g) {
-               if( keys == null ) return;
+               if(keys == null) return;
                Graphics2D g2 = (Graphics2D) g;
                Dimension d = getSize();
                //
-               // 鍵盤をクリア
-               g2.setBackground( getBackground() );
-               g2.clearRect( 0, 0, d.width, d.height );
+               // 鍵盤をクリアし、順次塗り重ねていく
+               g2.setBackground(getBackground());
+               g2.clearRect(0, 0, d.width, d.height);
                //
-               // 白鍵を描画
-               g2.setColor( isDark ? Color.gray : Color.white );
-               for( PianoKey k : whiteKeys ) k.paintKey(g2);
-
+               // 白鍵
+               g2.setColor(isDark ? Color.gray : Color.white);
+               for(PianoKey k : whiteKeys) k.paintKey(g2);
+               //
+               // 選択マーク●をつける鍵と、ノートオン状態の鍵をリストアップ
                NoteList notesArray[] = {
                        (NoteList)selectedKeyNoteList.clone(),
                        (NoteList)channelNotes[midiChComboboxModel.getSelectedChannel()].clone()
                };
-               PianoKey key;
-               //
-               // ノートオン状態の白鍵を塗り重ねる
-               for( int n : notesArray[1] )
-                       if( (key=getPianoKey(n)) != null && !(key.isBlack) )
-                               key.paintKey(g2,true);
-               //
-               // 黒鍵を描画
-               g2.setColor(getForeground());
-               for( PianoKey k : blackKeys ) k.paintKey(g2);
+               // ノートオン状態の白鍵
+               for(int n : notesArray[1]) {
+                       PianoKey k = getPianoKey(n);
+                       if( k == null || k.isBlack ) continue;
+                       k.paintKey(g2,true);
+               }
+               // 黒鍵
+               g2.setColor(getForeground()); for(PianoKey k : blackKeys) k.paintKey(g2);
                //
-               // ノートオン状態の黒鍵を塗り重ねる
-               g2.setColor( Color.gray );
-               for( int n : notesArray[1] )
-                       if( (key=getPianoKey(n)) != null && key.isBlack )
-                               key.paintKey(g2,true);
-               //
-               // インジケータの表示
-               for( NoteList nl : notesArray ) {
+               // ノートオン状態の黒鍵
+               g2.setColor(Color.gray);
+               for(int n : notesArray[1]) {
+                       PianoKey k = getPianoKey(n);
+                       if( k == null || ! k.isBlack ) continue;
+                       k.paintKey(g2,true);
+               }
+               // インジケータ
+               for(NoteList nl : notesArray) {
                        if( nl == null ) continue;
-                       for( Integer ni : nl ) {
+                       for(Integer ni : nl) {
                                if( ni == null ) continue;
                                int n = ni;
-                               if( (key=getPianoKey(n)) == null ) continue;
+                               PianoKey k = getPianoKey(n);
+                               if( k == null ) continue;
                                boolean isOnScale = (keySignature == null || keySignature.isOnScale(n));
                                int chordIndex;
                                if( chord != null && (chordIndex = chord.indexOf(n)) >=0 ) {
+                                       // コードを鳴らした直後は、その構成音に色を付ける
                                        g2.setColor(Chord.NOTE_INDEX_COLORS[chordIndex]);
                                }
                                else {
                                        g2.setColor(isDark && isOnScale ? Color.pink : DARK_PINK);
                                }
+                               // ●を表示(ピッチベンドしていたら引き伸ばす)
                                int c = midiChComboboxModel.getSelectedChannel();
-                               key.paintIndicator(g2, false, pitchBendValues[c]);
+                               k.paintIndicator(g2, false, pitchBendValues[c]);
                                if( ! isOnScale ) {
+                                       // スケールを外れた音は白抜き
                                        g2.setColor(Color.white);
-                                       key.paintIndicator(g2, true);
+                                       k.paintIndicator(g2, true);
                                }
                        }
                }
@@ -575,7 +547,6 @@ public class PianoKeyboard extends JComponent {
                        }
                }
        }
-       //
        protected void firePianoKeyPressed(int note_no, InputEvent event) {
                Object[] listeners = listenerList.getListenerList();
                for (int i = listeners.length-2; i>=0; i-=2) {
@@ -637,20 +608,16 @@ public class PianoKeyboard extends JComponent {
                int indexOctave = indexWhite / 7;
                int i = (indexWhite -= indexOctave * 7) * 2 + indexOctave * 12;
                if( indexWhite >= 3 ) i--;
-               if( i < 0 || i > keys.length-1 )
-                       return null;
-               if( point.y > blackKeySize.height )
-                       return keys[i];
+               if( i < 0 || i > keys.length-1 ) return null;
+               if( point.y > blackKeySize.height ) return keys[i];
                PianoKey k;
                if( i > 0 ) {
                        k = keys[i-1];
-                       if( k.isBlack && !(k.outOfBounds) && k.contains(point) )
-                               return k;
+                       if( k.isBlack && !(k.outOfBounds) && k.contains(point) ) return k;
                }
                if( i < keys.length-1 ) {
                        k = keys[i+1];
-                       if( k.isBlack && !(k.outOfBounds) && k.contains(point) )
-                               return k;
+                       if( k.isBlack && !(k.outOfBounds) && k.contains(point) ) return k;
                }
                return keys[i];
        }
@@ -678,14 +645,12 @@ public class PianoKeyboard extends JComponent {
        }
 
        private void checkOutOfBounds() {
-               if( keys == null ) return;
-               for( PianoKey k : keys ) k.getNote(getChromaticOffset());
+               if(keys != null) for(PianoKey k : keys) k.getNote(getChromaticOffset());
        }
        private void keyOff(int ch, int noteNumber) {
                if( noteNumber < 0 || ch < 0 || ch >= channelNotes.length ) return;
                channelNotes[ch].remove((Object)noteNumber);
-               if( ch == midiChComboboxModel.getSelectedChannel() )
-                       repaint();
+               if( ch == midiChComboboxModel.getSelectedChannel() ) repaint();
        }
        private void keyOn(int ch, int noteNumber) {
                if( noteNumber < 0 || ch < 0 || ch >= channelNotes.length ) return;
@@ -697,15 +662,11 @@ public class PianoKeyboard extends JComponent {
                        return false;
                int i = noteNumber - getChromaticOffset();
                if( i < 0 ) {
-                       octaveRangeModel.setValue(
-                               octaveRangeModel.getValue() - (-i)/Note.SEMITONES_PER_OCTAVE - 1
-                       );
+                       octaveRangeModel.setValue(octaveRangeModel.getValue() - (-i)/Note.SEMITONES_PER_OCTAVE - 1);
                        return true;
                }
                if( i >= keys.length ) {
-                       octaveRangeModel.setValue(
-                               octaveRangeModel.getValue() + (i-keys.length)/Note.SEMITONES_PER_OCTAVE + 1
-                       );
+                       octaveRangeModel.setValue(octaveRangeModel.getValue() + (i-keys.length)/Note.SEMITONES_PER_OCTAVE + 1);
                        return true;
                }
                return false;
@@ -729,15 +690,12 @@ public class PianoKeyboard extends JComponent {
                        selectedKeyNoteList = (NoteList)(channelNotes[ch].clone());
                        break;
                case  1:
-                       selectedKeyNoteList.add(
-                               channelNotes[ch].get(channelNotes[ch].size()-1)
-                       );
+                       selectedKeyNoteList.add(channelNotes[ch].get(channelNotes[ch].size()-1));
                        break;
                default: break;
                }
                channelNotes[ch].clear();
-               if( midiChComboboxModel.getSelectedChannel() == ch )
-                       repaint();
+               if( midiChComboboxModel.getSelectedChannel() == ch ) repaint();
        }
        public void clear() {
                selectedKeyNoteList.clear();
@@ -750,9 +708,8 @@ public class PianoKeyboard extends JComponent {
                switch( channelNotes[current_channel].size() ) {
                case 1: return channelNotes[current_channel].get(0);
                case 0:
-                       if( selectedKeyNoteList.size() == 1 )
-                               return selectedKeyNoteList.get(0);
-                       return -1;
+                       if( selectedKeyNoteList.size() == 1 ) return selectedKeyNoteList.get(0);
+                       // no break
                default:
                        return -1;
                }
@@ -761,12 +718,10 @@ public class PianoKeyboard extends JComponent {
                setSelectedNote(midiChComboboxModel.getSelectedChannel(), noteNumber);
        }
        void setSelectedNote(int ch, int note_no) {
-               if( ch != midiChComboboxModel.getSelectedChannel() )
-                       return;
+               if( ch != midiChComboboxModel.getSelectedChannel() ) return;
                selectedKeyNoteList.add(note_no);
                int maxSel = (chord == null ? maxSelectable : chord.numberOfNotes());
-               while( selectedKeyNoteList.size() > maxSel )
-                       selectedKeyNoteList.poll();
+               while(selectedKeyNoteList.size() > maxSel) selectedKeyNoteList.poll();
                if( !autoScroll(note_no) ) {
                        // When autoScroll() returned false, stateChanged() not invoked - need repaint()
                        repaint();
@@ -776,15 +731,10 @@ public class PianoKeyboard extends JComponent {
                return selectedKeyNoteList.toArray(new Integer[0]);
        }
        Chord getChord() { return chord; }
-       public void setChord(Chord c) {
-               chordDisplay.setChord(chord = c);
-       }
-       public void setKeySignature(Key ks) {
-               keySignature = ks;
-               repaint();
-       }
+       public void setChord(Chord c) { chordDisplay.setChord(chord = c); }
+       public void setKeySignature(Key ks) { keySignature = ks; repaint(); }
        private int     maxSelectable = 1;
-       public void setMaxSelectable( int maxSelectable ) {
+       public void setMaxSelectable(int maxSelectable) {
                this.maxSelectable = maxSelectable;
        }
        int getMaxSelectable() { return maxSelectable; }
@@ -794,21 +744,15 @@ public class PianoKeyboard extends JComponent {
        public int getOctaves() { return octaveSizeModel.getValue(); }
        private int getPerferredOctaves() {
                int octaves = Math.round( (float)getWidth() / WIDTH_PER_OCTAVE );
-               if( octaves > MAX_OCTAVE_WIDTH ) {
-                       octaves = MAX_OCTAVE_WIDTH;
-               }
-               else if( octaves < MIN_OCTAVE_WIDTH ) {
-                       octaves = MIN_OCTAVE_WIDTH;
-               }
+               if( octaves > MAX_OCTAVE_WIDTH ) octaves = MAX_OCTAVE_WIDTH;
+               else if( octaves < MIN_OCTAVE_WIDTH ) octaves = MIN_OCTAVE_WIDTH;
                return octaves;
        }
        private void octaveSizeChanged() {
                int octaves = octaveSizeModel.getValue();
                String defaultBindedKeyChars = "zsxdcvgbhnjm,l.;/\\]";
                Dimension keyboard_size = getSize();
-               if( keyboard_size.width == 0 ) {
-                       return;
-               }
+               if( keyboard_size.width == 0 ) return;
                whiteKeySize = new Dimension(
                        (keyboard_size.width - 1) / (octaves * 7 + 1),
                        keyboard_size.height - 1
@@ -833,24 +777,21 @@ public class PianoKeyboard extends JComponent {
                Point keyPoint = new Point(1,1);
                PianoKey k;
                int i, i12;
-               boolean is_CDE = true;
+               boolean isCDE = true;
                for( i = i12 = 0; i < keys.length; i++, i12++ ) {
                        switch(i12) {
-                       case 12: is_CDE = true; i12 = 0; break;
-                       case  5: is_CDE = false; break;
+                       case 12: isCDE = true; i12 = 0; break;
+                       case  5: isCDE = false; break;
                        default: break;
                        }
-                       keyPoint.x = whiteKeySize.width * (
-                               i / Note.SEMITONES_PER_OCTAVE * 7 + (i12+(is_CDE?1:2))/2
-                       );
+                       keyPoint.x = whiteKeySize.width * ( i / Note.SEMITONES_PER_OCTAVE * 7 + (i12+(isCDE?1:2))/2 );
                        if( Key.C_MAJOR_OR_A_MINOR.isOnScale(i12) ) {
-                               k = new PianoKey( keyPoint, whiteKeySize, indicatorSize );
+                               k = new PianoKey(keyPoint, whiteKeySize, indicatorSize);
                                k.isBlack = false;
                                vWhiteKeys.add(k);
-                       }
-                       else {
-                               keyPoint.x -= ( (is_CDE?5:12) - i12 )/2 * blackKeySize.width / (is_CDE?3:4);
-                               k = new PianoKey( keyPoint, blackKeySize, indicatorSize );
+                       } else {
+                               keyPoint.x -= ( (isCDE?5:12) - i12 )/2 * blackKeySize.width / (isCDE?3:4);
+                               k = new PianoKey(keyPoint, blackKeySize, indicatorSize);
                                k.isBlack = true;
                                vBlackKeys.add(k);
                        }
@@ -858,12 +799,12 @@ public class PianoKeyboard extends JComponent {
                }
                whiteKeys = vWhiteKeys.toArray(new PianoKey[1]);
                blackKeys = vBlackKeys.toArray(new PianoKey[1]);
-               changeKeyBinding(((octaves - 1) / 2) * 12, defaultBindedKeyChars);
+               changeKeyBinding( ((octaves - 1) / 2) * 12, defaultBindedKeyChars );
                checkOutOfBounds();
        }
        //
        void setDarkMode(boolean isDark) {
                this.isDark = isDark;
-               setBackground( isDark ? Color.black : null );
+               setBackground(isDark ? Color.black : null);
        }
 }
index a0b0db0..771e84f 100644 (file)
@@ -57,9 +57,9 @@ public class PianoKeyboardPanel extends JPanel {
        private JPanel octaveBar;
        public void setDarkMode(boolean isDark) {
                Color col = isDark ? Color.black : null;
-               octaveSelecter.setBackground( col );
-               octaveSizeSlider.setBackground( col );
-               octaveBar.setBackground( col );
-               keyboard.setDarkMode( isDark );
+               octaveSelecter.setBackground(col);
+               octaveSizeSlider.setBackground(col);
+               octaveBar.setBackground(col);
+               keyboard.setDarkMode(isDark);
        }
 }
\ No newline at end of file