OSDN Git Service

27d7f69c1af0cbbd8f8d549d5007669132b1b466
[midichordhelper/MIDIChordHelper.git] / src / camidion / chordhelper / pianokeyboard / MidiKeyboardPanel.java
1 package camidion.chordhelper.pianokeyboard;
2
3 import java.awt.Color;
4 import java.awt.Insets;
5 import java.awt.event.ActionEvent;
6 import java.nio.charset.Charset;
7
8 import javax.sound.midi.MidiMessage;
9 import javax.swing.AbstractAction;
10 import javax.swing.Box;
11 import javax.swing.BoxLayout;
12 import javax.swing.JButton;
13 import javax.swing.JPanel;
14
15 import camidion.chordhelper.ChordDisplayLabel;
16 import camidion.chordhelper.chordmatrix.ChordMatrix;
17 import camidion.chordhelper.mididevice.VirtualMidiDevice;
18 import camidion.chordhelper.midieditor.KeySignatureSelecter;
19 import camidion.chordhelper.midieditor.MidiChannelButtonSelecter;
20 import camidion.chordhelper.midieditor.MidiChannelComboSelecter;
21 import camidion.chordhelper.midieditor.MidiEventDialog;
22 import camidion.chordhelper.midieditor.VelocitySelecter;
23 import camidion.chordhelper.music.Key;
24
25 public class MidiKeyboardPanel extends JPanel {
26         private MidiEventDialog eventDialog;
27         public void setEventDialog(MidiEventDialog eventDialog) {
28                 this.eventDialog = eventDialog;
29         }
30         JButton sendEventButton;
31         JPanel keyboardChordPanel;
32         JPanel keyboardSouthPanel;
33         public KeySignatureSelecter keySelecter;
34         public PianoKeyboardPanel keyboardCenterPanel;
35         MidiChannelComboSelecter midiChannelCombobox;
36         MidiChannelButtonSelecter midiChannelButtons;
37         VelocitySelecter velocitySelecter;
38
39         private static final Insets ZERO_INSETS = new Insets(0,0,0,0);
40
41         public MidiKeyboardPanel(ChordMatrix chordMatrix) {
42                 keyboardCenterPanel = new PianoKeyboardPanel();
43                 keyboardCenterPanel.keyboard.chordMatrix = chordMatrix;
44                 keyboardCenterPanel.keyboard.chordDisplay =
45                         new ChordDisplayLabel(
46                                 "MIDI Keyboard", chordMatrix, keyboardCenterPanel.keyboard
47                         );
48                 //
49                 setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
50                 add(keyboardChordPanel = new JPanel() {
51                         {
52                                 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
53                                 add( Box.createHorizontalStrut(5) );
54                                 add(velocitySelecter = new VelocitySelecter(keyboardCenterPanel.keyboard.velocityModel));
55                                 add(keySelecter = new KeySignatureSelecter(new Key()));
56                                 add( keyboardCenterPanel.keyboard.chordDisplay );
57                                 add( Box.createHorizontalStrut(5) );
58                         }
59                 });
60                 add(keyboardCenterPanel);
61                 add(Box.createVerticalStrut(5));
62                 add(keyboardSouthPanel = new JPanel() {{
63                         setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
64                         add(midiChannelCombobox = new MidiChannelComboSelecter(
65                                 "MIDI Channel", keyboardCenterPanel.keyboard.midiChComboboxModel
66                         ));
67                         add(midiChannelButtons = new MidiChannelButtonSelecter(
68                                 keyboardCenterPanel.keyboard
69                         ));
70                         add(sendEventButton = new JButton(new AbstractAction() {
71                                 { putValue(NAME,"Send MIDI event"); }
72                                 @Override
73                                 public void actionPerformed(ActionEvent e) {
74                                         eventDialog.openMessageForm(
75                                                 "Send MIDI event",
76                                                 new AbstractAction() {
77                                                         { putValue(NAME,"Send"); }
78                                                         @Override
79                                                         public void actionPerformed(ActionEvent e) {
80                                                                 VirtualMidiDevice vmd = keyboardCenterPanel.keyboard.midiDevice;
81                                                                 MidiMessage msg = eventDialog.midiMessageForm.getMessage(Charset.defaultCharset());
82                                                                 vmd.sendMidiMessage(msg);
83                                                         }
84                                                 },
85                                                 keyboardCenterPanel.keyboard.midiChComboboxModel.getSelectedChannel()
86                                         );
87                                 }
88                         }) {
89                                 { setMargin(ZERO_INSETS); }
90                         });
91                 }});
92         }
93
94         public void setDarkMode(boolean isDark) {
95                 Color col = isDark ? Color.black : null;
96                 setBackground(col);
97                 keyboardCenterPanel.setDarkMode(isDark);
98                 keyboardChordPanel.setBackground(col);
99                 keyboardSouthPanel.setBackground(col);
100                 midiChannelButtons.setBackground(col);
101                 midiChannelCombobox.setBackground(col);
102                 midiChannelCombobox.comboBox.setBackground(col);
103                 keySelecter.setBackground(col);
104                 keySelecter.keysigCombobox.setBackground(col);
105                 velocitySelecter.setBackground(col);
106                 keyboardCenterPanel.keyboard.chordDisplay.setDarkMode(isDark);
107                 sendEventButton.setBackground(col);
108         }
109
110 }