fix connection updates
[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 "ardour_button.h"
31 #include "ardour_window.h"
32 #include "io_selector.h"
33
34 class PluginPinDialog : public ArdourWindow
35 {
36 public:
37         PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert>);
38         ~PluginPinDialog ();
39
40 private:
41         typedef enum {
42                 Input,
43                 Sink,
44                 Source,
45                 Output
46         } CtrlType;
47
48         struct _CtrlElem {
49                 _CtrlElem (CtrlType c, ARDOUR::DataType d, uint32_t i, uint32_t p, bool s)
50                         : ct (c), dt (d), id (i), ip (p), sc (s) {}
51                 CtrlType ct;
52                 ARDOUR::DataType dt;
53                 uint32_t id; // port/pin ID
54                 uint32_t ip; // plugin ID (for Sink, Source only);
55                 bool sc; // sidechain
56         };
57
58         typedef boost::shared_ptr<_CtrlElem> CtrlElem;
59
60         struct CtrlWidget {
61                 CtrlWidget (CtrlType ct, ARDOUR::DataType dt, uint32_t id, uint32_t ip = 0, bool sc = false)
62                         : x(0), y(0), w (0), h (0), prelight (false)
63                 {
64                         e = CtrlElem (new _CtrlElem (ct, dt, id, ip, sc));
65                 }
66                 double x,y;
67                 double w,h;
68                 bool prelight;
69                 CtrlElem e;
70         };
71
72         typedef std::vector<CtrlWidget> CtrlElemList;
73
74         CtrlElem _selection;
75         CtrlElem _actor;
76         CtrlElem _hover;
77         CtrlElemList _elements;
78
79
80         Gtk::DrawingArea darea;
81         ArdourButton _rst_config;
82         ArdourButton _rst_mapping;
83         ArdourButton _tgl_sidechain;
84         ArdourButton _add_plugin;
85         ArdourButton _del_plugin;
86         ArdourButton _add_output_audio;
87         ArdourButton _del_output_audio;
88         ArdourButton _add_output_midi;
89         ArdourButton _del_output_midi;
90         ArdourButton _add_sc_audio;
91         ArdourButton _add_sc_midi;
92
93         Gtk::Menu input_menu;
94         Gtk::Table* _sidechain_tbl;
95         Glib::RefPtr<Gtk::SizeGroup> _pm_size_group;
96         Glib::RefPtr<Gtk::SizeGroup> _sc_size_group;
97
98         void plugin_reconfigured ();
99         void update_element_pos ();
100         void refill_sidechain_table ();
101
102         void darea_size_request (Gtk::Requisition*);
103         void darea_size_allocate (Gtk::Allocation&);
104         bool darea_expose_event (GdkEventExpose*);
105         bool darea_motion_notify_event (GdkEventMotion*);
106         bool darea_button_press_event (GdkEventButton*);
107         bool darea_button_release_event (GdkEventButton*);
108
109         void draw_io_pin (cairo_t*, const CtrlWidget&);
110         void draw_plugin_pin (cairo_t*, const CtrlWidget&);
111
112         void set_color (cairo_t*, bool);
113         double pin_x_pos (uint32_t, double, double, uint32_t, uint32_t, bool);
114         void draw_connection (cairo_t*, double, double, double, double, bool, bool, bool dashed = false);
115         void draw_connection (cairo_t*, const CtrlWidget&, const CtrlWidget&, bool dashed = false);
116         const CtrlWidget& get_io_ctrl (CtrlType ct, ARDOUR::DataType dt, uint32_t id, uint32_t ip = 0) const;
117         static void edge_coordinates (const CtrlWidget& w, double &x, double &y);
118
119         void reset_mapping ();
120         void reset_configuration ();
121         void toggle_sidechain ();
122         void connect_sidechain ();
123         void add_remove_plugin_clicked (bool);
124         void add_remove_port_clicked (bool, ARDOUR::DataType);
125         void add_sidechain_port (ARDOUR::DataType);
126         void handle_input_action (const CtrlElem &, const CtrlElem &);
127         void handle_output_action (const CtrlElem &, const CtrlElem &);
128         void handle_disconnect (const CtrlElem &);
129         void add_port_to_table (boost::shared_ptr<ARDOUR::Port>, uint32_t, bool);
130         void remove_port (boost::weak_ptr<ARDOUR::Port>);
131         void disconnect_port (boost::weak_ptr<ARDOUR::Port>);
132         void connect_port (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Port>);
133         uint32_t maybe_add_route_to_input_menu (boost::shared_ptr<ARDOUR::Route>, ARDOUR::DataType, boost::weak_ptr<ARDOUR::Port>);
134         void port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Port>);
135
136         bool sc_input_press (GdkEventButton *, boost::weak_ptr<ARDOUR::Port>);
137         bool sc_input_release (GdkEventButton *);
138
139         PBD::ScopedConnectionList _plugin_connections;
140         PBD::ScopedConnection _io_connection;
141         boost::shared_ptr<ARDOUR::PluginInsert> _pi;
142
143         uint32_t _n_plugins;
144         ARDOUR::ChanCount _in, _ins, _out;
145         ARDOUR::ChanCount _sinks, _sources;
146
147         double _bxw2, _bxh2;
148         double _pin_box_size;
149         double _width, _height;
150         double _innerwidth, _margin_x, _margin_y;
151         double _min_width;
152         double _min_height;
153         uint32_t _n_inputs;
154         uint32_t _n_sidechains;
155         bool _position_valid;
156         bool _ignore_updates;
157         ARDOUR::Route* _route () { return static_cast<ARDOUR::Route*> (_pi->owner ()); }
158         IOSelectorWindow *_sidechain_selector;
159 };
160
161 #endif