1 package camidion.chordhelper.pianokeyboard;
4 import java.awt.event.ActionEvent;
5 import java.nio.charset.Charset;
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;
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;
25 public class MidiKeyboardPanel extends JPanel {
26 private MidiEventDialog eventDialog;
27 public void setEventDialog(MidiEventDialog eventDialog) {
28 this.eventDialog = eventDialog;
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;
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() {
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));
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
62 add(midiChannelButtons = new MidiChannelButtonSelecter(
63 keyboardCenterPanel.keyboard
65 add(sendEventButton = new JButton(new AbstractAction() {
66 { putValue(NAME,"Send MIDI event"); }
68 public void actionPerformed(ActionEvent e) {
69 eventDialog.openMessageForm(
71 new AbstractAction() {
72 { putValue(NAME,"Send"); }
74 public void actionPerformed(ActionEvent e) {
75 VirtualMidiDevice vmd = keyboardCenterPanel.keyboard.midiDevice;
76 MidiMessage msg = eventDialog.midiMessageForm.getMessage(Charset.defaultCharset());
77 vmd.sendMidiMessage(msg);
80 keyboardCenterPanel.keyboard.midiChComboboxModel.getSelectedChannel()
84 { setMargin(ChordHelperApplet.ZERO_INSETS); }
89 public void setDarkMode(boolean isDark) {
90 Color col = isDark ? Color.black : null;
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);