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