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 "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 bool on_focus_in_event (GdkEventFocus*);
100 bool on_key_press_event (GdkEventKey*);
101 bool on_key_release_event (GdkEventKey*);
103 void parameter_changed (std::string const&);
105 void note_on_event_handler (int, int);
106 void note_off_event_handler (int);
107 void control_change_event_handler (int, int);
108 void control_change_knob_event_handler (int, int);
110 void modwheel_update_tooltip (int);
111 void modwheel_slider_adjusted ();
113 void octave_key_event_handler (bool);
114 void pitch_bend_key_event_handler (int, bool);
115 bool pitch_bend_timeout ();
117 void pitch_bend_event_handler (int);
118 void pitch_bend_release ();
119 void pitch_bend_update_tooltip (int);
120 void pitch_slider_adjusted ();
122 void select_keyboard_layout (std::string const&);
123 void update_velocity_settings ();
124 void update_octave_key ();
125 void update_octave_range ();
126 void cc_key_changed (size_t);
127 void update_cc (size_t, int);
128 bool send_panic_message (GdkEventButton*);
129 bool on_velocity_scroll_event (GdkEventScroll*);
131 APianoKeyboard _piano;
133 ArdourWidgets::ArdourDropdown _midi_channel;
134 ArdourWidgets::ArdourDropdown _piano_velocity;
135 ArdourWidgets::ArdourDropdown _piano_octave_key;
136 ArdourWidgets::ArdourDropdown _piano_octave_range;
137 ArdourWidgets::ArdourDropdown _transpose_output;
138 ArdourWidgets::ArdourButton _send_panic;
140 boost::shared_ptr<VKBDControl> _pitchbend;
141 Gtk::Adjustment _pitch_adjustment;
142 ArdourWidgets::VSliderController* _pitch_slider;
143 Gtkmm2ext::PersistentTooltip* _pitch_slider_tooltip;
145 boost::shared_ptr<VKBDControl> _modwheel;
146 Gtk::Adjustment _modwheel_adjustment;
147 ArdourWidgets::VSliderController* _modwheel_slider;
148 Gtkmm2ext::PersistentTooltip* _modwheel_tooltip;
149 #define VKBD_NCTRLS 4
151 boost::shared_ptr<VKBDControl> _cc[VKBD_NCTRLS];
152 ArdourWidgets::ArdourKnob* _cc_knob[VKBD_NCTRLS];
153 ArdourWidgets::ArdourDropdown _cc_key[VKBD_NCTRLS];
155 PBD::ScopedConnectionList _cc_connections;
157 sigc::connection _bender_connection;
158 int _pitch_bend_target;