2019-10-17 21:50:52 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtkmm/box.h>
|
|
|
|
|
2019-10-26 18:05:22 -04:00
|
|
|
|
|
|
|
#include "pbd/convert.h"
|
2019-12-15 08:04:44 -05:00
|
|
|
#include "pbd/compose.h"
|
2019-10-26 18:05:22 -04:00
|
|
|
|
2019-10-17 21:50:52 -04:00
|
|
|
#include "ardour/async_midi_port.h"
|
2019-10-20 14:53:40 -04:00
|
|
|
#include "ardour/session.h"
|
2019-10-26 18:05:22 -04:00
|
|
|
|
|
|
|
#include "gtkmm2ext/utils.h"
|
2024-05-14 17:41:51 -04:00
|
|
|
|
|
|
|
#include "widgets/slider_controller.h"
|
2019-10-19 20:43:39 -04:00
|
|
|
#include "widgets/tooltips.h"
|
2019-10-17 21:50:52 -04:00
|
|
|
|
|
|
|
#include "ardour_ui.h"
|
2019-10-18 11:26:25 -04:00
|
|
|
#include "ui_config.h"
|
2019-10-17 21:50:52 -04:00
|
|
|
#include "utils.h"
|
2019-10-21 10:06:29 -04:00
|
|
|
#include "virtual_keyboard_window.h"
|
2019-10-17 21:50:52 -04:00
|
|
|
|
|
|
|
#include "pbd/i18n.h"
|
|
|
|
|
|
|
|
using namespace Glib;
|
|
|
|
using namespace Gtk;
|
2019-10-18 11:26:25 -04:00
|
|
|
using namespace ArdourWidgets;
|
|
|
|
|
2019-10-21 10:06:29 -04:00
|
|
|
#define PX_SCALE(px) std::max ((float)px, rintf ((float)px* UIConfiguration::instance ().get_ui_scale ()))
|
2019-10-17 21:50:52 -04:00
|
|
|
|
|
|
|
VirtualKeyboardWindow::VirtualKeyboardWindow ()
|
2019-10-20 23:41:34 -04:00
|
|
|
: ArdourWindow (_("Virtual MIDI Keyboard"))
|
2019-11-01 21:43:56 -04:00
|
|
|
, _send_panic (_("Panic"), ArdourButton::default_elements)
|
2019-10-20 12:29:23 -04:00
|
|
|
, _pitch_adjustment (8192, 0, 16383, 1, 256)
|
2019-12-18 09:01:17 -05:00
|
|
|
, _modwheel_adjustment (0, 0, 127, 1, 8)
|
2019-10-17 21:50:52 -04:00
|
|
|
{
|
2019-12-18 22:27:54 -05:00
|
|
|
UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::parameter_changed));
|
|
|
|
|
2022-01-26 16:29:36 -05:00
|
|
|
_piano.set_can_focus ();
|
2019-10-24 13:43:46 -04:00
|
|
|
|
2020-03-28 14:36:39 -04:00
|
|
|
select_keyboard_layout (UIConfiguration::instance().get_vkeybd_layout ());
|
2019-10-25 15:23:27 -04:00
|
|
|
_piano.set_annotate_octave (true);
|
|
|
|
_piano.set_grand_piano_highlight (false);
|
2019-10-26 18:05:22 -04:00
|
|
|
_piano.set_annotate_layout (true);
|
|
|
|
_piano.set_annotate_octave (true);
|
2019-10-17 21:50:52 -04:00
|
|
|
|
2019-10-25 17:52:53 -04:00
|
|
|
for (int c = 0; c < 16; ++c) {
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "%d", c + 1);
|
|
|
|
_midi_channel.append_text_item (buf);
|
|
|
|
}
|
2019-12-25 06:46:34 -05:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
for (int v = 0; v <= 128; v += 16) {
|
2019-12-24 12:15:09 -05:00
|
|
|
char buf[16];
|
2019-12-25 06:46:34 -05:00
|
|
|
sprintf (buf, "%d", std::min (127, std::max (1, v)));
|
2019-12-24 12:15:09 -05:00
|
|
|
_piano_velocity.append_text_item (buf);
|
|
|
|
}
|
2019-12-25 06:46:34 -05:00
|
|
|
#else
|
|
|
|
_piano_velocity.append_text_item ("8");
|
|
|
|
_piano_velocity.append_text_item ("32");
|
|
|
|
_piano_velocity.append_text_item ("64");
|
|
|
|
_piano_velocity.append_text_item ("82");
|
2023-07-25 17:26:46 -04:00
|
|
|
_piano_velocity.append_text_item ("96");
|
2019-12-25 06:46:34 -05:00
|
|
|
_piano_velocity.append_text_item ("100");
|
|
|
|
_piano_velocity.append_text_item ("127");
|
|
|
|
#endif
|
|
|
|
|
2019-12-24 12:15:09 -05:00
|
|
|
for (int k = -1; k < 8; ++k) {
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "%d", k);
|
|
|
|
_piano_octave_key.append_text_item (buf);
|
|
|
|
}
|
|
|
|
for (int r = 2; r < 12; ++r) {
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "%d", r);
|
|
|
|
_piano_octave_range.append_text_item (buf);
|
|
|
|
}
|
2019-10-25 17:52:53 -04:00
|
|
|
for (int t = -12; t < 13; ++t) {
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "%d", t);
|
|
|
|
_transpose_output.append_text_item (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
_midi_channel.set_active ("1");
|
2019-12-24 12:15:09 -05:00
|
|
|
_piano_velocity.set_active ("100");
|
|
|
|
_piano_octave_key.set_active ("4");
|
|
|
|
_piano_octave_range.set_active ("7");
|
2019-10-25 17:52:53 -04:00
|
|
|
_transpose_output.set_active ("0");
|
2019-10-18 11:26:25 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
_pitchbend = std::shared_ptr<VKBDControl> (new VKBDControl ("PB", 8192, 16383));
|
2019-10-21 10:06:29 -04:00
|
|
|
_pitch_slider = manage (new VSliderController (&_pitch_adjustment, _pitchbend, 0, PX_SCALE (15)));
|
2019-10-20 12:29:23 -04:00
|
|
|
_pitch_slider_tooltip = new Gtkmm2ext::PersistentTooltip (_pitch_slider);
|
2019-10-21 10:06:29 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
_modwheel = std::shared_ptr<VKBDControl> (new VKBDControl ("MW", 0, 127));
|
2019-12-18 09:01:17 -05:00
|
|
|
_modwheel_slider = manage (new VSliderController (&_modwheel_adjustment, _modwheel, 0, PX_SCALE (15)));
|
|
|
|
_modwheel_tooltip = new Gtkmm2ext::PersistentTooltip (_modwheel_slider);
|
|
|
|
|
2019-12-24 12:15:09 -05:00
|
|
|
/* tooltips */
|
|
|
|
set_tooltip (_midi_channel, _("Set the MIDI Channel of the produced MIDI events"));
|
2019-11-01 21:43:56 -04:00
|
|
|
set_tooltip (_piano_octave_key, _("The center octave, and lowest octave for keyboard control. Change with Arrow left/right."));
|
|
|
|
set_tooltip (_piano_octave_range, _("Available octave range, centered around the key-octave."));
|
2019-12-25 06:46:34 -05:00
|
|
|
set_tooltip (_piano_velocity, _("The velocity to use with keyboard control. Use mouse-scroll for fine-grained control"));
|
2019-12-24 12:15:09 -05:00
|
|
|
set_tooltip (_transpose_output, _("Chromatic transpose note events. Notes transposed outside the range of 0,,127 are discarded."));
|
2019-10-20 23:41:34 -04:00
|
|
|
|
2019-11-01 21:43:56 -04:00
|
|
|
set_tooltip (_send_panic, _("Send MIDI Panic message for current channel"));
|
2019-10-20 23:41:34 -04:00
|
|
|
|
2019-12-24 12:15:09 -05:00
|
|
|
modwheel_update_tooltip (0);
|
2019-12-15 08:04:44 -05:00
|
|
|
pitch_bend_update_tooltip (8192);
|
2019-12-24 12:15:09 -05:00
|
|
|
|
|
|
|
/* prevent focus grab, let MIDI keyboard to handle key events */
|
|
|
|
_send_panic.set_can_focus (false);
|
|
|
|
_modwheel_slider->set_can_focus (false);
|
2019-10-23 23:13:56 -04:00
|
|
|
_pitch_slider->set_can_focus (false);
|
2019-10-18 11:26:25 -04:00
|
|
|
|
2019-12-24 12:15:09 -05:00
|
|
|
/* layout */
|
2019-10-19 20:43:39 -04:00
|
|
|
Table* tbl = manage (new Table);
|
2019-10-25 17:52:53 -04:00
|
|
|
tbl->attach (_midi_channel, 0, 1, 0, 1, SHRINK, SHRINK, 4, 0);
|
2019-10-19 20:43:39 -04:00
|
|
|
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);
|
2019-10-20 12:29:23 -04:00
|
|
|
tbl->attach (*_pitch_slider, 2, 3, 0, 2, SHRINK, FILL, 4, 0);
|
2019-12-18 09:01:17 -05:00
|
|
|
tbl->attach (*_modwheel_slider, 3, 4, 0, 2, SHRINK, FILL, 4, 0);
|
2019-10-19 20:43:39 -04:00
|
|
|
|
2019-12-18 09:01:17 -05:00
|
|
|
const int default_cc[VKBD_NCTRLS] = { 7, 8, 91, 93};
|
2019-10-19 20:43:39 -04:00
|
|
|
|
2019-12-18 09:01:17 -05:00
|
|
|
int col = 4;
|
|
|
|
for (size_t i = 0; i < VKBD_NCTRLS; ++i, ++col) {
|
2023-02-16 18:33:28 -05:00
|
|
|
_cc[i] = std::shared_ptr<VKBDControl> (new VKBDControl ("CC"));
|
2019-10-21 10:06:29 -04:00
|
|
|
_cc_knob[i] = manage (new ArdourKnob (ArdourKnob::default_elements, ArdourKnob::Flags (0)));
|
2019-10-19 20:43:39 -04:00
|
|
|
_cc_knob[i]->set_controllable (_cc[i]);
|
2019-10-21 10:06:29 -04:00
|
|
|
_cc_knob[i]->set_size_request (PX_SCALE (21), PX_SCALE (21));
|
2019-10-19 20:43:39 -04:00
|
|
|
_cc_knob[i]->set_name ("monitor section knob");
|
|
|
|
|
2019-12-18 09:01:17 -05:00
|
|
|
for (int c = 2; c < 120; ++c) {
|
2019-10-19 20:43:39 -04:00
|
|
|
if (c == 32) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
char key[32];
|
|
|
|
sprintf (key, "%d", c);
|
|
|
|
_cc_key[i].append_text_item (key);
|
|
|
|
}
|
|
|
|
|
2019-10-21 13:31:25 -04:00
|
|
|
tbl->attach (*_cc_knob[i], col, col + 1, 0, 1, SHRINK, SHRINK, 4, 2);
|
|
|
|
tbl->attach (_cc_key[i], col, col + 1, 1, 2, SHRINK, SHRINK, 4, 2);
|
2019-10-19 20:43:39 -04:00
|
|
|
|
2019-12-18 09:01:17 -05:00
|
|
|
_cc_key[i].StateChanged.connect (sigc::bind (sigc::mem_fun (*this, &VirtualKeyboardWindow::cc_key_changed), i));
|
2019-10-19 20:43:39 -04:00
|
|
|
_cc[i]->ValueChanged.connect_same_thread (_cc_connections,
|
2019-12-18 09:01:17 -05:00
|
|
|
boost::bind (&VirtualKeyboardWindow::control_change_knob_event_handler, this, i, _1));
|
2020-04-22 10:20:54 -04:00
|
|
|
|
|
|
|
update_cc (i, default_cc[i]);
|
2019-10-19 20:43:39 -04:00
|
|
|
}
|
|
|
|
|
2019-12-18 09:01:46 -05:00
|
|
|
tbl->attach (*manage (new ArdourVSpacer), col, col + 1, 0, 2, SHRINK, FILL, 4, 0);
|
|
|
|
++col;
|
|
|
|
tbl->attach (_piano_octave_key, col, col + 1, 0, 1, SHRINK, SHRINK, 4, 0);
|
|
|
|
tbl->attach (*manage (new Label (_("Octave"))), col, col + 1, 1, 2, SHRINK, SHRINK, 4, 0);
|
|
|
|
++col;
|
|
|
|
tbl->attach (_piano_octave_range, col, col + 1, 0, 1, SHRINK, SHRINK, 4, 0);
|
|
|
|
tbl->attach (*manage (new Label (_("Range"))), col, col + 1, 1, 2, SHRINK, SHRINK, 4, 0);
|
|
|
|
++col;
|
|
|
|
|
|
|
|
tbl->attach (*manage (new ArdourVSpacer), col, col + 1, 0, 2, SHRINK, FILL, 4, 0);
|
|
|
|
++col;
|
2019-12-25 06:46:34 -05:00
|
|
|
tbl->attach (_piano_velocity, col, col + 1, 0, 1, SHRINK, SHRINK, 4, 0);
|
|
|
|
tbl->attach (*manage (new Label (_("Velocity"))), col, col + 1, 1, 2, SHRINK, SHRINK, 4, 0);
|
2019-12-18 09:01:46 -05:00
|
|
|
++col;
|
|
|
|
|
|
|
|
tbl->attach (*manage (new ArdourVSpacer), col, col + 1, 0, 2, SHRINK, FILL, 4, 0);
|
|
|
|
++col;
|
|
|
|
tbl->attach (_transpose_output, col, col + 1, 0, 1, SHRINK, SHRINK, 4, 0);
|
|
|
|
tbl->attach (*manage (new Label (_("Transpose"))), col, col + 1, 1, 2, SHRINK, SHRINK, 4, 0);
|
2019-10-21 13:31:25 -04:00
|
|
|
++col;
|
2019-12-18 09:01:46 -05:00
|
|
|
tbl->attach (_send_panic, col, col + 1, 0, 2, SHRINK, SHRINK, 4, 0);
|
2019-10-21 13:31:25 -04:00
|
|
|
|
2019-10-19 20:43:39 -04:00
|
|
|
/* main layout */
|
2019-10-18 11:26:25 -04:00
|
|
|
Box* box1 = manage (new HBox ());
|
2019-10-19 20:43:39 -04:00
|
|
|
box1->pack_start (*tbl, true, false);
|
|
|
|
|
2019-10-17 21:50:52 -04:00
|
|
|
VBox* vbox = manage (new VBox);
|
2019-10-18 11:26:25 -04:00
|
|
|
vbox->pack_start (*box1, false, false, 4);
|
2019-10-24 13:43:46 -04:00
|
|
|
vbox->pack_start (_piano, true, true);
|
2019-10-17 21:50:52 -04:00
|
|
|
add (*vbox);
|
|
|
|
|
2019-12-25 06:46:34 -05:00
|
|
|
set_size_request_to_display_given_text (_piano_octave_key, "88", 19, 2);
|
|
|
|
set_size_request_to_display_given_text (_piano_octave_range, "88", 19, 2);
|
|
|
|
set_size_request_to_display_given_text (_piano_velocity, "888", 19, 2);
|
|
|
|
|
2019-12-24 12:15:09 -05:00
|
|
|
/* GUI signals */
|
|
|
|
|
|
|
|
_pitch_adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::pitch_slider_adjusted));
|
|
|
|
_pitchbend->ValueChanged.connect_same_thread (_cc_connections, boost::bind (&VirtualKeyboardWindow::pitch_bend_event_handler, this, _1));
|
|
|
|
_pitch_slider->StopGesture.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::pitch_bend_release));
|
|
|
|
|
|
|
|
_modwheel_adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::modwheel_slider_adjusted));
|
|
|
|
_modwheel->ValueChanged.connect_same_thread (_cc_connections, boost::bind (&VirtualKeyboardWindow::control_change_event_handler, this, 1, _1));
|
2019-10-18 11:26:25 -04:00
|
|
|
|
2019-12-24 12:15:09 -05:00
|
|
|
_piano_velocity.StateChanged.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_velocity_settings));
|
|
|
|
_piano_octave_key.StateChanged.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_octave_key));
|
|
|
|
_piano_octave_range.StateChanged.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::update_octave_range));
|
2019-10-20 23:41:34 -04:00
|
|
|
|
2019-10-21 10:06:29 -04:00
|
|
|
_send_panic.signal_button_release_event ().connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::send_panic_message), false);
|
2019-10-18 11:26:25 -04:00
|
|
|
|
2019-12-25 06:46:34 -05:00
|
|
|
_piano_velocity.disable_scrolling ();
|
|
|
|
_piano_velocity.signal_scroll_event().connect (sigc::mem_fun(*this, &VirtualKeyboardWindow::on_velocity_scroll_event), false);
|
|
|
|
|
2019-12-24 12:15:09 -05:00
|
|
|
/* piano keyboard signals */
|
2019-10-24 13:43:46 -04:00
|
|
|
|
|
|
|
_piano.NoteOn.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::note_on_event_handler));
|
|
|
|
_piano.NoteOff.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::note_off_event_handler));
|
2019-12-16 09:02:39 -05:00
|
|
|
_piano.SwitchOctave.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::octave_key_event_handler));
|
|
|
|
_piano.PitchBend.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::pitch_bend_key_event_handler));
|
2023-06-10 08:59:49 -04:00
|
|
|
_piano.SetVelocity.connect (sigc::mem_fun (*this, &VirtualKeyboardWindow::velocity_key_event_handler));
|
2019-10-18 11:26:25 -04:00
|
|
|
|
2019-12-24 12:15:09 -05:00
|
|
|
/* initialize GUI */
|
|
|
|
|
2019-12-18 22:27:54 -05:00
|
|
|
update_velocity_settings ();
|
2019-10-21 09:27:42 -04:00
|
|
|
update_octave_range ();
|
2019-10-18 11:26:25 -04:00
|
|
|
|
2019-10-17 21:50:52 -04:00
|
|
|
set_keep_above (true);
|
2019-10-21 10:06:29 -04:00
|
|
|
vbox->show_all ();
|
2019-10-17 21:50:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VirtualKeyboardWindow::~VirtualKeyboardWindow ()
|
|
|
|
{
|
2019-10-20 12:29:23 -04:00
|
|
|
delete _pitch_slider_tooltip;
|
2019-10-17 21:50:52 -04:00
|
|
|
}
|
|
|
|
|
2019-10-20 14:53:40 -04:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::set_session (ARDOUR::Session* s)
|
|
|
|
{
|
|
|
|
ArdourWindow::set_session (s);
|
|
|
|
|
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-21 10:06:29 -04:00
|
|
|
XMLNode* node = _session->instant_xml (X_("VirtualKeyboard"));
|
2019-10-20 14:53:40 -04:00
|
|
|
if (node) {
|
|
|
|
set_state (*node);
|
|
|
|
}
|
|
|
|
}
|
2020-04-03 15:17:53 -04:00
|
|
|
|
2019-12-18 22:27:54 -05:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::parameter_changed (std::string const& p)
|
|
|
|
{
|
|
|
|
if (p == "vkeybd-layout") {
|
|
|
|
select_keyboard_layout (UIConfiguration::instance().get_vkeybd_layout ());
|
|
|
|
}
|
|
|
|
}
|
2019-10-20 14:53:40 -04:00
|
|
|
|
|
|
|
XMLNode&
|
2022-04-06 23:56:45 -04:00
|
|
|
VirtualKeyboardWindow::get_state () const
|
2019-10-20 14:53:40 -04:00
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode (X_("VirtualKeyboard"));
|
2019-10-25 17:52:53 -04:00
|
|
|
node->set_property (X_("Channel"), _midi_channel.get_text ());
|
|
|
|
node->set_property (X_("Transpose"), _transpose_output.get_text ());
|
2019-12-24 12:15:09 -05:00
|
|
|
node->set_property (X_("KeyVelocity"), _piano_velocity.get_text ());
|
|
|
|
node->set_property (X_("Octave"), _piano_octave_key.get_text ());
|
|
|
|
node->set_property (X_("Range"), _piano_octave_range.get_text ());
|
2019-10-20 14:53:40 -04:00
|
|
|
for (int i = 0; i < VKBD_NCTRLS; ++i) {
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "CC-%d", i);
|
2019-10-21 10:06:29 -04:00
|
|
|
node->set_property (buf, _cc_key[i].get_text ());
|
2019-10-20 14:53:40 -04:00
|
|
|
}
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-10-21 10:06:29 -04:00
|
|
|
VirtualKeyboardWindow::set_state (const XMLNode& root)
|
2019-10-20 14:53:40 -04:00
|
|
|
{
|
2019-10-21 10:06:29 -04:00
|
|
|
if (root.name () != "VirtualKeyboard") {
|
2019-10-20 14:53:40 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode const* node = &root;
|
|
|
|
|
|
|
|
for (int i = 0; i < VKBD_NCTRLS; ++i) {
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "CC-%d", i);
|
|
|
|
std::string cckey;
|
2019-10-21 10:06:29 -04:00
|
|
|
if (node->get_property (buf, cckey)) {
|
2019-12-18 09:01:17 -05:00
|
|
|
update_cc (i, PBD::atoi (cckey));
|
2019-10-20 14:53:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 17:52:53 -04:00
|
|
|
std::string s;
|
|
|
|
if (node->get_property (X_("Channel"), s)) {
|
|
|
|
uint8_t channel = PBD::atoi (_midi_channel.get_text ());
|
|
|
|
if (channel > 0 && channel < 17) {
|
|
|
|
_midi_channel.set_active (s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node->get_property (X_("Transpose"), s)) {
|
|
|
|
_transpose_output.set_active (s);
|
|
|
|
}
|
2019-12-24 12:15:09 -05:00
|
|
|
if (node->get_property (X_("KeyVelocity"), s)) {
|
|
|
|
_piano_velocity.set_active (s);
|
2019-10-20 14:53:40 -04:00
|
|
|
}
|
2019-12-24 12:15:09 -05:00
|
|
|
if (node->get_property (X_("Octave"), s)) {
|
|
|
|
_piano_octave_key.set_active (s);
|
2019-10-21 09:27:42 -04:00
|
|
|
}
|
2019-12-24 12:15:09 -05:00
|
|
|
if (node->get_property (X_("Range"), s)) {
|
|
|
|
_piano_octave_range.set_active (s);
|
2019-10-21 09:27:42 -04:00
|
|
|
}
|
2019-10-20 14:53:40 -04:00
|
|
|
|
2019-12-18 22:27:54 -05:00
|
|
|
update_velocity_settings ();
|
2019-10-21 09:27:42 -04:00
|
|
|
update_octave_range ();
|
|
|
|
update_octave_key ();
|
2019-10-20 14:53:40 -04:00
|
|
|
}
|
|
|
|
|
2019-10-23 23:13:56 -04:00
|
|
|
bool
|
2019-10-25 08:35:38 -04:00
|
|
|
VirtualKeyboardWindow::on_focus_in_event (GdkEventFocus* ev)
|
2019-10-23 23:13:56 -04:00
|
|
|
{
|
2019-10-24 13:43:46 -04:00
|
|
|
_piano.grab_focus ();
|
2019-10-25 08:35:38 -04:00
|
|
|
return ArdourWindow::on_focus_in_event (ev);
|
2019-10-23 23:13:56 -04:00
|
|
|
}
|
|
|
|
|
2019-10-17 21:50:52 -04:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::on_unmap ()
|
|
|
|
{
|
|
|
|
ArdourWindow::on_unmap ();
|
2019-10-21 10:06:29 -04:00
|
|
|
ARDOUR_UI::instance ()->reset_focus (this);
|
2019-10-17 21:50:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VirtualKeyboardWindow::on_key_press_event (GdkEventKey* ev)
|
|
|
|
{
|
2019-10-25 15:23:27 -04:00
|
|
|
/* try propagate unmodified events first */
|
|
|
|
if ((ev->state & 0xf) == 0) {
|
|
|
|
if (gtk_window_propagate_key_event (gobj(), ev)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 15:54:16 -04:00
|
|
|
_piano.grab_focus ();
|
|
|
|
|
2019-12-15 07:58:03 -05:00
|
|
|
return ARDOUR_UI_UTILS::relay_key_press (ev, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VirtualKeyboardWindow::on_key_release_event (GdkEventKey* ev)
|
|
|
|
{
|
|
|
|
/* try propagate unmodified events first */
|
|
|
|
if ((ev->state & 0xf) == 0) {
|
|
|
|
if (gtk_window_propagate_key_event (gobj(), ev)) {
|
2019-10-25 15:23:27 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-15 07:58:03 -05:00
|
|
|
_piano.grab_focus ();
|
|
|
|
|
|
|
|
return ArdourWindow::on_key_release_event (ev);
|
2019-10-17 21:50:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-10-21 09:27:42 -04:00
|
|
|
VirtualKeyboardWindow::select_keyboard_layout (std::string const& l)
|
2019-10-18 11:26:25 -04:00
|
|
|
{
|
2020-04-07 12:38:33 -04:00
|
|
|
_piano.set_keyboard_layout (PianoKeyBindings::layout (l));
|
2019-10-26 18:05:22 -04:00
|
|
|
_piano.grab_focus ();
|
2019-10-18 11:26:25 -04:00
|
|
|
}
|
|
|
|
|
2019-10-20 23:41:34 -04:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::update_octave_key ()
|
|
|
|
{
|
2019-12-24 12:15:09 -05:00
|
|
|
_piano.set_octave (PBD::atoi (_piano_octave_key.get_text ()));
|
2019-10-24 13:43:46 -04:00
|
|
|
_piano.grab_focus ();
|
2019-10-20 23:41:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::update_octave_range ()
|
|
|
|
{
|
2019-12-24 12:15:09 -05:00
|
|
|
_piano.set_octave_range (PBD::atoi (_piano_octave_range.get_text ()));
|
|
|
|
_piano.set_grand_piano_highlight (PBD::atoi (_piano_octave_range.get_text ()) > 3);
|
2019-10-24 13:43:46 -04:00
|
|
|
_piano.grab_focus ();
|
2019-10-20 23:41:34 -04:00
|
|
|
}
|
|
|
|
|
2019-10-19 20:43:39 -04:00
|
|
|
bool
|
|
|
|
VirtualKeyboardWindow::send_panic_message (GdkEventButton*)
|
|
|
|
{
|
2019-12-26 06:17:20 -05:00
|
|
|
_piano.reset ();
|
2019-10-25 17:52:53 -04:00
|
|
|
uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
|
2019-10-19 20:43:39 -04:00
|
|
|
uint8_t ev[3];
|
|
|
|
ev[0] = MIDI_CMD_CONTROL | channel;
|
|
|
|
ev[1] = MIDI_CTL_SUSTAIN;
|
|
|
|
ev[2] = 0;
|
2019-10-21 10:06:29 -04:00
|
|
|
_session->vkbd_output_port ()->write (ev, 3, 0);
|
2019-10-19 20:43:39 -04:00
|
|
|
ev[1] = MIDI_CTL_ALL_NOTES_OFF;
|
2019-10-21 10:06:29 -04:00
|
|
|
_session->vkbd_output_port ()->write (ev, 3, 0);
|
2019-10-19 20:43:39 -04:00
|
|
|
ev[1] = MIDI_CTL_RESET_CONTROLLERS;
|
2019-10-21 10:06:29 -04:00
|
|
|
_session->vkbd_output_port ()->write (ev, 3, 0);
|
2019-10-19 20:43:39 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-25 06:46:34 -05:00
|
|
|
bool
|
|
|
|
VirtualKeyboardWindow::on_velocity_scroll_event (GdkEventScroll* ev)
|
|
|
|
{
|
|
|
|
int v = PBD::atoi (_piano_velocity.get_text ());
|
|
|
|
switch (ev->direction) {
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
v = std::min (127, v + 1);
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
v = std::max (1, v - 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "%d", v);
|
|
|
|
_piano_velocity.set_active (buf);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-19 20:43:39 -04:00
|
|
|
void
|
2019-12-18 22:27:54 -05:00
|
|
|
VirtualKeyboardWindow::update_velocity_settings ()
|
2019-10-18 11:26:25 -04:00
|
|
|
{
|
2019-12-24 12:15:09 -05:00
|
|
|
int v = PBD::atoi (_piano_velocity.get_text ());
|
|
|
|
_piano.set_velocities (v, v, v);
|
2019-10-18 11:26:25 -04:00
|
|
|
}
|
|
|
|
|
2019-12-18 09:01:17 -05:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::cc_key_changed (size_t i)
|
|
|
|
{
|
2020-04-22 10:20:54 -04:00
|
|
|
_cc_knob[i]->set_tooltip_prefix (string_compose (_("CC-%1: "), _cc_key[i].get_text ()));
|
|
|
|
// TODO update _cc[i]->normal
|
2019-12-18 09:01:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::update_cc (size_t i, int cc)
|
|
|
|
{
|
|
|
|
assert (i < VKBD_NCTRLS);
|
|
|
|
if (cc < 0 || cc > 120) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "%d", cc);
|
|
|
|
_cc_key[i].set_active (buf);
|
|
|
|
}
|
|
|
|
|
2023-06-10 08:59:49 -04:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::velocity_key_event_handler (int v)
|
|
|
|
{
|
|
|
|
if (v < 1 || v > 127) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "%d", v);
|
|
|
|
_piano_velocity.set_active (buf);
|
|
|
|
}
|
|
|
|
|
2019-12-16 09:02:39 -05:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::octave_key_event_handler (bool up)
|
|
|
|
{
|
2019-12-24 12:15:09 -05:00
|
|
|
int k = PBD::atoi (_piano_octave_key.get_text ()) + (up ? 1 : -1);
|
|
|
|
k = std::min (7, std::max (-1, k));
|
|
|
|
char buf[16];
|
|
|
|
sprintf (buf, "%d", k);
|
|
|
|
_piano_octave_key.set_active (buf);
|
2019-12-16 09:02:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::pitch_bend_key_event_handler (int target, bool interpolate)
|
|
|
|
{
|
2019-12-17 10:47:46 -05:00
|
|
|
int cur = _pitch_adjustment.get_value();
|
|
|
|
if (cur == target) {
|
2019-12-16 09:02:39 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (interpolate) {
|
|
|
|
_pitch_bend_target = target;
|
2019-12-17 10:47:46 -05:00
|
|
|
if (!_bender_connection.connected ()) {
|
|
|
|
float tc = _pitch_bend_target == 8192 ? .35 : .51;
|
|
|
|
cur = rintf (cur + tc * (_pitch_bend_target - cur));
|
|
|
|
_pitch_adjustment.set_value (cur);
|
|
|
|
_bender_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &VirtualKeyboardWindow::pitch_bend_timeout), 20 /*ms*/);
|
2019-12-16 09:02:39 -05:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_bender_connection.disconnect ();
|
|
|
|
_pitch_adjustment.set_value (target);
|
|
|
|
_pitch_bend_target = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VirtualKeyboardWindow::pitch_bend_timeout ()
|
|
|
|
{
|
|
|
|
int cur = _pitch_adjustment.get_value();
|
2019-12-17 10:47:46 -05:00
|
|
|
|
|
|
|
/* a spring would be 2nd order with overshoot,
|
|
|
|
* but we assume it's critically damped */
|
|
|
|
float tc = _pitch_bend_target == 8192 ? .35 : .51;
|
|
|
|
cur = rintf (cur + tc * (_pitch_bend_target - cur));
|
|
|
|
if (abs (cur - _pitch_bend_target) < 2) {
|
|
|
|
cur = _pitch_bend_target;
|
2019-12-16 09:02:39 -05:00
|
|
|
}
|
2019-12-17 10:47:46 -05:00
|
|
|
_pitch_adjustment.set_value (cur);
|
|
|
|
return _pitch_bend_target != cur;
|
2019-12-16 09:02:39 -05:00
|
|
|
}
|
|
|
|
|
2019-10-20 12:29:23 -04:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::pitch_slider_adjusted ()
|
|
|
|
{
|
|
|
|
_pitchbend->set_value (_pitch_adjustment.get_value (), PBD::Controllable::NoGroup);
|
2019-12-15 08:04:44 -05:00
|
|
|
pitch_bend_update_tooltip (_pitch_adjustment.get_value ());
|
2019-10-20 12:29:23 -04:00
|
|
|
}
|
|
|
|
|
2019-12-15 08:04:44 -05:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::pitch_bend_update_tooltip (int value)
|
|
|
|
{
|
|
|
|
_pitch_slider_tooltip->set_tip (string_compose (
|
|
|
|
_("Pitchbend: %1\n"
|
|
|
|
"Use mouse-drag for sprung mode,\n"
|
2020-09-13 08:30:12 -04:00
|
|
|
"mouse-wheel for persistent bends.\n"
|
2019-12-15 11:30:25 -05:00
|
|
|
"F1-F4 and arrow-up/down keys jump\n"
|
|
|
|
"to select values."), value));
|
2019-12-15 08:04:44 -05:00
|
|
|
}
|
|
|
|
|
2019-12-18 09:01:17 -05:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::modwheel_slider_adjusted ()
|
|
|
|
{
|
|
|
|
_modwheel->set_value (_modwheel_adjustment.get_value (), PBD::Controllable::NoGroup);
|
|
|
|
modwheel_update_tooltip (_modwheel_adjustment.get_value ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::modwheel_update_tooltip (int value)
|
|
|
|
{
|
|
|
|
_modwheel_tooltip->set_tip (string_compose (_("Modulation: %1"), value));
|
|
|
|
}
|
2019-12-15 08:04:44 -05:00
|
|
|
|
2019-10-18 11:26:25 -04:00
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::note_on_event_handler (int note, int velocity)
|
2019-10-17 21:50:52 -04:00
|
|
|
{
|
2019-10-24 13:43:46 -04:00
|
|
|
_piano.grab_focus ();
|
2019-10-17 21:50:52 -04:00
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-25 17:52:53 -04:00
|
|
|
note += PBD::atoi (_transpose_output.get_text ());
|
2019-10-21 13:31:25 -04:00
|
|
|
if (note < 0 || note > 127) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-25 17:52:53 -04:00
|
|
|
uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
|
2019-10-17 21:50:52 -04:00
|
|
|
uint8_t ev[3];
|
2019-10-20 12:29:23 -04:00
|
|
|
ev[0] = MIDI_CMD_NOTE_ON | channel;
|
2019-10-17 21:50:52 -04:00
|
|
|
ev[1] = note;
|
2019-10-18 11:26:25 -04:00
|
|
|
ev[2] = velocity;
|
2019-10-21 10:06:29 -04:00
|
|
|
_session->vkbd_output_port ()->write (ev, 3, 0);
|
2019-10-17 21:50:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::note_off_event_handler (int note)
|
|
|
|
{
|
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-25 17:52:53 -04:00
|
|
|
note += PBD::atoi (_transpose_output.get_text ());
|
2019-10-21 13:31:25 -04:00
|
|
|
if (note < 0 || note > 127) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-25 17:52:53 -04:00
|
|
|
uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
|
2019-10-17 21:50:52 -04:00
|
|
|
uint8_t ev[3];
|
2019-10-20 12:29:23 -04:00
|
|
|
ev[0] = MIDI_CMD_NOTE_OFF | channel;
|
2019-10-17 21:50:52 -04:00
|
|
|
ev[1] = note;
|
|
|
|
ev[2] = 0;
|
2022-04-20 13:32:19 -04:00
|
|
|
_session->vkbd_output_port ()->write (ev, 3, 1);
|
2019-10-17 21:50:52 -04:00
|
|
|
}
|
2019-10-18 11:26:25 -04:00
|
|
|
|
|
|
|
void
|
2019-12-18 09:01:17 -05:00
|
|
|
VirtualKeyboardWindow::control_change_knob_event_handler (int key, int val)
|
2019-10-18 11:26:25 -04:00
|
|
|
{
|
2019-10-19 20:43:39 -04:00
|
|
|
assert (key >= 0 && key < VKBD_NCTRLS);
|
2019-10-21 10:06:29 -04:00
|
|
|
int ctrl = PBD::atoi (_cc_key[key].get_text ());
|
2019-10-19 20:43:39 -04:00
|
|
|
assert (ctrl > 0 && ctrl < 127);
|
2019-12-18 09:01:17 -05:00
|
|
|
control_change_event_handler (ctrl, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::control_change_event_handler (int ctrl, int val)
|
|
|
|
{
|
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-25 17:52:53 -04:00
|
|
|
uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
|
2019-10-18 11:26:25 -04:00
|
|
|
uint8_t ev[3];
|
2019-10-20 12:29:23 -04:00
|
|
|
ev[0] = MIDI_CMD_CONTROL | channel;
|
2019-12-18 09:01:17 -05:00
|
|
|
ev[1] = ctrl & 0x7f;
|
|
|
|
ev[2] = val & 0x7f;
|
2019-10-21 10:06:29 -04:00
|
|
|
_session->vkbd_output_port ()->write (ev, 3, 0);
|
2019-10-18 11:26:25 -04:00
|
|
|
}
|
2019-10-20 12:29:23 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
VirtualKeyboardWindow::pitch_bend_event_handler (int val)
|
|
|
|
{
|
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-25 17:52:53 -04:00
|
|
|
uint8_t channel = PBD::atoi (_midi_channel.get_text ()) - 1;
|
2019-10-20 12:29:23 -04:00
|
|
|
uint8_t ev[3];
|
|
|
|
ev[0] = MIDI_CMD_BENDER | channel;
|
|
|
|
ev[1] = val & 0x7f;
|
|
|
|
ev[2] = (val >> 7) & 0x7f;
|
2019-10-21 10:06:29 -04:00
|
|
|
_session->vkbd_output_port ()->write (ev, 3, 0);
|
2019-10-20 12:29:23 -04:00
|
|
|
}
|
2019-12-15 07:58:03 -05:00
|
|
|
|
|
|
|
void
|
2023-07-26 15:11:52 -04:00
|
|
|
VirtualKeyboardWindow::pitch_bend_release (int)
|
2019-12-15 07:58:03 -05:00
|
|
|
{
|
|
|
|
_pitch_adjustment.set_value (8192);
|
|
|
|
}
|