2 * Copyright (C) 2019 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <gtkmm/box.h>
22 #include "pbd/convert.h"
24 #include "ardour/async_midi_port.h"
25 #include "ardour/session.h"
27 #include "gtkmm2ext/utils.h"
28 #include "widgets/tooltips.h"
30 #include "ardour_ui.h"
31 #include "ui_config.h"
33 #include "virtual_keyboard_window.h"
39 using namespace ArdourWidgets;
41 #define PX_SCALE(px) std::max ((float)px, rintf ((float)px* UIConfiguration::instance ().get_ui_scale ()))
43 VirtualKeyboardWindow::VirtualKeyboardWindow ()
44 : ArdourWindow (_("Virtual MIDI Keyboard"))
45 , _bank_msb (*manage (new Adjustment (0, 0, 127, 1, 16)))
46 , _bank_lsb (*manage (new Adjustment (0, 0, 127, 1, 16)))
47 , _patchpgm (*manage (new Adjustment (1, 1, 128, 1, 16)))
48 , _cfg_display (S_("Virtual keyboard|Config"), ArdourButton::led_default_elements)
49 , _pgm_display (_("Bank/Patch"), ArdourButton::led_default_elements)
50 , _yaxis_velocity (_("Y-Axis"), ArdourButton::led_default_elements)
51 , _send_panic (_("Panic"), ArdourButton::default_elements)
52 , _piano_key_velocity (*manage (new Adjustment (100, 1, 127, 1, 16)))
53 , _piano_min_velocity (*manage (new Adjustment ( 1, 1, 127, 1, 16)))
54 , _piano_max_velocity (*manage (new Adjustment (127, 1, 127, 1, 16)))
55 , _piano_octave_key (*manage (new Adjustment (4, -1, 7, 1, 1)))
56 , _piano_octave_range (*manage (new Adjustment (7, 2, 11, 1, 1)))
57 , _pitch_adjustment (8192, 0, 16383, 1, 256)
59 _piano.set_flags (Gtk::CAN_FOCUS);
61 _piano.set_keyboard_layout (APianoKeyboard::S_QWERTY);
62 _piano.set_annotate_octave (true);
63 _piano.set_grand_piano_highlight (false);
64 _piano.set_annotate_layout (true);
65 _piano.set_annotate_octave (true);
67 for (int c = 0; c < 16; ++c) {
69 sprintf (buf, "%d", c + 1);
70 _midi_channel.append_text_item (buf);
72 for (int t = -12; t < 13; ++t) {
74 sprintf (buf, "%d", t);
75 _transpose_output.append_text_item (buf);
78 using namespace Menu_Helpers;
79 _keyboard_layout.AddMenuElem (MenuElem (_("QWERTY"), sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::select_keyboard_layout), "QWERTY")));
80 _keyboard_layout.AddMenuElem (MenuElem (_("QWERTZ"), sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::select_keyboard_layout), "QWERTZ")));
81 _keyboard_layout.AddMenuElem (MenuElem (_("AZERTY"), sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::select_keyboard_layout), "AZERTY")));
82 _keyboard_layout.AddMenuElem (MenuElem (_("DVORAK"), sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::select_keyboard_layout), "DVORAK")));
83 _keyboard_layout.AddMenuElem (MenuElem (_("QWERTY Single"), sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::select_keyboard_layout), "QWERTY Single")));
84 _keyboard_layout.AddMenuElem (MenuElem (_("QWERTZ Single"), sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::select_keyboard_layout), "QWERTZ Single")));
86 Gtkmm2ext::set_size_request_to_display_given_text_width (_keyboard_layout, _("QWERTZ Single"), 2, 0); // Longest Text
87 _keyboard_layout.set_active (_("QWERTY Single"));
88 _midi_channel.set_active ("1");
89 _transpose_output.set_active ("0");
91 _cfg_display.set_active (false);
92 _pgm_display.set_active (false);
93 _yaxis_velocity.set_active (false);
95 _send_panic.set_can_focus (false);
97 _pitchbend = boost::shared_ptr<VKBDControl> (new VKBDControl ("PB", 8192, 16383));
98 _pitch_slider = manage (new VSliderController (&_pitch_adjustment, _pitchbend, 0, PX_SCALE (15)));
99 _pitch_slider_tooltip = new Gtkmm2ext::PersistentTooltip (_pitch_slider);
101 _pitch_adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::pitch_slider_adjusted));
102 _pitchbend->ValueChanged.connect_same_thread (_cc_connections, boost::bind (&VirtualKeyboardWindow::pitch_bend_event_handler, this, _1));
104 set_tooltip (_yaxis_velocity, _("When enabled, mouse-click y-axis position defines the velocity."));
106 set_tooltip (_piano_octave_key, _("The center octave, and lowest octave for keyboard control. Change with Arrow left/right."));
107 set_tooltip (_piano_octave_range, _("Available octave range, centered around the key-octave."));
108 set_tooltip (_keyboard_layout, _("Keyboard layout to use for keyboard control."));
110 set_tooltip (_piano_key_velocity, _("The default velocity to use with keyboard control, and when y-axis click-position is disabled."));
111 set_tooltip (_piano_min_velocity, _("Velocity to use when clicking at the top-end of a key."));
112 set_tooltip (_piano_max_velocity, _("Velocity to use when clicking at the bottom-end of a key."));
114 set_tooltip (_send_panic, _("Send MIDI Panic message for current channel"));
116 _pitch_slider_tooltip->set_tip (_("Pitchbend: ") + std::string ("8192"));
117 _pitch_slider->set_can_focus (false);
120 Table* cfg_tbl = manage (new Table);
121 cfg_tbl->attach (_yaxis_velocity, 0, 1, 0, 1, SHRINK, SHRINK, 4, 0);
122 cfg_tbl->attach (*manage (new Label (_("Velocity:"))), 0, 1, 1, 2, SHRINK, SHRINK, 4, 0);
124 cfg_tbl->attach (_piano_min_velocity, 1, 2, 0, 1, SHRINK, SHRINK, 4, 0);
125 cfg_tbl->attach (*manage (new Label (_("Min"))), 1, 2, 1, 2, SHRINK, SHRINK, 4, 0);
126 cfg_tbl->attach (_piano_max_velocity, 2, 3, 0, 1, SHRINK, SHRINK, 4, 0);
127 cfg_tbl->attach (*manage (new Label (_("Max"))), 2, 3, 1, 2, SHRINK, SHRINK, 4, 0);
128 cfg_tbl->attach (_piano_key_velocity, 3, 4, 0, 1, SHRINK, SHRINK, 4, 0);
129 cfg_tbl->attach (*manage (new Label (_("Key"))), 3, 4, 1, 2, SHRINK, SHRINK, 4, 0);
131 cfg_tbl->attach (*manage (new ArdourVSpacer), 4, 5, 0, 2, SHRINK, FILL, 4, 0);
133 cfg_tbl->attach (_piano_octave_key, 5, 6, 0, 1, SHRINK, SHRINK, 4, 0);
134 cfg_tbl->attach (*manage (new Label (_("Octave"))), 5, 6, 1, 2, SHRINK, SHRINK, 4, 0);
135 cfg_tbl->attach (_piano_octave_range, 6, 7, 0, 1, SHRINK, SHRINK, 4, 0);
136 cfg_tbl->attach (*manage (new Label (_("Range"))), 6, 7, 1, 2, SHRINK, SHRINK, 4, 0);
138 cfg_tbl->attach (*manage (new ArdourVSpacer), 7, 8, 0, 2, SHRINK, FILL, 4, 0);
140 cfg_tbl->attach (_keyboard_layout, 8, 9, 0, 2, FILL, SHRINK, 4, 1);
141 cfg_tbl->show_all ();
144 Table* pgm_tbl = manage (new Table);
146 Label* lbl = manage (new Label (_("Note: Prefer\nTrack-controls")));
147 lbl->set_justify (JUSTIFY_CENTER);
149 pgm_tbl->attach (*lbl, 0, 1, 0, 2, SHRINK, SHRINK, 4, 0);
150 pgm_tbl->attach (*manage (new ArdourVSpacer), 1, 2, 0, 2, SHRINK, FILL, 4, 0);
151 pgm_tbl->attach (_bank_msb, 2, 3, 0, 1, SHRINK, SHRINK, 4, 0);
152 pgm_tbl->attach (_bank_lsb, 3, 4, 0, 1, SHRINK, SHRINK, 4, 0);
153 pgm_tbl->attach (_patchpgm, 4, 5, 0, 1, SHRINK, SHRINK, 4, 0);
154 pgm_tbl->attach (*manage (new Label (_("MSB"))), 2, 3, 1, 2, SHRINK, SHRINK, 4, 0);
155 pgm_tbl->attach (*manage (new Label (_("LSB"))), 3, 4, 1, 2, SHRINK, SHRINK, 4, 0);
156 pgm_tbl->attach (*manage (new Label (_("PGM"))), 4, 5, 1, 2, SHRINK, SHRINK, 4, 0);
157 pgm_tbl->attach (*manage (new ArdourVSpacer), 5, 6, 0, 2, SHRINK, FILL, 4, 0);
158 pgm_tbl->attach (_send_panic, 6, 7, 0, 2, SHRINK, SHRINK, 4, 0);
159 pgm_tbl->show_all ();
162 Table* tbl = manage (new Table);
163 tbl->attach (_midi_channel, 0, 1, 0, 1, SHRINK, SHRINK, 4, 0);
164 tbl->attach (*manage (new Label (_("Channel"))), 0, 1, 1, 2, SHRINK, SHRINK, 4, 0);
165 tbl->attach (*manage (new ArdourVSpacer), 1, 2, 0, 2, SHRINK, FILL, 4, 0);
166 tbl->attach (*_pitch_slider, 2, 3, 0, 2, SHRINK, FILL, 4, 0);
168 const char* default_cc[VKBD_NCTRLS] = { "7", "8", "1", "11", "91", "92", "93", "94" };
171 for (int i = 0; i < VKBD_NCTRLS; ++i, ++col) {
172 _cc[i] = boost::shared_ptr<VKBDControl> (new VKBDControl ("CC"));
173 _cc_knob[i] = manage (new ArdourKnob (ArdourKnob::default_elements, ArdourKnob::Flags (0)));
174 _cc_knob[i]->set_controllable (_cc[i]);
175 _cc_knob[i]->set_size_request (PX_SCALE (21), PX_SCALE (21));
176 _cc_knob[i]->set_tooltip_prefix (_("CC: "));
177 _cc_knob[i]->set_name ("monitor section knob");
179 for (int c = 1; c < 120; ++c) {
184 sprintf (key, "%d", c);
185 _cc_key[i].append_text_item (key);
187 _cc_key[i].set_active (default_cc[i]);
189 tbl->attach (*_cc_knob[i], col, col + 1, 0, 1, SHRINK, SHRINK, 4, 2);
190 tbl->attach (_cc_key[i], col, col + 1, 1, 2, SHRINK, SHRINK, 4, 2);
192 _cc[i]->ValueChanged.connect_same_thread (_cc_connections,
193 boost::bind (&VirtualKeyboardWindow::control_change_event_handler, this, i, _1));
196 tbl->attach (*manage (new ArdourVSpacer), col, col + 1, 0, 2, SHRINK, FILL, 4, 0);
198 tbl->attach (_transpose_output, col, col + 1, 0, 1, SHRINK, SHRINK, 4, 0);
199 tbl->attach (*manage (new Label (_("Transpose"))), col, col + 1, 1, 2, SHRINK, SHRINK, 4, 0);
202 Box* box1 = manage (new HBox ());
203 box1->pack_start (*tbl, true, false);
205 Box* box2 = manage (new VBox ());
206 box2->pack_start (_pgm_display, false, false, 1);
207 box2->pack_start (_cfg_display, false, false, 1);
208 box1->pack_start (*box2, false, false);
210 _cfg_box = manage (new HBox ());
211 _cfg_box->pack_start (*cfg_tbl, true, false);
212 _cfg_box->set_no_show_all (true);
214 _pgm_box = manage (new HBox ());
215 _pgm_box->pack_start (*pgm_tbl, true, false);
216 _pgm_box->set_no_show_all (true);
218 VBox* vbox = manage (new VBox);
219 vbox->pack_start (*box1, false, false, 4);
220 vbox->pack_start (*_pgm_box, false, false, 4);
221 vbox->pack_start (*_cfg_box, false, false, 4);
222 vbox->pack_start (_piano, true, true);
225 _bank_msb.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::bank_patch));
226 _bank_lsb.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::bank_patch));
227 _patchpgm.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::bank_patch));
229 _piano_key_velocity.signal_value_changed ().connect (sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_velocity_settings), 0));
230 _piano_min_velocity.signal_value_changed ().connect (sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_velocity_settings), 1));
231 _piano_max_velocity.signal_value_changed ().connect (sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_velocity_settings), 2));
233 _piano_octave_key.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_octave_key));
234 _piano_octave_range.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_octave_range));
236 _cfg_display.signal_button_release_event ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::toggle_config), false);
237 _pgm_display.signal_button_release_event ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::toggle_bankpatch), false);
238 _yaxis_velocity.signal_button_release_event ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::toggle_yaxis_velocity), false);
239 _send_panic.signal_button_release_event ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::send_panic_message), false);
242 _piano.NoteOn.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::note_on_event_handler));
243 _piano.NoteOff.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::note_off_event_handler));
245 update_velocity_settings (0);
246 update_octave_range ();
248 set_keep_above (true);
252 VirtualKeyboardWindow::~VirtualKeyboardWindow ()
254 delete _pitch_slider_tooltip;
258 VirtualKeyboardWindow::set_session (ARDOUR::Session* s)
260 ArdourWindow::set_session (s);
266 XMLNode* node = _session->instant_xml (X_("VirtualKeyboard"));
273 VirtualKeyboardWindow::get_state ()
275 XMLNode* node = new XMLNode (X_("VirtualKeyboard"));
276 node->set_property (X_("YAxisVelocity"), _yaxis_velocity.get_active ());
277 node->set_property (X_("Layout"), _keyboard_layout.get_text ());
278 node->set_property (X_("Channel"), _midi_channel.get_text ());
279 node->set_property (X_("Transpose"), _transpose_output.get_text ());
280 node->set_property (X_("MinVelocity"), _piano_min_velocity.get_value_as_int ());
281 node->set_property (X_("MaxVelocity"), _piano_max_velocity.get_value_as_int ());
282 node->set_property (X_("KeyVelocity"), _piano_key_velocity.get_value_as_int ());
283 node->set_property (X_("Octave"), _piano_octave_key.get_value_as_int ());
284 node->set_property (X_("Range"), _piano_octave_range.get_value_as_int ());
285 for (int i = 0; i < VKBD_NCTRLS; ++i) {
287 sprintf (buf, "CC-%d", i);
288 node->set_property (buf, _cc_key[i].get_text ());
294 VirtualKeyboardWindow::set_state (const XMLNode& root)
296 if (root.name () != "VirtualKeyboard") {
300 XMLNode const* node = &root;
303 if (node->get_property (X_("Layout"), layout)) {
304 select_keyboard_layout (layout);
307 for (int i = 0; i < VKBD_NCTRLS; ++i) {
309 sprintf (buf, "CC-%d", i);
311 if (node->get_property (buf, cckey)) {
312 _cc_key[i].set_active (cckey);
317 if (node->get_property (X_("Channel"), s)) {
318 uint8_t channel = PBD::atoi (_midi_channel.get_text ());
319 if (channel > 0 && channel < 17) {
320 _midi_channel.set_active (s);
323 if (node->get_property (X_("Transpose"), s)) {
324 _transpose_output.set_active (s);
328 if (node->get_property (X_("YAxisVelocity"), a)) {
329 _yaxis_velocity.set_active (a);
333 if (node->get_property (X_("MinVelocity"), v)) {
334 _piano_min_velocity.set_value (v);
336 if (node->get_property (X_("MaxVelocity"), v)) {
337 _piano_max_velocity.set_value (v);
339 if (node->get_property (X_("KeyVelocity"), v)) {
340 _piano_key_velocity.set_value (v);
342 if (node->get_property (X_("Octave"), v)) {
343 _piano_octave_key.set_value (v);
345 if (node->get_property (X_("Range"), v)) {
346 _piano_octave_range.set_value (v);
349 update_velocity_settings (0);
350 update_octave_range ();
351 update_octave_key ();
355 VirtualKeyboardWindow::on_focus_in_event (GdkEventFocus* ev)
357 _piano.grab_focus ();
358 return ArdourWindow::on_focus_in_event (ev);
362 VirtualKeyboardWindow::on_unmap ()
364 ArdourWindow::on_unmap ();
365 ARDOUR_UI::instance ()->reset_focus (this);
369 VirtualKeyboardWindow::on_key_press_event (GdkEventKey* ev)
371 /* try propagate unmodified events first */
372 if ((ev->state & 0xf) == 0) {
373 if (gtk_window_propagate_key_event (gobj(), ev)) {
378 _piano.grab_focus ();
381 // XXX consider to handle these in APianoKeyboard::on_key_press_event
382 // and use signals. -- also subscribe SustainChanged, indicate sustain.
383 // TODO: pitch-bend shortcuts
384 if (ev->type == GDK_KEY_PRESS) {
385 if (ev->keyval == GDK_KEY_Left) {
386 _piano_octave_key.set_value (_piano_octave_key.get_value_as_int () - 1);
389 if (ev->keyval == GDK_KEY_Right) {
390 _piano_octave_key.set_value (_piano_octave_key.get_value_as_int () + 1);
395 return ARDOUR_UI_UTILS::relay_key_press (ev, this);
399 VirtualKeyboardWindow::select_keyboard_layout (std::string const& l)
401 _keyboard_layout.set_active (l);
403 _piano.set_keyboard_layout (APianoKeyboard::QWERTY);
404 } else if (l == "QWERTZ") {
405 _piano.set_keyboard_layout (APianoKeyboard::QWERTZ);
406 } else if (l == "AZERTY") {
407 _piano.set_keyboard_layout (APianoKeyboard::AZERTY);
408 } else if (l == "DVORAK") {
409 _piano.set_keyboard_layout (APianoKeyboard::DVORAK);
410 } else if (l == "QWERTY Single") {
411 _piano.set_keyboard_layout (APianoKeyboard::S_QWERTY);
412 } else if (l == "QWERTZ Single") {
413 _piano.set_keyboard_layout (APianoKeyboard::S_QWERTZ);
415 _keyboard_layout.set_active ("QWERTY");
417 _piano.grab_focus ();
421 VirtualKeyboardWindow::toggle_config (GdkEventButton* ev)
423 bool a = !_cfg_display.get_active ();
424 _cfg_display.set_active (a);
434 VirtualKeyboardWindow::toggle_bankpatch (GdkEventButton*)
436 bool a = !_pgm_display.get_active ();
437 _pgm_display.set_active (a);
447 VirtualKeyboardWindow::update_octave_key ()
449 _piano.set_octave (_piano_octave_key.get_value_as_int ());
450 _piano.grab_focus ();
454 VirtualKeyboardWindow::update_octave_range ()
456 _piano.set_octave_range (_piano_octave_range.get_value_as_int ());
457 _piano.set_grand_piano_highlight (_piano_octave_range.get_value_as_int () > 3);
458 _piano.grab_focus ();
462 VirtualKeyboardWindow::toggle_yaxis_velocity (GdkEventButton*)
464 _yaxis_velocity.set_active (!_yaxis_velocity.get_active ());
465 update_velocity_settings (0);
470 VirtualKeyboardWindow::send_panic_message (GdkEventButton*)
472 uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
474 ev[0] = MIDI_CMD_CONTROL | channel;
475 ev[1] = MIDI_CTL_SUSTAIN;
477 _session->vkbd_output_port ()->write (ev, 3, 0);
478 ev[1] = MIDI_CTL_ALL_NOTES_OFF;
479 _session->vkbd_output_port ()->write (ev, 3, 0);
480 ev[1] = MIDI_CTL_RESET_CONTROLLERS;
481 _session->vkbd_output_port ()->write (ev, 3, 0);
486 VirtualKeyboardWindow::bank_patch ()
488 int msb = _bank_msb.get_value_as_int ();
489 int lsb = _bank_lsb.get_value_as_int ();
490 int pgm = _patchpgm.get_value_as_int () - 1;
492 uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
494 ev[0] = MIDI_CMD_CONTROL | channel;
495 ev[1] = MIDI_CTL_MSB_BANK;
496 ev[2] = (msb >> 7) & 0x7f;
497 _session->vkbd_output_port ()->write (ev, 3, 0);
498 ev[1] = MIDI_CTL_LSB_BANK | channel;
500 _session->vkbd_output_port ()->write (ev, 3, 0);
501 ev[0] = MIDI_CMD_PGM_CHANGE | channel;
503 _session->vkbd_output_port ()->write (ev, 2, 0);
507 VirtualKeyboardWindow::update_velocity_settings (int ctrl)
509 if (_piano_min_velocity.get_value_as_int () > _piano_max_velocity.get_value_as_int ()) {
511 _piano_min_velocity.set_value (_piano_max_velocity.get_value_as_int ());
514 _piano_max_velocity.set_value (_piano_min_velocity.get_value_as_int ());
519 if (_yaxis_velocity.get_active ()) {
520 _piano.set_velocities (_piano_min_velocity.get_value_as_int (),
521 _piano_max_velocity.get_value_as_int (),
522 _piano_key_velocity.get_value_as_int ());
524 _piano.set_velocities (_piano_key_velocity.get_value_as_int (),
525 _piano_key_velocity.get_value_as_int (),
526 _piano_key_velocity.get_value_as_int ());
528 update_sensitivity ();
532 VirtualKeyboardWindow::update_sensitivity ()
534 bool c = _yaxis_velocity.get_active ();
535 _piano_min_velocity.set_sensitive (c);
536 _piano_max_velocity.set_sensitive (c);
537 _piano.grab_focus ();
541 VirtualKeyboardWindow::pitch_slider_adjusted ()
543 _pitchbend->set_value (_pitch_adjustment.get_value (), PBD::Controllable::NoGroup);
545 snprintf (buf, sizeof (buf), "%.0f", _pitch_adjustment.get_value ());
546 _pitch_slider_tooltip->set_tip (_("Pitchbend: ") + std::string(buf));
550 VirtualKeyboardWindow::note_on_event_handler (int note, int velocity)
552 _piano.grab_focus ();
556 note += PBD::atoi (_transpose_output.get_text ());
557 if (note < 0 || note > 127) {
560 uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
562 ev[0] = MIDI_CMD_NOTE_ON | channel;
565 _session->vkbd_output_port ()->write (ev, 3, 0);
569 VirtualKeyboardWindow::note_off_event_handler (int note)
574 note += PBD::atoi (_transpose_output.get_text ());
575 if (note < 0 || note > 127) {
578 uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
580 ev[0] = MIDI_CMD_NOTE_OFF | channel;
583 _session->vkbd_output_port ()->write (ev, 3, 0);
587 VirtualKeyboardWindow::control_change_event_handler (int key, int val)
592 assert (key >= 0 && key < VKBD_NCTRLS);
593 int ctrl = PBD::atoi (_cc_key[key].get_text ());
594 assert (ctrl > 0 && ctrl < 127);
595 uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
597 ev[0] = MIDI_CMD_CONTROL | channel;
600 _session->vkbd_output_port ()->write (ev, 3, 0);
604 VirtualKeyboardWindow::pitch_bend_event_handler (int val)
609 uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
611 ev[0] = MIDI_CMD_BENDER | channel;
613 ev[2] = (val >> 7) & 0x7f;
614 _session->vkbd_output_port ()->write (ev, 3, 0);