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 #ifndef _virtual_keyboard_window_h_
20 #define _virtual_keyboard_window_h_
22 #include <gtkmm/box.h>
23 #include <gtkmm/spinbutton.h>
25 #include "pbd/controllable.h"
26 #include "pbd/signals.h"
28 #include "gtkmm2ext/persistent_tooltip.h"
30 #include "widgets/ardour_button.h"
31 #include "widgets/ardour_dropdown.h"
32 #include "widgets/ardour_knob.h"
33 #include "widgets/slider_controller.h"
35 #include "ardour_window.h"
36 #include "gtk_pianokeyboard.h"
42 class VKBDControl : public PBD::Controllable
45 VKBDControl (const std::string& name, double normal = 127, double upper = 127)
46 : PBD::Controllable (name, Flag (0))
53 /* Controllable API */
54 void set_value (double v, PBD::Controllable::GroupControlDisposition gcd)
57 _value = std::max (_lower, std::min (_upper, v));
58 Changed (true, gcd); /* EMIT SIGNAL */
59 ValueChanged ((int)_value); /* EMIT SIGNAL */
63 std::string get_user_string () const
66 sprintf (buf, "%.0f", get_value ());
67 return std::string (buf);
70 double get_value () const { return _value; }
71 double lower () const { return _lower; }
72 double upper () const { return _upper; }
73 double normal () const { return _normal; }
75 PBD::Signal1<void, int> ValueChanged;
84 class VirtualKeyboardWindow : public ArdourWindow
87 VirtualKeyboardWindow ();
88 ~VirtualKeyboardWindow ();
90 void set_session (ARDOUR::Session*);
92 XMLNode& get_state ();
93 void set_state (const XMLNode&);
96 static void _note_on_event_handler (GtkWidget*, int note, int vel, gpointer arg)
98 static_cast<VirtualKeyboardWindow*> (arg)->note_on_event_handler (note, vel);
101 static void _note_off_event_handler (GtkWidget*, int note, gpointer arg)
103 static_cast<VirtualKeyboardWindow*> (arg)->note_off_event_handler (note);
107 bool on_key_press_event (GdkEventKey*);
109 void note_on_event_handler (int, int);
110 void note_off_event_handler (int);
111 void control_change_event_handler (int, int);
112 void pitch_bend_event_handler (int);
114 void select_keyboard_layout (std::string const&);
115 void update_velocity_settings (int);
116 void update_octave_key ();
117 void update_octave_range ();
119 void update_sensitivity ();
120 void pitch_slider_adjusted ();
121 bool toggle_config (GdkEventButton*);
122 bool toggle_bankpatch (GdkEventButton*);
123 bool toggle_yaxis_velocity (GdkEventButton*);
124 bool toggle_highlight_piano (GdkEventButton*);
125 bool toggle_highlight_key (GdkEventButton*);
126 bool toggle_note_label (GdkEventButton*);
127 bool send_panic_message (GdkEventButton*);
129 PianoKeyboard* _piano;
130 Gtk::Widget* _pianomm;
131 Gtk::SpinButton _piano_channel;
133 Gtk::SpinButton _bank_msb;
134 Gtk::SpinButton _bank_lsb;
135 Gtk::SpinButton _patchpgm;
140 ArdourWidgets::ArdourButton _cfg_display;
141 ArdourWidgets::ArdourButton _pgm_display;
142 ArdourWidgets::ArdourButton _yaxis_velocity;
143 ArdourWidgets::ArdourButton _highlight_grand_piano;
144 ArdourWidgets::ArdourButton _highlight_key_range;
145 ArdourWidgets::ArdourButton _show_note_label;
146 ArdourWidgets::ArdourButton _send_panic;
147 ArdourWidgets::ArdourDropdown _keyboard_layout;
149 Gtk::SpinButton _piano_key_velocity;
150 Gtk::SpinButton _piano_min_velocity;
151 Gtk::SpinButton _piano_max_velocity;
153 Gtk::SpinButton _piano_octave_key;
154 Gtk::SpinButton _piano_octave_range;
156 boost::shared_ptr<VKBDControl> _pitchbend;
157 Gtk::Adjustment _pitch_adjustment;
158 ArdourWidgets::VSliderController* _pitch_slider;
159 Gtkmm2ext::PersistentTooltip* _pitch_slider_tooltip;
161 #define VKBD_NCTRLS 8
163 boost::shared_ptr<VKBDControl> _cc[VKBD_NCTRLS];
164 ArdourWidgets::ArdourKnob* _cc_knob[VKBD_NCTRLS];
165 ArdourWidgets::ArdourDropdown _cc_key[VKBD_NCTRLS];
167 PBD::ScopedConnectionList _cc_connections;