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