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;
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 private static final Insets ZERO_INSETS = new Insets(0,0,0,0);
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
49 setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
50 add(keyboardChordPanel = new JPanel() {
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) );
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
67 add(midiChannelButtons = new MidiChannelButtonSelecter(
68 keyboardCenterPanel.keyboard
70 add(sendEventButton = new JButton(new AbstractAction() {
71 { putValue(NAME,"Send MIDI event"); }
73 public void actionPerformed(ActionEvent e) {
74 eventDialog.openMessageForm(
76 new AbstractAction() {
77 { putValue(NAME,"Send"); }
79 public void actionPerformed(ActionEvent e) {
80 VirtualMidiDevice vmd = keyboardCenterPanel.keyboard.midiDevice;
81 MidiMessage msg = eventDialog.midiMessageForm.getMessage(Charset.defaultCharset());
82 vmd.sendMidiMessage(msg);
85 keyboardCenterPanel.keyboard.midiChComboboxModel.getSelectedChannel()
89 { setMargin(ZERO_INSETS); }
94 public void setDarkMode(boolean isDark) {
95 Color col = isDark ? Color.black : null;
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);