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