Prefer key-event dispatch over emulated events for VST plugins.
[ardour.git] / gtk2_ardour / plugin_pin_dialog.h
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #ifndef __gtkardour_plugin_pin_dialog_h__
20 #define __gtkardour_plugin_pin_dialog_h__
21
22 #include <gtkmm/drawingarea.h>
23
24 #include "pbd/stateful.h"
25 #include "pbd/signals.h"
26
27 #include "ardour/plugin_insert.h"
28 #include "ardour/route.h"
29
30 #include <gtkmm/alignment.h>
31 #include <gtkmm/box.h>
32 #include <gtkmm/drawingarea.h>
33 #include <gtkmm/scrolledwindow.h>
34 #include <gtkmm/sizegroup.h>
35
36 #include "gtkmm2ext/persistent_tooltip.h"
37
38 #include "widgets/ardour_button.h"
39 #include "widgets/ardour_dropdown.h"
40 #include "widgets/ardour_fader.h"
41 #include "widgets/slider_controller.h"
42
43 #include "ardour_window.h"
44 #include "io_selector.h"
45
46 class PluginPinWidget : public ARDOUR::SessionHandlePtr, public Gtk::VBox
47 {
48 public:
49         PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert>);
50         ~PluginPinWidget ();
51         void set_session (ARDOUR::Session *);
52 private:
53         typedef enum {
54                 Input,
55                 Sink,
56                 Source,
57                 Output
58         } CtrlType;
59
60         struct _CtrlElem {
61                 _CtrlElem (CtrlType c, ARDOUR::DataType d, uint32_t i, uint32_t p, bool s)
62                         : ct (c), dt (d), id (i), ip (p), sc (s) {}
63                 CtrlType ct;
64                 ARDOUR::DataType dt;
65                 uint32_t id; // port/pin ID
66                 uint32_t ip; // plugin ID (for Sink, Source only);
67                 bool sc; // sidechain
68         };
69
70         typedef boost::shared_ptr<_CtrlElem> CtrlElem;
71
72         struct CtrlWidget {
73                 CtrlWidget (const std::string& n, CtrlType ct, ARDOUR::DataType dt, uint32_t id, uint32_t ip = 0, bool sc = false)
74                         : name (n), x(0), y(0), w (0), h (0), prelight (false)
75                 {
76                         e = CtrlElem (new _CtrlElem (ct, dt, id, ip, sc));
77                 }
78                 std::string name;
79                 double x,y;
80                 double w,h;
81                 bool prelight;
82                 CtrlElem e;
83         };
84
85         typedef std::vector<CtrlWidget> CtrlElemList;
86
87         CtrlElem _selection;
88         CtrlElem _actor;
89         CtrlElem _hover;
90         CtrlElemList _elements;
91         CtrlElem _drag_dst;
92
93         /* cache settings for expose */
94         typedef std::map <uint32_t, ARDOUR::ChanMapping> Mappings;
95         Mappings _in_map;
96         Mappings _out_map;
97         ARDOUR::ChanMapping _thru_map;
98         bool _has_midi_bypass;
99
100
101         Gtk::DrawingArea darea;
102
103         ArdourWidgets::ArdourButton _set_config;
104         ArdourWidgets::ArdourButton _tgl_sidechain;
105         ArdourWidgets::ArdourButton _add_plugin;
106         ArdourWidgets::ArdourButton _del_plugin;
107         ArdourWidgets::ArdourButton _add_input_audio;
108         ArdourWidgets::ArdourButton _del_input_audio;
109         ArdourWidgets::ArdourButton _add_input_midi;
110         ArdourWidgets::ArdourButton _del_input_midi;
111         ArdourWidgets::ArdourButton _add_output_audio;
112         ArdourWidgets::ArdourButton _del_output_audio;
113         ArdourWidgets::ArdourButton _add_output_midi;
114         ArdourWidgets::ArdourButton _del_output_midi;
115         ArdourWidgets::ArdourButton _add_sc_audio;
116         ArdourWidgets::ArdourButton _add_sc_midi;
117
118         ArdourWidgets::ArdourDropdown _out_presets;
119
120         Gtk::Menu reset_menu;
121         Gtk::Menu input_menu;
122         Gtk::Table* _sidechain_tbl;
123         Glib::RefPtr<Gtk::SizeGroup> _pm_size_group;
124
125         void plugin_reconfigured ();
126         void update_element_pos ();
127         void refill_sidechain_table ();
128         void refill_output_presets ();
129
130         void darea_size_request (Gtk::Requisition*);
131         void darea_size_allocate (Gtk::Allocation&);
132         bool darea_expose_event (GdkEventExpose*);
133         bool darea_motion_notify_event (GdkEventMotion*);
134         bool darea_button_press_event (GdkEventButton*);
135         bool darea_button_release_event (GdkEventButton*);
136         bool drag_type_matches (const CtrlElem& ct);
137
138         void start_drag (const CtrlElem&, double, double);
139
140         void draw_io_pin (cairo_t*, const CtrlWidget&);
141         void draw_plugin_pin (cairo_t*, const CtrlWidget&);
142
143         void set_color (cairo_t*, bool);
144         double pin_x_pos (uint32_t, double, double, uint32_t, uint32_t, bool);
145         void draw_connection (cairo_t*, double, double, double, double, bool, bool, bool dashed = false);
146         void draw_connection (cairo_t*, const CtrlWidget&, const CtrlWidget&, bool dashed = false);
147         const CtrlWidget& get_io_ctrl (CtrlType ct, ARDOUR::DataType dt, uint32_t id, uint32_t ip = 0) const;
148
149         static void edge_coordinates (const CtrlWidget& w, double &x, double &y);
150         static std::string port_label (const std::string&, bool);
151
152         void reset_mapping ();
153         void reset_configuration ();
154         void toggle_sidechain ();
155         void connect_sidechain ();
156         void add_remove_plugin_clicked (bool);
157         void add_remove_port_clicked (bool, ARDOUR::DataType);
158         void add_remove_inpin_clicked (bool, ARDOUR::DataType);
159         void add_sidechain_port (ARDOUR::DataType);
160         void select_output_preset (uint32_t n_audio);
161         void handle_input_action (const CtrlElem &, const CtrlElem &);
162         void handle_output_action (const CtrlElem &, const CtrlElem &);
163         void handle_thru_action (const CtrlElem &, const CtrlElem &);
164         bool handle_disconnect (const CtrlElem &, bool no_signal = false);
165         void disconnect_other_outputs (uint32_t skip_pc, ARDOUR::DataType dt, uint32_t id);
166         void disconnect_other_thru (ARDOUR::DataType dt, uint32_t id);
167         void remove_port (boost::weak_ptr<ARDOUR::Port>);
168         void disconnect_port (boost::weak_ptr<ARDOUR::Port>);
169         void connect_port (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Port>);
170         void add_send_from (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Route>);
171         uint32_t add_port_to_table (boost::shared_ptr<ARDOUR::Port>, uint32_t, bool);
172         uint32_t maybe_add_route_to_input_menu (boost::shared_ptr<ARDOUR::Route>, ARDOUR::DataType, boost::weak_ptr<ARDOUR::Port>);
173         void port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Port>);
174
175         bool sc_input_press (GdkEventButton *, boost::weak_ptr<ARDOUR::Port>);
176         bool sc_input_release (GdkEventButton *);
177
178         PBD::ScopedConnectionList _plugin_connections;
179         PBD::ScopedConnection _io_connection;
180         boost::shared_ptr<ARDOUR::PluginInsert> _pi;
181
182         void queue_idle_update ();
183         bool idle_update ();
184
185         void error_message_dialog (std::string const&) const;
186
187         uint32_t _n_plugins;
188         ARDOUR::ChanCount _in, _ins, _out;
189         ARDOUR::ChanCount _sinks, _sources;
190
191         double _bxw2, _bxh2;
192         double _pin_box_size;
193         double _width, _height;
194         double _innerwidth, _margin_x, _margin_y;
195         double _min_width;
196         double _min_height;
197         uint32_t _n_inputs;
198         uint32_t _n_sidechains;
199         bool _position_valid;
200         bool _ignore_updates;
201         ARDOUR::Route* _route () { return static_cast<ARDOUR::Route*> (_pi->owner ()); }
202         IOSelectorWindow *_sidechain_selector;
203
204         bool   _dragging;
205         double _drag_x, _drag_y;
206
207         class Control: public sigc::trackable {
208         public:
209                 Control (boost::shared_ptr<ARDOUR::AutomationControl>, std::string const &);
210                 ~Control ();
211                 Gtk::Alignment box;
212         private:
213                 void slider_adjusted ();
214                 void control_changed ();
215                 void set_tooltip ();
216
217                 boost::weak_ptr<ARDOUR::AutomationControl> _control;
218                 Gtk::Adjustment _adjustment;
219                 ArdourWidgets::HSliderController _slider;
220                 Gtkmm2ext::PersistentTooltip _slider_persistant_tooltip;
221
222                 bool _ignore_ui_adjustment;
223                 sigc::connection timer_connection;
224                 std::string _name;
225         };
226         std::list<Control*> _controls;
227 };
228
229
230 class PluginPinDialog : public ArdourWindow
231 {
232 public:
233         PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert>);
234         PluginPinDialog (boost::shared_ptr<ARDOUR::Route>);
235
236         void set_session (ARDOUR::Session *);
237 private:
238         Gtk::ScrolledWindow* scroller;
239         Gtk::VBox *vbox;
240         typedef boost::shared_ptr<PluginPinWidget> PluginPinWidgetPtr;
241         typedef std::vector<PluginPinWidgetPtr> PluginPinWidgetList;
242
243         void route_going_away ();
244         void route_processors_changed (ARDOUR::RouteProcessorChange);
245         void add_processor (boost::weak_ptr<ARDOUR::Processor>);
246         void map_height (Gtk::Allocation&);
247
248         boost::shared_ptr<ARDOUR::Route> _route;
249         PluginPinWidgetList ppw;
250         PBD::ScopedConnectionList _route_connections;
251         bool _height_mapped;
252 };
253
254 #endif