52363c2232d0f01d3ba5105cec42fe1c2eda1ca5
[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 _edt_sidechain;
85         ArdourButton _add_plugin;
86         ArdourButton _del_plugin;
87         ArdourButton _add_output_audio;
88         ArdourButton _del_output_audio;
89         ArdourButton _add_output_midi;
90         ArdourButton _del_output_midi;
91         Glib::RefPtr<Gtk::SizeGroup> _pm_size_group;
92
93         void plugin_reconfigured ();
94         void update_element_pos ();
95
96         void darea_size_request (Gtk::Requisition*);
97         void darea_size_allocate (Gtk::Allocation&);
98         bool darea_expose_event (GdkEventExpose*);
99         bool darea_motion_notify_event (GdkEventMotion*);
100         bool darea_button_press_event (GdkEventButton*);
101         bool darea_button_release_event (GdkEventButton*);
102
103         void draw_io_pin (cairo_t*, const CtrlWidget&);
104         void draw_plugin_pin (cairo_t*, const CtrlWidget&);
105
106         void set_color (cairo_t*, bool);
107         double pin_x_pos (uint32_t, double, double, uint32_t, uint32_t, bool);
108         void draw_connection (cairo_t*, double, double, double, double, bool, bool, bool dashed = false);
109         void draw_connection (cairo_t*, const CtrlWidget&, const CtrlWidget&, bool dashed = false);
110         const CtrlWidget& get_io_ctrl (CtrlType ct, ARDOUR::DataType dt, uint32_t id, uint32_t ip = 0) const;
111         static void edge_coordinates (const CtrlWidget& w, double &x, double &y);
112
113         void reset_mapping ();
114         void reset_configuration ();
115         void toggle_sidechain ();
116         void connect_sidechain ();
117         void add_remove_plugin_clicked (bool);
118         void add_remove_port_clicked (bool, ARDOUR::DataType);
119         void handle_input_action (const CtrlElem &, const CtrlElem &);
120         void handle_output_action (const CtrlElem &, const CtrlElem &);
121         void handle_disconnect (const CtrlElem &);
122
123         PBD::ScopedConnectionList _plugin_connections;
124         boost::shared_ptr<ARDOUR::PluginInsert> _pi;
125
126         uint32_t _n_plugins;
127         ARDOUR::ChanCount _in, _ins, _out;
128         ARDOUR::ChanCount _sinks, _sources;
129
130         double _bxw2, _bxh2;
131         double _pin_box_size;
132         double _width, _height;
133         double _innerwidth, _margin_x, _margin_y;
134         double _min_width;
135         double _min_height;
136         uint32_t _n_inputs;
137         uint32_t _n_sidechains;
138         bool _position_valid;
139         bool _ignore_updates;
140         ARDOUR::Route* _route () { return static_cast<ARDOUR::Route*> (_pi->owner ()); }
141         IOSelectorWindow *_sidechain_selector;
142 };
143
144 #endif