OSDN Git Service

d49f029e3179b30f7ce5b06a443fc5c4bb3bef96
[midichordhelper/MIDIChordHelper.git] / src / camidion / chordhelper / pianokeyboard / MidiKeyboardPanel.java
1 package camidion.chordhelper.pianokeyboard;
2
3 import java.awt.Color;
4 import java.awt.event.ActionEvent;
5 import java.nio.charset.Charset;
6
7 import javax.sound.midi.MidiMessage;
8 import javax.swing.AbstractAction;
9 import javax.swing.Box;
10 import javax.swing.BoxLayout;
11 import javax.swing.JButton;
12 import javax.swing.JPanel;
13
14 import camidion.chordhelper.ChordDisplayLabel;
15 import camidion.chordhelper.ChordHelperApplet;
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         public MidiKeyboardPanel(ChordMatrix chordMatrix) {
40                 keyboardCenterPanel = new PianoKeyboardPanel();
41                 keyboardCenterPanel.keyboard.chordMatrix = chordMatrix;
42                 keyboardCenterPanel.keyboard.chordDisplay =
43                         new ChordDisplayLabel("MIDI Keyboard", null, chordMatrix, keyboardCenterPanel.keyboard);
44                 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
45                 add(keyboardChordPanel = new JPanel() {
46                         {
47                                 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
48                                 add(Box.createHorizontalStrut(5));
49                                 add(velocitySelecter = new VelocitySelecter(keyboardCenterPanel.keyboard.velocityModel));
50                                 add(keySelecter = new KeySignatureSelecter(Key.C_MAJOR_OR_A_MINOR));
51                                 add(keyboardCenterPanel.keyboard.chordDisplay);
52                                 add(Box.createHorizontalStrut(5));
53                         }
54                 });
55                 add(keyboardCenterPanel);
56                 add(Box.createVerticalStrut(5));
57                 add(keyboardSouthPanel = new JPanel() {{
58                         setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
59                         add(midiChannelCombobox = new MidiChannelComboSelecter(
60                                 "MIDI Channel", keyboardCenterPanel.keyboard.midiChComboboxModel
61                         ));
62                         add(midiChannelButtons = new MidiChannelButtonSelecter(
63                                 keyboardCenterPanel.keyboard
64                         ));
65                         add(sendEventButton = new JButton(new AbstractAction() {
66                                 { putValue(NAME,"Send MIDI event"); }
67                                 @Override
68                                 public void actionPerformed(ActionEvent e) {
69                                         eventDialog.openMessageForm(
70                                                 "Send MIDI event",
71                                                 new AbstractAction() {
72                                                         { putValue(NAME,"Send"); }
73                                                         @Override
74                                                         public void actionPerformed(ActionEvent e) {
75                                                                 VirtualMidiDevice vmd = keyboardCenterPanel.keyboard.midiDevice;
76                                                                 MidiMessage msg = eventDialog.midiMessageForm.getMessage(Charset.defaultCharset());
77                                                                 vmd.sendMidiMessage(msg);
78                                                         }
79                                                 },
80                                                 keyboardCenterPanel.keyboard.midiChComboboxModel.getSelectedChannel()
81                                         );
82                                 }
83                         }) {
84                                 { setMargin(ChordHelperApplet.ZERO_INSETS); }
85                         });
86                 }});
87         }
88
89         public void setDarkMode(boolean isDark) {
90                 Color col = isDark ? Color.black : null;
91                 setBackground(col);
92                 keyboardCenterPanel.setDarkMode(isDark);
93                 keyboardChordPanel.setBackground(col);
94                 keyboardSouthPanel.setBackground(col);
95                 midiChannelButtons.setBackground(col);
96                 midiChannelCombobox.setBackground(col);
97                 midiChannelCombobox.comboBox.setBackground(col);
98                 keySelecter.setBackground(col);
99                 keySelecter.getKeysigCombobox().setBackground(col);
100                 velocitySelecter.setBackground(col);
101                 keyboardCenterPanel.keyboard.chordDisplay.setDarkMode(isDark);
102                 sendEventButton.setBackground(col);
103         }
104
105 }