2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2011 Paul Davis
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <gtkmm/table.h>
21 #include <gtkmm/frame.h>
22 #include <gtkmm/box.h>
23 #include <gtkmm/label.h>
25 #include "pbd/replace_all.h"
27 #include "gtkmm2ext/utils.h"
28 #include "gtkmm2ext/rgb_macros.h"
30 #include "ardour/audioengine.h"
31 #include "ardour/plugin.h"
32 #include "ardour/port.h"
33 #include "ardour/session.h"
35 #include "plugin_pin_dialog.h"
36 #include "gui_thread.h"
38 #include "ui_config.h"
42 using namespace ARDOUR;
46 using namespace Gtkmm2ext;
48 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
49 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
50 , _set_config (_("Configure"), ArdourButton::led_default_elements)
51 , _tgl_sidechain (_("Side Chain"), ArdourButton::led_default_elements)
52 , _add_plugin (_("+"))
53 , _del_plugin (_("-"))
54 , _add_output_audio (_("+"))
55 , _del_output_audio (_("-"))
56 , _add_output_midi (_("+"))
57 , _del_output_midi (_("-"))
58 , _add_sc_audio (_("Audio"))
59 , _add_sc_midi (_("MIDI"))
71 , _position_valid (false)
72 , _ignore_updates (false)
73 , _sidechain_selector (0)
75 assert (pi->owner ()); // Route
77 _pi->PluginIoReConfigure.connect (
78 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context ()
81 _pi->PluginMapChanged.connect (
82 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context ()
85 _pi->PluginConfigChanged.connect (
86 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context ()
89 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
90 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
91 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
93 _tgl_sidechain.set_name ("pinrouting sidechain");
94 _set_config.set_name ("pinrouting custom");
96 Menu_Helpers::MenuList& citems = reset_menu.items();
97 reset_menu.set_name ("ArdourContextMenu");
99 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinDialog::reset_mapping)));
101 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
102 _add_plugin.set_tweaks (ArdourButton::Square);
103 _del_plugin.set_tweaks (ArdourButton::Square);
104 _pm_size_group->add_widget (_add_plugin);
105 _pm_size_group->add_widget (_del_plugin);
106 _pm_size_group->add_widget (_add_output_audio);
107 _pm_size_group->add_widget (_del_output_audio);
108 _pm_size_group->add_widget (_add_output_midi);
109 _pm_size_group->add_widget (_del_output_midi);
114 VBox* tl = manage (new VBox ());
115 tl->set_border_width (2);
118 VBox* tr = manage (new VBox ());
119 tr->set_border_width (2);
123 tl->pack_start (_set_config, false, false);
124 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
126 box = manage (new HBox ());
127 box->set_border_width (2);
128 box->pack_start (_add_plugin, true, false);
129 box->pack_start (_del_plugin, true, false);
130 f = manage (new Frame());
131 f->set_label (_("Instances"));
133 tl->pack_start (*f, false, false);
135 box = manage (new HBox ());
136 box->set_border_width (2);
137 box->pack_start (_add_output_audio, true, false);
138 box->pack_start (_del_output_audio, true, false);
139 f = manage (new Frame());
140 f->set_label (_("Audio Out"));
142 tl->pack_start (*f, false, false);
144 box = manage (new HBox ());
145 box->set_border_width (2);
146 box->pack_start (_add_output_midi, true, false);
147 box->pack_start (_del_output_midi, true, false);
148 f = manage (new Frame());
149 f->set_label (_("MIDI Out"));
151 tl->pack_start (*f, false, false);
155 _sidechain_tbl = manage (new Gtk::Table ());
156 _sidechain_tbl->set_spacings (2);
158 tr->pack_start (_tgl_sidechain, false, false);
159 tr->pack_start (*_sidechain_tbl, true, true);
161 box = manage (new VBox ());
162 box->set_border_width (2);
163 box->set_spacing (2);
164 box->pack_start (_add_sc_audio, false, false);
165 box->pack_start (_add_sc_midi , false, false);
166 f = manage (new Frame());
167 f->set_label (_("Add Port"));
170 tr->pack_start (*f, false, false);
173 HBox* hbox = manage (new HBox ());
174 hbox->set_spacing (4);
175 hbox->pack_start (*tl, false, false);
176 hbox->pack_start (darea, true, true);
177 hbox->pack_start (*tr, false, false);
179 VBox* vbox = manage (new VBox ());
180 vbox->pack_start (*hbox, true, true);
181 set_border_width (4);
185 plugin_reconfigured ();
187 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
188 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_request));
189 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_allocate));
190 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event));
191 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_press_event));
192 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_release_event));
193 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_motion_notify_event));
195 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::toggle_sidechain));
197 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::reset_configuration));
198 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), true));
199 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), false));
201 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::AUDIO));
202 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::AUDIO));
203 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::MIDI));
204 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::MIDI));
205 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::AUDIO));
206 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::MIDI));
208 AudioEngine::instance()->PortConnectedOrDisconnected.connect (
209 _io_connection, invalidator (*this), boost::bind (&PluginPinDialog::port_connected_or_disconnected, this, _1, _3), gui_context ()
213 PluginPinDialog::~PluginPinDialog ()
215 delete _sidechain_selector;
219 PluginPinDialog::plugin_reconfigured ()
221 ENSURE_GUI_THREAD (*this, &PluginPinDialog::plugin_reconfigured);
222 if (_ignore_updates) {
225 _n_plugins = _pi->get_count ();
226 _pi->configured_io (_in, _out);
227 _ins = _pi->internal_streams (); // with sidechain
228 _sinks = _pi->natural_input_streams ();
229 _sources = _pi->natural_output_streams ();
231 _tgl_sidechain.set_active (_pi->has_sidechain ());
232 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
233 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
235 if (_pi->custom_cfg ()) {
236 _set_config.set_active (true);
237 _add_plugin.set_sensitive (true);
238 _add_output_audio.set_sensitive (true);
239 _add_output_midi.set_sensitive (true);
240 _del_plugin.set_sensitive (_n_plugins > 1);
241 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
242 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
244 _set_config.set_active (false);
245 _add_plugin.set_sensitive (false);
246 _add_output_audio.set_sensitive (false);
247 _add_output_midi.set_sensitive (false);
248 _del_plugin.set_sensitive (false);
249 _del_output_audio.set_sensitive (false);
250 _del_output_midi.set_sensitive (false);
253 if (!_pi->has_sidechain () && _sidechain_selector) {
254 delete _sidechain_selector;
255 _sidechain_selector = 0;
258 refill_sidechain_table ();
260 /* update elements */
267 _n_inputs = _n_sidechains = 0;
269 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
270 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
271 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
272 bool sidechain = id >= _in.get (dt) ? true : false;
279 CtrlWidget cw (CtrlWidget (Input, dt, id, 0, sidechain));
280 _elements.push_back (cw);
283 for (uint32_t i = 0; i < _out.n_total (); ++i) {
284 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
285 _elements.push_back (CtrlWidget (Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
288 for (uint32_t n = 0; n < _n_plugins; ++n) {
289 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
290 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
291 DataType dt (_sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
292 int idx = (i < _sinks.n_midi ()) ? i : i - _sinks.n_midi ();
293 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
294 CtrlWidget cw (CtrlWidget (Sink, dt, i, n, iod.is_sidechain));
295 _elements.push_back (cw);
297 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
298 _elements.push_back (CtrlWidget (Source, (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO), i, n));
302 /* calc minimum size */
303 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
304 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
305 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
306 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
307 min_width = std::max ((uint32_t)300, min_width);
309 min_width = 50 + 10 * ceilf (min_width / 10.f);
311 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
312 min_height = std::max ((uint32_t)200, min_height);
313 min_height = 4 * ceilf (min_height / 4.f);
315 if (min_width != _min_width || min_height != _min_height) {
316 _min_width = min_width;
317 _min_height = min_height;
318 darea.queue_resize ();
321 _position_valid = false;
326 PluginPinDialog::refill_sidechain_table ()
328 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
329 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
332 _sidechain_tbl->resize (1, 1);
333 if (!_pi->has_sidechain () && _sidechain_selector) {
336 boost::shared_ptr<IO> io = _pi->sidechain_input ();
342 PortSet& p (io->ports ());
343 bool can_remove = p.num_ports () > 1;
344 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i, ++r) {
345 add_port_to_table (*i, r, can_remove);
347 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i, ++r) {
348 add_port_to_table (*i, r, can_remove);
350 _sidechain_tbl->show_all ();
354 PluginPinDialog::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
357 std::string tip = p->name ();
358 std::vector<std::string> cns;
359 p->get_connections (cns);
361 // TODO proper labels, see MixerStrip::update_io_button()
362 if (cns.size () == 0) {
364 } else if (cns.size () > 1) {
370 if (lbl.find ("system:") == 0) {
371 lbl = AudioEngine::instance ()->get_pretty_name_by_name (lbl);
373 lbl = cns[0].substr (7);
377 for (std::vector<std::string>::const_iterator i = cns.begin(); i != cns.end(); ++i) {
382 ArdourButton *pb = manage (new ArdourButton (lbl));
383 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
384 pb->set_layout_ellipsize_width (56 * PANGO_SCALE);
385 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
386 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
388 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::sc_input_press), boost::weak_ptr<Port> (p)), false);
389 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::sc_input_release), false);
391 pb = manage (new ArdourButton ("-"));
392 _sidechain_tbl->attach (*pb, 1, 2, r, r +1 , FILL, SHRINK);
394 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::remove_port), boost::weak_ptr<Port> (p)));
396 pb->set_sensitive (false);
401 PluginPinDialog::update_element_pos ()
404 _innerwidth = _width - 2. * _margin_x;
406 const double yc = rint (_height * .5);
407 const double bxh2 = rint (_margin_y * .45); // TODO grow?
408 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
409 const double bxw2 = rint (bxw * .5);
410 const double y_in = _margin_y;
411 const double y_out = _height - _margin_y;
416 const double dx = _pin_box_size * .5;
419 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
423 i->x = _innerwidth + _margin_x - dx;
424 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
425 i->h = _pin_box_size;
426 i->w = 1.5 * _pin_box_size;
429 uint32_t idx = i->e->id;
430 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
431 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
432 i->w = _pin_box_size;
433 i->h = 1.5 * _pin_box_size;
439 uint32_t idx = i->e->id;
440 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
441 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
443 i->w = _pin_box_size;
444 i->h = 1.5 * _pin_box_size;
449 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
450 i->x = _margin_x + rint (x0 + (i->e->id + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
451 i->y = yc - bxh2 - dx;
452 i->w = _pin_box_size;
453 i->h = _pin_box_size;
458 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
459 i->x = _margin_x + rint (x0 + (i->e->id + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
460 i->y = yc + bxh2 - dx;
461 i->w = _pin_box_size;
462 i->h = _pin_box_size;
470 PluginPinDialog::set_color (cairo_t* cr, bool midi)
472 // see also gtk2_ardour/processor_box.cc
473 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
474 static const uint32_t midi_port_color = 0x960909FF; //Red
477 cairo_set_source_rgb (cr,
478 UINT_RGBA_R_FLT (midi_port_color),
479 UINT_RGBA_G_FLT (midi_port_color),
480 UINT_RGBA_B_FLT (midi_port_color));
482 cairo_set_source_rgb (cr,
483 UINT_RGBA_R_FLT (audio_port_color),
484 UINT_RGBA_G_FLT (audio_port_color),
485 UINT_RGBA_B_FLT (audio_port_color));
490 PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
494 const double dy = w.h * .5;
495 const double dx = w.w - dy;
496 cairo_move_to (cr, w.x, w.y + dy);
497 cairo_rel_line_to (cr, dy, -dy);
498 cairo_rel_line_to (cr, dx, 0);
499 cairo_rel_line_to (cr, 0, w.h);
500 cairo_rel_line_to (cr, -dx, 0);
502 const double dir = (w.e->ct == Input) ? 1 : -1;
503 const double dx = w.w * .5;
504 const double dy = w.h - dx;
506 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
507 cairo_rel_line_to (cr, -dx, -dx * dir);
508 cairo_rel_line_to (cr, 0., -dy * dir);
509 cairo_rel_line_to (cr, 2. * dx, 0.);
510 cairo_rel_line_to (cr, 0., dy * dir);
512 cairo_close_path (cr);
514 cairo_set_line_width (cr, 1.0);
515 cairo_set_source_rgb (cr, 0, 0, 0);
516 cairo_stroke_preserve (cr);
518 set_color (cr, w.e->dt == DataType::MIDI);
521 assert (w.e->ct == Input);
522 cairo_fill_preserve (cr);
523 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
526 if (w.e == _selection || w.e == _actor) {
527 cairo_fill_preserve (cr);
528 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
529 } else if (w.prelight) {
530 cairo_fill_preserve (cr);
531 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
537 PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
539 const double dx = w.w * .5;
540 const double dy = w.h * .5;
542 cairo_move_to (cr, w.x + dx, w.y);
543 cairo_rel_line_to (cr, -dx, dy);
544 cairo_rel_line_to (cr, dx, dy);
545 cairo_rel_line_to (cr, dx, -dy);
546 cairo_close_path (cr);
548 cairo_set_line_width (cr, 1.0);
549 cairo_set_source_rgb (cr, 0, 0, 0);
550 cairo_stroke_preserve (cr);
552 set_color (cr, w.e->dt == DataType::MIDI);
555 assert (w.e->ct == Sink);
556 cairo_fill_preserve (cr);
557 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
560 if (w.e == _selection || w.e == _actor) {
561 cairo_fill_preserve (cr);
562 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
563 } else if (w.prelight) {
564 cairo_fill_preserve (cr);
565 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
571 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
573 if (!midi) { i += n_midi; }
574 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
577 const PluginPinDialog::CtrlWidget&
578 PluginPinDialog::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
580 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
581 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
585 fatal << string_compose (_("programming error: %1"),
586 X_("Invalid Plugin I/O Port."))
588 abort (); /*NOTREACHED*/
589 static CtrlWidget screw_old_compilers (Input, DataType::NIL, 0);
590 return screw_old_compilers;
594 PluginPinDialog::edge_coordinates (const CtrlWidget& w, double &x, double &y)
622 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
624 const double bz = 2 * _pin_box_size;
625 const double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
627 cairo_move_to (cr, x0, y0);
629 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
631 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
633 cairo_set_line_width (cr, 3.0);
634 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
635 cairo_set_source_rgb (cr, 1, 0, 0);
637 const double dashes[] = { 5, 7 };
638 cairo_set_dash (cr, dashes, 2, 0);
640 set_color (cr, midi);
643 cairo_set_dash (cr, 0, 0, 0);
648 PluginPinDialog::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
650 double x0, x1, y0, y1;
651 edge_coordinates (w0, x0, y0);
652 edge_coordinates (w1, x1, y1);
653 assert (w0.e->dt == w1.e->dt);
654 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
659 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
661 Gtk::Allocation a = darea.get_allocation ();
662 double const width = a.get_width ();
663 double const height = a.get_height ();
665 if (!_position_valid) {
668 update_element_pos ();
669 _position_valid = true;
672 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
673 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
676 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
677 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
678 cairo_rectangle (cr, 0, 0, width, height);
681 const double yc = rint (_height * .5);
684 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
685 cairo_set_line_width (cr, 1.0);
686 cairo_set_source_rgb (cr, .1, .1, .3);
687 cairo_stroke_preserve (cr);
688 cairo_set_source_rgb (cr, .3, .3, .3);
691 /* draw midi-bypass (behind) */
692 if (_pi->has_midi_bypass ()) {
693 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
694 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
695 draw_connection (cr, cw0, cw1, true);
699 Glib::RefPtr<Pango::Layout> layout;
700 layout = Pango::Layout::create (get_pango_context ());
702 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
703 layout->set_width (_height * PANGO_SCALE);
708 layout->set_text (_route ()->name ());
709 layout->get_pixel_size (text_width, text_height);
711 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
712 cairo_rotate (cr, M_PI * -.5);
713 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
714 pango_cairo_show_layout (cr, layout->gobj ());
718 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
719 layout->set_text (_pi->name ());
720 layout->get_pixel_size (text_width, text_height);
721 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
722 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
723 pango_cairo_show_layout (cr, layout->gobj ());
725 if (_pi->strict_io ()) {
726 layout->set_text (_("Strict I/O"));
727 layout->get_pixel_size (text_width, text_height);
728 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
729 const double sy0 = _height - 3 - text_height;
731 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
732 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
735 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
736 cairo_move_to (cr, sx0, sy0);
737 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
738 pango_cairo_show_layout (cr, layout->gobj ());
742 /* plugins & connection wires */
743 for (uint32_t i = 0; i < _n_plugins; ++i) {
744 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
747 cairo_set_source_rgb (cr, .5, .5, .5);
748 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
751 const ChanMapping::Mappings in_map = _pi->input_map (i).mappings ();
752 const ChanMapping::Mappings out_map = _pi->output_map (i).mappings ();
754 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
755 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
756 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
757 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
758 draw_connection (cr, cw0, cw1);
762 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
763 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
764 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
765 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
766 draw_connection (cr, cw0, cw1);
772 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
776 draw_io_pin (cr, *i);
780 draw_plugin_pin (cr, *i);
790 PluginPinDialog::darea_size_request (Gtk::Requisition* req)
792 req->width = _min_width;
793 req->height = _min_height;
797 PluginPinDialog::darea_size_allocate (Gtk::Allocation&)
799 _position_valid = false;
803 PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev)
805 bool changed = false;
807 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
808 if (ev->x >= i->x && ev->x <= i->x + i->w
809 && ev->y >= i->y && ev->y <= i->y + i->h)
811 if (!i->prelight) changed = true;
815 if (i->prelight) changed = true;
826 PluginPinDialog::darea_button_press_event (GdkEventButton* ev)
828 if (ev->type != GDK_BUTTON_PRESS) {
832 switch (ev->button) {
834 if (!_selection || (_selection && !_hover)) {
838 } else if (_selection && _hover && _selection != _hover) {
839 if (_selection->dt != _hover->dt) { _actor.reset (); }
840 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
841 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
842 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
843 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
851 if (_selection != _hover) {
865 PluginPinDialog::darea_button_release_event (GdkEventButton* ev)
867 if (_hover == _actor && _actor && ev->button == 1) {
869 assert (_selection->dt == _actor->dt);
870 if (_selection->ct == Input && _actor->ct == Sink) {
871 handle_input_action (_actor, _selection);
873 else if (_selection->ct == Sink && _actor->ct == Input) {
874 handle_input_action (_selection, _actor);
876 else if (_selection->ct == Output && _actor->ct == Source) {
877 handle_output_action (_actor, _selection);
879 else if (_selection->ct == Source && _actor->ct == Output) {
880 handle_output_action (_selection, _actor);
883 } else if (_hover == _selection && _selection && ev->button == 3) {
884 handle_disconnect (_selection);
885 } else if (!_hover && ev->button == 3) {
886 reset_menu.popup (1, ev->time);
894 PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i)
896 const int pc = s->ip;
898 ChanMapping in_map (_pi->input_map (pc));
899 uint32_t idx = in_map.get (s->dt, s->id, &valid);
901 if (valid && idx == i->id) {
903 in_map.unset (s->dt, s->id);
904 _pi->set_input_map (pc, in_map);
908 in_map.set (s->dt, s->id, i->id);
909 _pi->set_input_map (pc, in_map);
913 in_map.unset (s->dt, s->id);
914 in_map.set (s->dt, s->id, i->id);
915 _pi->set_input_map (pc, in_map);
920 PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o)
922 const uint32_t pc = s->ip;
924 ChanMapping out_map (_pi->output_map (pc));
925 uint32_t idx = out_map.get (s->dt, s->id, &valid);
927 if (valid && idx == o->id) {
929 out_map.unset (s->dt, s->id);
930 _pi->set_output_map (pc, out_map);
935 out_map.unset (s->dt, s->id);
937 // disconnect other outputs
938 _ignore_updates = true;
939 for (uint32_t n = 0; n < _n_plugins; ++n) {
943 ChanMapping n_out_map (_pi->output_map (n));
944 idx = n_out_map.get_src (s->dt, o->id, &valid);
946 n_out_map.unset (s->dt, idx);
947 _pi->set_output_map (n, n_out_map);
950 _ignore_updates = false;
951 idx = out_map.get_src (s->dt, o->id, &valid);
953 out_map.unset (s->dt, idx);
956 out_map.set (s->dt, s->id, o->id);
957 _pi->set_output_map (pc, out_map);
962 PluginPinDialog::handle_disconnect (const CtrlElem &e)
964 _ignore_updates = true;
965 bool changed = false;
970 for (uint32_t n = 0; n < _n_plugins; ++n) {
971 ChanMapping map (_pi->input_map (n));
972 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
973 uint32_t idx = map.get (e->dt, i, &valid);
974 if (valid && idx == e->id) {
975 map.unset (e->dt, i);
979 _pi->set_input_map (n, map);
984 ChanMapping map (_pi->input_map (e->ip));
985 map.get (e->dt, e->id, &valid);
987 map.unset (e->dt, e->id);
988 _pi->set_input_map (e->ip, map);
995 ChanMapping map (_pi->output_map (e->ip));
996 map.get (e->dt, e->id, &valid);
998 map.unset (e->dt, e->id);
999 _pi->set_output_map (e->ip, map);
1005 for (uint32_t n = 0; n < _n_plugins; ++n) {
1006 ChanMapping map (_pi->output_map (n));
1007 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1008 uint32_t idx = map.get (e->dt, i, &valid);
1009 if (valid && idx == e->id) {
1010 map.unset (e->dt, i);
1014 _pi->set_output_map (n, map);
1018 _ignore_updates = false;
1020 plugin_reconfigured ();
1025 PluginPinDialog::toggle_sidechain ()
1027 if (_session && _session->actively_recording()) { return; }
1028 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1032 PluginPinDialog::connect_sidechain ()
1034 if (!_session) { return; }
1036 if (_sidechain_selector == 0) {
1037 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1040 if (_sidechain_selector->is_visible ()) {
1041 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1043 _sidechain_selector->present ();
1048 PluginPinDialog::reset_configuration ()
1050 if (_set_config.get_active ()) {
1051 _route ()->reset_plugin_insert (_pi);
1053 _route ()->customize_plugin_insert (_pi, _n_plugins, _out);
1058 PluginPinDialog::reset_mapping ()
1064 PluginPinDialog::add_remove_plugin_clicked (bool add)
1066 if (_session && _session->actively_recording()) { return; }
1067 ChanCount out = _out;
1068 assert (add || _n_plugins > 0);
1069 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out);
1073 PluginPinDialog::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1075 if (_session && _session->actively_recording()) { return; }
1076 ChanCount out = _out;
1077 assert (add || out.get (dt) > 0);
1078 out.set (dt, out.get (dt) + (add ? 1 : -1));
1079 _route ()->customize_plugin_insert (_pi, _n_plugins, out);
1083 PluginPinDialog::add_sidechain_port (DataType dt)
1085 if (_session && _session->actively_recording()) { return; }
1086 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1090 io->add_port ("", this, dt);
1094 PluginPinDialog::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1096 if (_session && _session->actively_recording()) { return; }
1097 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1098 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1102 io->remove_port (p, this);
1106 PluginPinDialog::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1108 if (_session && _session->actively_recording()) { return; }
1109 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1110 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1114 p->disconnect_all ();
1118 PluginPinDialog::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1120 if (_session && _session->actively_recording()) { return; }
1121 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1122 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1123 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1124 if (!io || !p0 || !p1) {
1127 _ignore_updates = true;
1128 p0->disconnect_all ();
1129 _ignore_updates = false;
1130 p0->connect (p1->name ());
1134 PluginPinDialog::sc_input_release (GdkEventButton *ev)
1136 if (_session && _session->actively_recording()) { return false; }
1137 if (ev->button == 3) {
1138 connect_sidechain ();
1143 struct RouteCompareByName {
1144 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1145 return a->name().compare (b->name()) < 0;
1150 PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1152 using namespace Menu_Helpers;
1153 if (!_session || _session->actively_recording()) { return false; }
1154 if (!_session->engine().connected()) { return false; }
1156 if (ev->button == 1) {
1157 MenuList& citems = input_menu.items();
1158 input_menu.set_name ("ArdourContextMenu");
1161 boost::shared_ptr<Port> p = wp.lock ();
1162 if (p && p->connected ()) {
1163 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::disconnect_port), wp)));
1164 citems.push_back (SeparatorElem());
1168 // TODO add system inputs, too ?!
1169 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1170 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1171 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1173 //maybe_add_bundle_to_input_menu (*i, current);
1177 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1178 RouteList copy = *routes;
1179 copy.sort (RouteCompareByName ());
1181 for (ARDOUR::RouteList::const_iterator i = copy.begin(); i != copy.end(); ++i) {
1182 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1186 citems.push_back (SeparatorElem());
1188 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinDialog::connect_sidechain)));
1189 input_menu.popup (1, ev->time);
1195 PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1198 using namespace Menu_Helpers;
1199 if (r->output () == _route()->output()) {
1203 if (_route ()->feeds_according_to_graph (r)) {
1207 MenuList& citems = input_menu.items();
1208 const IOVector& iov (r->all_outputs());
1210 for (IOVector::const_iterator o = iov.begin(); o != iov.end(); ++o) {
1211 boost::shared_ptr<IO> op = o->lock();
1215 PortSet& p (op->ports ());
1216 for (PortSet::iterator i = p.begin (dt); i != p.end (dt); ++i) {
1217 std::string n = i->name ();
1218 replace_all (n, "_", " ");
1219 citems.push_back (MenuElem (n, sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::connect_port), wp, boost::weak_ptr<Port> (*i))));
1227 PluginPinDialog::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1229 boost::shared_ptr<Port> p0 = w0.lock ();
1230 boost::shared_ptr<Port> p1 = w1.lock ();
1232 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1233 if (!io) { return; }
1235 if (p0 && io->has_port (p0)) {
1236 plugin_reconfigured ();
1238 else if (p1 && io->has_port (p1)) {
1239 plugin_reconfigured ();