OSDN Git Service

397aae5c31c425a7c26241d0812b1eb10fb1768e
[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
24 public class MidiKeyboardPanel extends JPanel {
25         private MidiEventDialog eventDialog;
26         public void setEventDialog(MidiEventDialog eventDialog) {
27                 this.eventDialog = eventDialog;
28         }
29         JButton sendEventButton;
30         JPanel keyboardChordPanel;
31         JPanel keyboardSouthPanel;
32         public KeySignatureSelecter keySelecter;
33         public PianoKeyboardPanel keyboardCenterPanel;
34         MidiChannelComboSelecter midiChannelCombobox;
35         MidiChannelButtonSelecter midiChannelButtons;
36         VelocitySelecter velocitySelecter;
37
38         private static final Insets ZERO_INSETS = new Insets(0,0,0,0);
39
40         public MidiKeyboardPanel(ChordMatrix chordMatrix) {
41                 keyboardCenterPanel = new PianoKeyboardPanel();
42                 keyboardCenterPanel.keyboard.chordMatrix = chordMatrix;
43                 keyboardCenterPanel.keyboard.chordDisplay =
44                         new ChordDisplayLabel(
45                                 "MIDI Keyboard", chordMatrix, keyboardCenterPanel.keyboard
46                         );
47                 //
48                 setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
49                 add(keyboardChordPanel = new JPanel() {
50                         {
51                                 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
52                                 add( Box.createHorizontalStrut(5) );
53                                 add(velocitySelecter = new VelocitySelecter(
54                                         keyboardCenterPanel.keyboard.velocityModel)
55                                 );
56                                 add(keySelecter = new KeySignatureSelecter(false));
57                                 add( keyboardCenterPanel.keyboard.chordDisplay );
58                                 add( Box.createHorizontalStrut(5) );
59                         }
60                 });
61                 add(keyboardCenterPanel);
62                 add(Box.createVerticalStrut(5));
63                 add(keyboardSouthPanel = new JPanel() {{
64                         setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
65                         add(midiChannelCombobox = new MidiChannelComboSelecter(
66                                 "MIDI Channel", keyboardCenterPanel.keyboard.midiChComboboxModel
67                         ));
68                         add(midiChannelButtons = new MidiChannelButtonSelecter(
69                                 keyboardCenterPanel.keyboard
70                         ));
71                         add(sendEventButton = new JButton(new AbstractAction() {
72                                 { putValue(NAME,"Send MIDI event"); }
73                                 @Override
74                                 public void actionPerformed(ActionEvent e) {
75                                         eventDialog.openMessageForm(
76                                                 "Send MIDI event",
77                                                 new AbstractAction() {
78                                                         { putValue(NAME,"Send"); }
79                                                         @Override
80                                                         public void actionPerformed(ActionEvent e) {
81                                                                 VirtualMidiDevice vmd = keyboardCenterPanel.keyboard.midiDevice;
82                                                                 MidiMessage msg = eventDialog.midiMessageForm.getMessage(Charset.defaultCharset());
83                                                                 vmd.sendMidiMessage(msg);
84                                                         }
85                                                 },
86                                                 keyboardCenterPanel.keyboard.midiChComboboxModel.getSelectedChannel()
87                                         );
88                                 }
89                         }) {
90                                 { setMargin(ZERO_INSETS); }
91                         });
92                 }});
93         }
94
95         public void setDarkMode(boolean isDark) {
96                 Color col = isDark ? Color.black : null;
97                 setBackground(col);
98                 keyboardCenterPanel.setDarkMode(isDark);
99                 keyboardChordPanel.setBackground(col);
100                 keyboardSouthPanel.setBackground(col);
101                 midiChannelButtons.setBackground(col);
102                 midiChannelCombobox.setBackground(col);
103                 midiChannelCombobox.comboBox.setBackground(col);
104                 keySelecter.setBackground(col);
105                 keySelecter.keysigCombobox.setBackground(col);
106                 velocitySelecter.setBackground(col);
107                 keyboardCenterPanel.keyboard.chordDisplay.setDarkMode(isDark);
108                 sendEventButton.setBackground(col);
109         }
110
111 }