NO-OP: whitespace
[ardour.git] / gtk2_ardour / virtual_keyboard_window.h
1 /*
2  * Copyright (C) 2019 Robin Gareus <robin@gareus.org>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #ifndef _virtual_keyboard_window_h_
20 #define _virtual_keyboard_window_h_
21
22 #include <gtkmm/box.h>
23 #include <gtkmm/spinbutton.h>
24
25 #include "pbd/controllable.h"
26 #include "pbd/signals.h"
27
28 #include "gtkmm2ext/persistent_tooltip.h"
29
30 #include "widgets/ardour_button.h"
31 #include "widgets/ardour_dropdown.h"
32 #include "widgets/ardour_knob.h"
33 #include "widgets/slider_controller.h"
34
35 #include "ardour_window.h"
36 #include "gtk_pianokeyboard.h"
37
38 namespace ARDOUR {
39         class Session;
40 }
41
42 class VKBDControl : public PBD::Controllable
43 {
44 public:
45         VKBDControl (const std::string& name, double normal = 127, double upper = 127)
46                 : PBD::Controllable (name, Flag (0))
47                 , _lower (0)
48                 , _upper (upper)
49                 , _normal (normal)
50                 , _value (normal)
51         {}
52
53         /* Controllable API */
54         void set_value (double v, PBD::Controllable::GroupControlDisposition gcd)
55         {
56                 if (v != _value) {
57                         _value = std::max (_lower, std::min (_upper, v));
58                         Changed (true, gcd);        /* EMIT SIGNAL */
59                         ValueChanged ((int)_value); /* EMIT SIGNAL */
60                 }
61         }
62
63         std::string get_user_string () const
64         {
65                 char buf[32];
66                 sprintf (buf, "%.0f", get_value ());
67                 return std::string (buf);
68         }
69
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; }
74
75         PBD::Signal1<void, int> ValueChanged;
76
77 protected:
78         double _lower;
79         double _upper;
80         double _normal;
81         double _value;
82 };
83
84 class VirtualKeyboardWindow : public ArdourWindow
85 {
86 public:
87         VirtualKeyboardWindow ();
88         ~VirtualKeyboardWindow ();
89
90         void set_session (ARDOUR::Session*);
91
92         XMLNode& get_state ();
93         void     set_state (const XMLNode&);
94
95 private:
96         static void _note_on_event_handler (GtkWidget*, int note, int vel, gpointer arg)
97         {
98                 static_cast<VirtualKeyboardWindow*> (arg)->note_on_event_handler (note, vel);
99         }
100
101         static void _note_off_event_handler (GtkWidget*, int note, gpointer arg)
102         {
103                 static_cast<VirtualKeyboardWindow*> (arg)->note_off_event_handler (note);
104         }
105
106         void on_unmap ();
107         bool on_key_press_event (GdkEventKey*);
108
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);
113
114         void select_keyboard_layout (std::string const&);
115         void update_velocity_settings (int);
116         void update_octave_key ();
117         void update_octave_range ();
118         void bank_patch ();
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*);
128
129         PianoKeyboard*  _piano;
130         Gtk::Widget*    _pianomm;
131         Gtk::SpinButton _piano_channel;
132
133         Gtk::SpinButton _bank_msb;
134         Gtk::SpinButton _bank_lsb;
135         Gtk::SpinButton _patchpgm;
136
137         Gtk::HBox* _cfg_box;
138         Gtk::HBox* _pgm_box;
139
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;
148
149         Gtk::SpinButton _piano_key_velocity;
150         Gtk::SpinButton _piano_min_velocity;
151         Gtk::SpinButton _piano_max_velocity;
152
153         Gtk::SpinButton _piano_octave_key;
154         Gtk::SpinButton _piano_octave_range;
155
156         boost::shared_ptr<VKBDControl>    _pitchbend;
157         Gtk::Adjustment                   _pitch_adjustment;
158         ArdourWidgets::VSliderController* _pitch_slider;
159         Gtkmm2ext::PersistentTooltip*     _pitch_slider_tooltip;
160
161 #define VKBD_NCTRLS 8
162
163         boost::shared_ptr<VKBDControl> _cc[VKBD_NCTRLS];
164         ArdourWidgets::ArdourKnob*     _cc_knob[VKBD_NCTRLS];
165         ArdourWidgets::ArdourDropdown  _cc_key[VKBD_NCTRLS];
166
167         PBD::ScopedConnectionList _cc_connections;
168 };
169
170 #endif