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