Virtual-keyboard: add CCs, bank/patch selector

This commit is contained in:
Robin Gareus 2019-10-20 02:43:39 +02:00
parent ce13979175
commit e63c2133e5
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 182 additions and 32 deletions

View File

@ -18,7 +18,9 @@
#include <gtkmm/box.h>
#include "pbd/convert.h"
#include "ardour/async_midi_port.h"
#include "widgets/tooltips.h"
#include "ardour_ui.h"
#include "virtual_keyboard_window.h"
@ -35,13 +37,17 @@ using namespace ArdourWidgets;
VirtualKeyboardWindow::VirtualKeyboardWindow ()
: ArdourWindow (_("Virtual Keyboard"))
, _piano_channel (*manage (new Adjustment (0, 1, 16, 1, 1)))
, _piano_channel (*manage (new Adjustment (1, 1, 16, 1, 1)))
, _bank_msb (*manage (new Adjustment (0, 0, 127, 1, 16)))
, _bank_lsb (*manage (new Adjustment (0, 0, 127, 1, 16)))
, _patchpgm (*manage (new Adjustment (1, 1, 128, 1, 16)))
, _cfg_display ("Config", ArdourButton::led_default_elements)
, _pgm_display ("Bank/Patch", ArdourButton::led_default_elements)
, _yaxis_velocity ("Y-Axis Click Velocity", ArdourButton::led_default_elements)
, _send_panic ("Panic", ArdourButton::default_elements)
, _piano_key_velocity (*manage (new Adjustment (100, 1, 127, 1, 16)))
, _piano_min_velocity (*manage (new Adjustment (1 , 1, 127, 1, 16)))
, _piano_max_velocity (*manage (new Adjustment (127, 1, 127, 1, 16)))
, _cc7 (new VKBDControl ("CC7", 127))
, _cc7_knob (ArdourKnob::default_elements, ArdourKnob::Flags (0))
{
_piano = (PianoKeyboard*)piano_keyboard_new();
_pianomm = Glib::wrap((GtkWidget*)_piano);
@ -58,15 +64,12 @@ VirtualKeyboardWindow::VirtualKeyboardWindow ()
sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::select_keyboard_layout), 2)));
_keyboard_layout.set_text (_("QWERTY"));
_cfg_display.set_active (false);
_pgm_display.set_active (false);
_yaxis_velocity.set_active (false);
_cc7_knob.set_controllable (_cc7);
_cc7_knob.set_size_request (PX_SCALE(21), PX_SCALE(21));
_cc7_knob.set_tooltip_prefix (_("CC7: "));
_cc7_knob.set_name ("monitor section knob");
set_tooltip (_send_panic, "Send MIDI Panic message for current channel");
// TODO allow to hide config panel
// save/restore settings
/* config */
HBox* cfg_box = manage (new HBox);
@ -79,37 +82,101 @@ VirtualKeyboardWindow::VirtualKeyboardWindow ()
cfg_box->pack_start (*manage (new Label (_("Max Velocity:"))), false, false);
cfg_box->pack_start (_piano_max_velocity, false, false);
cfg_box->pack_start (_keyboard_layout, false, false, 8);
cfg_box->show_all ();
/* bank/patch */
Table* pgm_tbl = manage (new Table);
Label* lbl = manage (new Label (_("Note: Prefer\nTrack-controls")));
lbl->set_justify (JUSTIFY_CENTER);
pgm_tbl->attach (*lbl, 0, 1, 0, 2, SHRINK, SHRINK, 4, 0);
pgm_tbl->attach (*manage (new ArdourVSpacer), 1, 2, 0, 2, SHRINK, FILL, 4, 0);
pgm_tbl->attach (_bank_msb, 2, 3, 0, 1, SHRINK, SHRINK, 4, 0);
pgm_tbl->attach (_bank_lsb, 3, 4, 0, 1, SHRINK, SHRINK, 4, 0);
pgm_tbl->attach (_patchpgm, 4, 5, 0, 1, SHRINK, SHRINK, 4, 0);
pgm_tbl->attach (*manage (new Label (_("MSB"))), 2, 3, 1, 2, SHRINK, SHRINK, 4, 0);
pgm_tbl->attach (*manage (new Label (_("LSB"))), 3, 4, 1, 2, SHRINK, SHRINK, 4, 0);
pgm_tbl->attach (*manage (new Label (_("PGM"))), 4, 5, 1, 2, SHRINK, SHRINK, 4, 0);
pgm_tbl->attach (*manage (new ArdourVSpacer), 5, 6, 0, 2, SHRINK, FILL, 4, 0);
pgm_tbl->attach (_send_panic, 6, 7, 0, 2, SHRINK, SHRINK, 4, 0);
pgm_tbl->show_all ();
/* settings */
HBox* set_box = manage (new HBox);
set_box->set_spacing (4);
set_box->pack_start (*manage (new Label (_("Channel:"))), false, false);
set_box->pack_start (_piano_channel, false, false, 8);
set_box->pack_start (*manage (new Label (_("CC7:"))), false, false);
set_box->pack_start (_cc7_knob, false, false);
Table* tbl = manage (new Table);
tbl->attach (_piano_channel, 0, 1, 0, 1, SHRINK, SHRINK, 4, 0);
tbl->attach (*manage (new Label (_("Channel"))), 0, 1, 1, 2, SHRINK, SHRINK, 4, 0);
tbl->attach (*manage (new ArdourVSpacer), 1, 2, 0, 2, SHRINK, FILL, 4, 0);
/* layout */
// TODO: pitchbend
const char* default_cc[VKBD_NCTRLS] = { "7", "8", "1", "11", "91", "92", "93", "94" };
for (int i = 0; i < VKBD_NCTRLS; ++i) {
_cc[i] = boost::shared_ptr<VKBDControl> (new VKBDControl ("CC7", 127));
_cc_knob[i] = manage(new ArdourKnob (ArdourKnob::default_elements, ArdourKnob::Flags (0)));
_cc_knob[i]->set_controllable (_cc[i]);
_cc_knob[i]->set_size_request (PX_SCALE(21), PX_SCALE(21));
_cc_knob[i]->set_tooltip_prefix (_("CC: "));
_cc_knob[i]->set_name ("monitor section knob");
for (int c = 1; c < 120; ++c) {
if (c == 32) {
continue;
}
char key[32];
sprintf (key, "%d", c);
_cc_key[i].append_text_item (key);
}
_cc_key[i].set_text (default_cc[i]);
tbl->attach (*_cc_knob[i], i+2, i+3, 0, 1, SHRINK, SHRINK, 4, 2);
tbl->attach (_cc_key[i] , i+2, i+3, 1, 2, SHRINK, SHRINK, 4, 2);
_cc[i]->ValueChanged.connect_same_thread (_cc_connections,
boost::bind (&VirtualKeyboardWindow::control_change_event_handler, this, i, _1));
}
/* main layout */
Box* box1 = manage (new HBox ());
box1->pack_start (*cfg_box, true, false);
Box* box2 = manage (new HBox ());
box2->pack_start (*set_box, true, false);
box1->pack_start (*tbl, true, false);
Box* box2 = manage (new VBox ());
box2->pack_start (_pgm_display, false, false);
box2->pack_start (_cfg_display, false, false);
box1->pack_start (*box2, false, false);
_cfg_box = manage (new HBox ());
_cfg_box->pack_start (*cfg_box, true, false);
_cfg_box->set_no_show_all (true);
_pgm_box = manage (new HBox ());
_pgm_box->pack_start (*pgm_tbl, true, false);
_pgm_box->set_no_show_all (true);
VBox* vbox = manage (new VBox);
vbox->pack_start (*box1, false, false, 4);
vbox->pack_start (*box2, false, false, 4);
vbox->pack_start (*_pgm_box, false, false, 4);
vbox->pack_start (*_cfg_box, false, false, 4);
vbox->pack_start (*_pianomm, true, true);
add (*vbox);
_bank_msb.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::bank_patch));
_bank_lsb.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::bank_patch));
_patchpgm.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::bank_patch));
_piano_key_velocity.signal_value_changed ().connect (sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_velocity_settings), 0));
_piano_min_velocity.signal_value_changed ().connect (sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_velocity_settings), 1));
_piano_max_velocity.signal_value_changed ().connect (sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_velocity_settings), 2));
_yaxis_velocity.signal_button_release_event().connect (sigc::mem_fun(*this, &VirtualKeyboardWindow::yaxis_velocity_button_release), false);
_cfg_display.signal_button_release_event().connect (sigc::mem_fun(*this, &VirtualKeyboardWindow::toggle_config), false);
_pgm_display.signal_button_release_event().connect (sigc::mem_fun(*this, &VirtualKeyboardWindow::toggle_bankpatch), false);
_yaxis_velocity.signal_button_release_event().connect (sigc::mem_fun(*this, &VirtualKeyboardWindow::toggle_yaxis_velocity), false);
_send_panic.signal_button_release_event().connect (sigc::mem_fun(*this, &VirtualKeyboardWindow::send_panic_message), false);
g_signal_connect (G_OBJECT (_piano), "note-on", G_CALLBACK (VirtualKeyboardWindow::_note_on_event_handler), this);
g_signal_connect (G_OBJECT (_piano), "note-off", G_CALLBACK (VirtualKeyboardWindow::_note_off_event_handler), this);
_cc7->ValueChanged.connect_same_thread (_cc_connections, boost::bind (&VirtualKeyboardWindow::control_change_event_handler, this, 7, _1));
update_velocity_settings (0);
set_keep_above (true);
@ -155,13 +222,76 @@ VirtualKeyboardWindow::select_keyboard_layout (int l)
}
bool
VirtualKeyboardWindow::yaxis_velocity_button_release (GdkEventButton* ev)
VirtualKeyboardWindow::toggle_config (GdkEventButton* ev)
{
bool a = ! _cfg_display.get_active ();
_cfg_display.set_active (a);
if (a) {
_cfg_box->show ();
} else {
_cfg_box->hide ();
}
return false;
}
bool
VirtualKeyboardWindow::toggle_bankpatch (GdkEventButton*)
{
bool a = ! _pgm_display.get_active ();
_pgm_display.set_active (a);
if (a) {
_pgm_box->show ();
} else {
_pgm_box->hide ();
}
return false;
}
bool
VirtualKeyboardWindow::toggle_yaxis_velocity (GdkEventButton*)
{
_yaxis_velocity.set_active (!_yaxis_velocity.get_active ());
update_velocity_settings (0);
return false;
}
bool
VirtualKeyboardWindow::send_panic_message (GdkEventButton*)
{
uint8_t channel = _piano_channel.get_value_as_int () - 1;
uint8_t ev[3];
ev[0] = MIDI_CMD_CONTROL | channel;
ev[1] = MIDI_CTL_SUSTAIN;
ev[2] = 0;
_session->vkbd_output_port()->write (ev, 3, 0);
ev[1] = MIDI_CTL_ALL_NOTES_OFF;
_session->vkbd_output_port()->write (ev, 3, 0);
ev[1] = MIDI_CTL_RESET_CONTROLLERS;
_session->vkbd_output_port()->write (ev, 3, 0);
return false;
}
void
VirtualKeyboardWindow::bank_patch ()
{
int msb = _bank_msb.get_value_as_int ();
int lsb = _bank_lsb.get_value_as_int ();
int pgm = _patchpgm.get_value_as_int () - 1;
uint8_t channel = _piano_channel.get_value_as_int () - 1;
uint8_t ev[3];
ev[0] = MIDI_CMD_CONTROL | channel;
ev[1] = MIDI_CTL_MSB_BANK;
ev[2] = (msb >> 7) & 0x7f;
_session->vkbd_output_port()->write (ev, 3, 0);
ev[1] = MIDI_CTL_LSB_BANK | channel;
ev[2] = lsb & 0x7f;
_session->vkbd_output_port()->write (ev, 3, 0);
ev[0] = MIDI_CMD_PGM_CHANGE | channel;
ev[1] = pgm & 0x7f;
_session->vkbd_output_port()->write (ev, 2, 0);
}
void
VirtualKeyboardWindow::update_velocity_settings (int ctrl)
{
@ -232,10 +362,13 @@ VirtualKeyboardWindow::note_off_event_handler (int note)
void
VirtualKeyboardWindow::control_change_event_handler (int key, int val)
{
assert (key >= 0 && key < VKBD_NCTRLS);
int ctrl = PBD::atoi (_cc_key[key].get_text());
assert (ctrl > 0 && ctrl < 127);
uint8_t channel = _piano_channel.get_value_as_int () - 1;
uint8_t ev[3];
ev[0] = (MIDI_CMD_CONTROL | channel);
ev[1] = key;
ev[1] = ctrl;
ev[2] = val;
_session->vkbd_output_port()->write (ev, 3, 0);
}

View File

@ -19,6 +19,7 @@
#ifndef _virtual_keyboard_window_h_
#define _virtual_keyboard_window_h_
#include <gtkmm/box.h>
#include <gtkmm/spinbutton.h>
#include "pbd/signals.h"
@ -85,10 +86,6 @@ public:
VirtualKeyboardWindow ();
~VirtualKeyboardWindow ();
protected:
void on_unmap ();
bool on_key_press_event (GdkEventKey*);
private:
static void _note_on_event_handler (GtkWidget*, int note, int vel, gpointer arg)
{
@ -100,28 +97,48 @@ private:
static_cast<VirtualKeyboardWindow*>(arg)->note_off_event_handler(note);
}
void on_unmap ();
bool on_key_press_event (GdkEventKey*);
void note_on_event_handler (int, int);
void note_off_event_handler (int);
void control_change_event_handler (int, int);
void select_keyboard_layout (int);
void update_velocity_settings (int);
void bank_patch ();
void update_sensitivity ();
bool yaxis_velocity_button_release (GdkEventButton* ev);
bool toggle_config (GdkEventButton*);
bool toggle_bankpatch (GdkEventButton*);
bool toggle_yaxis_velocity (GdkEventButton*);
bool send_panic_message (GdkEventButton*);
PianoKeyboard* _piano;
Gtk::Widget* _pianomm;
Gtk::SpinButton _piano_channel;
Gtk::SpinButton _bank_msb;
Gtk::SpinButton _bank_lsb;
Gtk::SpinButton _patchpgm;
Gtk::HBox* _cfg_box;
Gtk::HBox* _pgm_box;
ArdourWidgets::ArdourButton _cfg_display;
ArdourWidgets::ArdourButton _pgm_display;
ArdourWidgets::ArdourButton _yaxis_velocity;
ArdourWidgets::ArdourButton _send_panic;
ArdourWidgets::ArdourDropdown _keyboard_layout;
Gtk::SpinButton _piano_key_velocity;
Gtk::SpinButton _piano_min_velocity;
Gtk::SpinButton _piano_max_velocity;
boost::shared_ptr<VKBDControl> _cc7;
ArdourWidgets::ArdourKnob _cc7_knob;
#define VKBD_NCTRLS 8
boost::shared_ptr<VKBDControl> _cc[VKBD_NCTRLS];
ArdourWidgets::ArdourKnob* _cc_knob[VKBD_NCTRLS];
ArdourWidgets::ArdourDropdown _cc_key[VKBD_NCTRLS];
PBD::ScopedConnectionList _cc_connections;
};