1 package camidion.chordhelper.pianokeyboard;
4 import java.awt.Insets;
5 import java.awt.event.ActionEvent;
6 import java.nio.charset.Charset;
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;
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;
24 public class MidiKeyboardPanel extends JPanel {
25 private MidiEventDialog eventDialog;
26 public void setEventDialog(MidiEventDialog eventDialog) {
27 this.eventDialog = eventDialog;
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;
38 private static final Insets ZERO_INSETS = new Insets(0,0,0,0);
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
48 setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
49 add(keyboardChordPanel = new JPanel() {
51 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
52 add( Box.createHorizontalStrut(5) );
53 add(velocitySelecter = new VelocitySelecter(
54 keyboardCenterPanel.keyboard.velocityModel)
56 add(keySelecter = new KeySignatureSelecter(false));
57 add( keyboardCenterPanel.keyboard.chordDisplay );
58 add( Box.createHorizontalStrut(5) );
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
68 add(midiChannelButtons = new MidiChannelButtonSelecter(
69 keyboardCenterPanel.keyboard
71 add(sendEventButton = new JButton(new AbstractAction() {
72 { putValue(NAME,"Send MIDI event"); }
74 public void actionPerformed(ActionEvent e) {
75 eventDialog.openMessageForm(
77 new AbstractAction() {
78 { putValue(NAME,"Send"); }
80 public void actionPerformed(ActionEvent e) {
81 VirtualMidiDevice vmd = keyboardCenterPanel.keyboard.midiDevice;
82 MidiMessage msg = eventDialog.midiMessageForm.getMessage(Charset.defaultCharset());
83 vmd.sendMidiMessage(msg);
86 keyboardCenterPanel.keyboard.midiChComboboxModel.getSelectedChannel()
90 { setMargin(ZERO_INSETS); }
95 public void setDarkMode(boolean isDark) {
96 Color col = isDark ? Color.black : null;
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);