2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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.
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.
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.
19 #ifndef __gtkardour_plugin_pin_dialog_h__
20 #define __gtkardour_plugin_pin_dialog_h__
22 #include <gtkmm/drawingarea.h>
24 #include "pbd/stateful.h"
25 #include "pbd/signals.h"
27 #include "ardour/plugin_insert.h"
28 #include "ardour/route.h"
30 #include "gtkmm2ext/pixfader.h"
31 #include "gtkmm2ext/persistent_tooltip.h"
32 #include "gtkmm2ext/slider_controller.h"
34 #include "ardour_button.h"
35 #include "ardour_dropdown.h"
36 #include "ardour_window.h"
37 #include "io_selector.h"
39 class PluginPinDialog : public ArdourWindow
42 PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert>);
44 void set_session (ARDOUR::Session *);
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) {}
58 uint32_t id; // port/pin ID
59 uint32_t ip; // plugin ID (for Sink, Source only);
63 typedef boost::shared_ptr<_CtrlElem> CtrlElem;
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)
69 e = CtrlElem (new _CtrlElem (ct, dt, id, ip, sc));
78 typedef std::vector<CtrlWidget> CtrlElemList;
83 CtrlElemList _elements;
86 /* cache settings for expose */
87 typedef std::map <uint32_t, ARDOUR::ChanMapping> Mappings;
90 ARDOUR::ChanMapping _thru_map;
91 bool _has_midi_bypass;
94 Gtk::DrawingArea darea;
95 ArdourButton _set_config;
96 ArdourButton _tgl_sidechain;
97 ArdourButton _add_plugin;
98 ArdourButton _del_plugin;
99 ArdourButton _add_input_audio;
100 ArdourButton _del_input_audio;
101 ArdourButton _add_input_midi;
102 ArdourButton _del_input_midi;
103 ArdourButton _add_output_audio;
104 ArdourButton _del_output_audio;
105 ArdourButton _add_output_midi;
106 ArdourButton _del_output_midi;
107 ArdourButton _add_sc_audio;
108 ArdourButton _add_sc_midi;
110 ArdourDropdown _out_presets;
112 Gtk::Menu reset_menu;
113 Gtk::Menu input_menu;
114 Gtk::Table* _sidechain_tbl;
115 Glib::RefPtr<Gtk::SizeGroup> _pm_size_group;
117 void plugin_reconfigured ();
118 void update_element_pos ();
119 void refill_sidechain_table ();
120 void refill_output_presets ();
122 void darea_size_request (Gtk::Requisition*);
123 void darea_size_allocate (Gtk::Allocation&);
124 bool darea_expose_event (GdkEventExpose*);
125 bool darea_motion_notify_event (GdkEventMotion*);
126 bool darea_button_press_event (GdkEventButton*);
127 bool darea_button_release_event (GdkEventButton*);
128 bool drag_type_matches (const CtrlElem& ct);
130 void start_drag (const CtrlElem&, double, double);
132 void draw_io_pin (cairo_t*, const CtrlWidget&);
133 void draw_plugin_pin (cairo_t*, const CtrlWidget&);
135 void set_color (cairo_t*, bool);
136 double pin_x_pos (uint32_t, double, double, uint32_t, uint32_t, bool);
137 void draw_connection (cairo_t*, double, double, double, double, bool, bool, bool dashed = false);
138 void draw_connection (cairo_t*, const CtrlWidget&, const CtrlWidget&, bool dashed = false);
139 const CtrlWidget& get_io_ctrl (CtrlType ct, ARDOUR::DataType dt, uint32_t id, uint32_t ip = 0) const;
141 static void edge_coordinates (const CtrlWidget& w, double &x, double &y);
142 static std::string port_label (const std::string&, bool);
144 void reset_mapping ();
145 void reset_configuration ();
146 void toggle_sidechain ();
147 void connect_sidechain ();
148 void add_remove_plugin_clicked (bool);
149 void add_remove_port_clicked (bool, ARDOUR::DataType);
150 void add_remove_inpin_clicked (bool, ARDOUR::DataType);
151 void add_sidechain_port (ARDOUR::DataType);
152 void select_output_preset (uint32_t n_audio);
153 void handle_input_action (const CtrlElem &, const CtrlElem &);
154 void handle_output_action (const CtrlElem &, const CtrlElem &);
155 void handle_thru_action (const CtrlElem &, const CtrlElem &);
156 bool handle_disconnect (const CtrlElem &, bool no_signal = false);
157 void disconnect_other_outputs (uint32_t skip_pc, ARDOUR::DataType dt, uint32_t id);
158 void disconnect_other_thru (ARDOUR::DataType dt, uint32_t id);
159 void remove_port (boost::weak_ptr<ARDOUR::Port>);
160 void disconnect_port (boost::weak_ptr<ARDOUR::Port>);
161 void connect_port (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Port>);
162 void add_send_from (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Route>);
163 uint32_t add_port_to_table (boost::shared_ptr<ARDOUR::Port>, uint32_t, bool);
164 uint32_t maybe_add_route_to_input_menu (boost::shared_ptr<ARDOUR::Route>, ARDOUR::DataType, boost::weak_ptr<ARDOUR::Port>);
165 void port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port>, boost::weak_ptr<ARDOUR::Port>);
167 bool sc_input_press (GdkEventButton *, boost::weak_ptr<ARDOUR::Port>);
168 bool sc_input_release (GdkEventButton *);
170 PBD::ScopedConnectionList _plugin_connections;
171 PBD::ScopedConnection _io_connection;
172 boost::shared_ptr<ARDOUR::PluginInsert> _pi;
174 void queue_idle_update ();
178 ARDOUR::ChanCount _in, _ins, _out;
179 ARDOUR::ChanCount _sinks, _sources;
182 double _pin_box_size;
183 double _width, _height;
184 double _innerwidth, _margin_x, _margin_y;
188 uint32_t _n_sidechains;
189 bool _position_valid;
190 bool _ignore_updates;
191 ARDOUR::Route* _route () { return static_cast<ARDOUR::Route*> (_pi->owner ()); }
192 IOSelectorWindow *_sidechain_selector;
195 double _drag_x, _drag_y;
197 class Control: public sigc::trackable {
199 Control (boost::shared_ptr<ARDOUR::AutomationControl>, std::string const &);
203 void slider_adjusted ();
204 void control_changed ();
207 boost::weak_ptr<ARDOUR::AutomationControl> _control;
208 Gtk::Adjustment _adjustment;
209 Gtkmm2ext::HSliderController _slider;
210 Gtkmm2ext::PersistentTooltip _slider_persistant_tooltip;
212 bool _ignore_ui_adjustment;
213 sigc::connection timer_connection;
216 std::list<Control*> _controls;