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 <boost/algorithm/string.hpp>
22 #include <gtkmm/table.h>
23 #include <gtkmm/frame.h>
24 #include <gtkmm/box.h>
25 #include <gtkmm/label.h>
27 #include "pbd/replace_all.h"
29 #include "gtkmm2ext/utils.h"
30 #include "gtkmm2ext/rgb_macros.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/plugin.h"
34 #include "ardour/port.h"
35 #include "ardour/profile.h"
36 #include "ardour/session.h"
38 #include "plugin_pin_dialog.h"
39 #include "gui_thread.h"
41 #include "ui_config.h"
45 using namespace ARDOUR;
49 using namespace Gtkmm2ext;
51 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
52 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
53 , _set_config (_("Manual Config"), ArdourButton::led_default_elements)
54 , _tgl_sidechain (_("Side Chain"), ArdourButton::led_default_elements)
55 , _add_plugin (_("+"))
56 , _del_plugin (_("-"))
57 , _add_output_audio (_("+"))
58 , _del_output_audio (_("-"))
59 , _add_output_midi (_("+"))
60 , _del_output_midi (_("-"))
61 , _add_sc_audio (_("Audio"))
62 , _add_sc_midi (_("MIDI"))
74 , _position_valid (false)
75 , _ignore_updates (false)
76 , _sidechain_selector (0)
79 assert (pi->owner ()); // Route
81 _pi->PluginIoReConfigure.connect (
82 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context ()
85 _pi->PluginMapChanged.connect (
86 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context ()
89 _pi->PluginConfigChanged.connect (
90 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context ()
93 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
94 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
95 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
97 _tgl_sidechain.set_name ("pinrouting sidechain");
98 _set_config.set_name ("pinrouting custom");
100 Menu_Helpers::MenuList& citems = reset_menu.items();
101 reset_menu.set_name ("ArdourContextMenu");
103 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinDialog::reset_mapping)));
105 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
106 _add_plugin.set_tweaks (ArdourButton::Square);
107 _del_plugin.set_tweaks (ArdourButton::Square);
108 _pm_size_group->add_widget (_add_plugin);
109 _pm_size_group->add_widget (_del_plugin);
110 _pm_size_group->add_widget (_add_output_audio);
111 _pm_size_group->add_widget (_del_output_audio);
112 _pm_size_group->add_widget (_add_output_midi);
113 _pm_size_group->add_widget (_del_output_midi);
118 VBox* tl = manage (new VBox ());
119 tl->set_border_width (2);
122 VBox* tr = manage (new VBox ());
123 tr->set_border_width (2);
127 tl->pack_start (_set_config, false, false);
129 box = manage (new HBox ());
130 box->set_border_width (2);
131 box->pack_start (_add_plugin, true, false);
132 box->pack_start (_del_plugin, true, false);
133 f = manage (new Frame());
134 f->set_label (_("Instances"));
136 tl->pack_start (*f, false, false);
138 box = manage (new HBox ());
139 box->set_border_width (2);
140 box->pack_start (_add_output_audio, true, false);
141 box->pack_start (_del_output_audio, true, false);
142 f = manage (new Frame());
143 f->set_label (_("Audio Out"));
145 tl->pack_start (*f, false, false);
147 box = manage (new HBox ());
148 box->set_border_width (2);
149 box->pack_start (_add_output_midi, true, false);
150 box->pack_start (_del_output_midi, true, false);
151 f = manage (new Frame());
152 f->set_label (_("MIDI Out"));
154 tl->pack_start (*f, false, false);
156 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
157 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
158 _out_presets.disable_scrolling ();
159 ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
160 tl->pack_start (_out_presets, false, false);
163 _sidechain_tbl = manage (new Gtk::Table ());
164 _sidechain_tbl->set_spacings (2);
166 tr->pack_start (_tgl_sidechain, false, false);
167 tr->pack_start (*_sidechain_tbl, true, true);
169 box = manage (new VBox ());
170 box->set_border_width (2);
171 box->set_spacing (2);
172 box->pack_start (_add_sc_audio, false, false);
173 box->pack_start (_add_sc_midi , false, false);
174 f = manage (new Frame());
175 f->set_label (_("Add Sidechain Input"));
178 tr->pack_start (*f, false, false);
181 HBox* hbox = manage (new HBox ());
182 hbox->set_spacing (4);
183 hbox->pack_start (*tl, false, false);
184 hbox->pack_start (darea, true, true);
185 hbox->pack_start (*tr, false, false);
187 VBox* vbox = manage (new VBox ());
188 vbox->pack_start (*hbox, true, true);
189 set_border_width (4);
193 plugin_reconfigured ();
195 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
196 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_request));
197 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_allocate));
198 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event));
199 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_press_event));
200 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_release_event));
201 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_motion_notify_event));
203 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::toggle_sidechain));
205 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::reset_configuration));
206 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), true));
207 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), false));
209 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::AUDIO));
210 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::AUDIO));
211 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::MIDI));
212 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::MIDI));
213 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::AUDIO));
214 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::MIDI));
216 AudioEngine::instance()->PortConnectedOrDisconnected.connect (
217 _io_connection, invalidator (*this), boost::bind (&PluginPinDialog::port_connected_or_disconnected, this, _1, _3), gui_context ()
221 PluginPinDialog::~PluginPinDialog ()
223 delete _sidechain_selector;
227 PluginPinDialog::plugin_reconfigured ()
229 ENSURE_GUI_THREAD (*this, &PluginPinDialog::plugin_reconfigured);
230 if (_ignore_updates) {
233 _n_plugins = _pi->get_count ();
234 _pi->configured_io (_in, _out);
235 _ins = _pi->internal_streams (); // with sidechain
236 _sinks = _pi->natural_input_streams ();
237 _sources = _pi->natural_output_streams ();
240 _tgl_sidechain.set_active (_pi->has_sidechain ());
241 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
242 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
244 if (_pi->custom_cfg ()) {
245 _set_config.set_active (true);
246 _add_plugin.set_sensitive (true);
247 _add_output_audio.set_sensitive (true);
248 _add_output_midi.set_sensitive (true);
249 _del_plugin.set_sensitive (_n_plugins > 1);
250 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
251 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
252 _out_presets.set_sensitive (false);
253 _out_presets.set_text (_("Manual"));
255 _set_config.set_active (false);
256 _add_plugin.set_sensitive (false);
257 _add_output_audio.set_sensitive (false);
258 _add_output_midi.set_sensitive (false);
259 _del_plugin.set_sensitive (false);
260 _del_output_audio.set_sensitive (false);
261 _del_output_midi.set_sensitive (false);
262 _out_presets.set_sensitive (true);
263 refill_output_presets ();
266 if (!_pi->has_sidechain () && _sidechain_selector) {
267 delete _sidechain_selector;
268 _sidechain_selector = 0;
271 refill_sidechain_table ();
273 /* update elements */
282 _n_inputs = _n_sidechains = 0;
284 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
285 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
286 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
287 bool sidechain = id >= _in.get (dt) ? true : false;
294 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
295 _elements.push_back (cw);
298 for (uint32_t i = 0; i < _out.n_total (); ++i) {
299 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
300 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
303 for (uint32_t n = 0; n < _n_plugins; ++n) {
304 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
305 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
306 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
307 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
308 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
309 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
310 _elements.push_back (cw);
312 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
313 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
314 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
315 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
316 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
320 /* calc minimum size */
321 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
322 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
323 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
324 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
325 min_width = std::max ((uint32_t)300, min_width);
327 min_width = 50 + 10 * ceilf (min_width / 10.f);
329 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
330 min_height = std::max ((uint32_t)200, min_height);
331 min_height = 4 * ceilf (min_height / 4.f);
333 if (min_width != _min_width || min_height != _min_height) {
334 _min_width = min_width;
335 _min_height = min_height;
336 darea.queue_resize ();
339 _position_valid = false;
344 PluginPinDialog::refill_sidechain_table ()
346 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
347 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
350 _sidechain_tbl->resize (1, 1);
351 if (!_pi->has_sidechain () && _sidechain_selector) {
354 boost::shared_ptr<IO> io = _pi->sidechain_input ();
360 PortSet& p (io->ports ());
361 bool can_remove = p.num_ports () > 1;
362 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i, ++r) {
363 add_port_to_table (*i, r, can_remove);
365 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i, ++r) {
366 add_port_to_table (*i, r, can_remove);
368 _sidechain_tbl->show_all ();
372 PluginPinDialog::refill_output_presets ()
374 using namespace Menu_Helpers;
375 _out_presets.clear_items();
376 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
378 bool need_dropdown = true;
380 if (ppc.size () == 0) {
381 need_dropdown = false;
384 if (!_pi->strict_io () && ppc.size () == 1) {
385 need_dropdown = false;
388 if (_pi->strict_io () && ppc.size () == 1) {
389 // XXX "stereo" is currently preferred default for instruments, see PluginInsert
390 if (ppc.find (2) != ppc.end ()) {
391 need_dropdown = false;
395 if (!_pi->needs_midi_input ()) {
396 /* loose definition of instruments, maybe impose additional
397 * || _pi->natural_input_streams ().n_audio () != 0
398 * and special case variable output plugins
399 * && !_pi->plugin (0)->info->reconfigurable_io()
401 need_dropdown = false;
404 if (!need_dropdown) {
405 _out_presets.set_sensitive (false);
406 _out_presets.set_text(_("Automatic"));
410 _out_presets.AddMenuElem (MenuElem(_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), 0)));
412 const uint32_t n_audio = _pi->preset_out ().n_audio ();
414 _out_presets.set_text(_("Automatic"));
417 if (ppc.find (0) != ppc.end ()) {
421 ppc.insert (n_audio);
431 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
442 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
445 _out_presets.AddMenuElem (MenuElem(tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), *i)));
447 _out_presets.set_text(tmp);
453 PluginPinDialog::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
456 std::string tip = p->name ();
457 std::vector<std::string> cns;
458 p->get_connections (cns);
460 // TODO proper labels, see MixerStrip::update_io_button()
461 if (cns.size () == 0) {
463 } else if (cns.size () > 1) {
467 string lpn (PROGRAM_NAME);
468 boost::to_lower (lpn);
469 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
473 if (lbl.find ("system:capture_") == 0) {
474 lbl = AudioEngine::instance ()->get_pretty_name_by_name (lbl);
476 lbl = cns[0].substr (15);
478 } else if (lbl.find("system:midi_capture_") == 0) {
479 lbl = AudioEngine::instance ()->get_pretty_name_by_name (lbl);
481 // "system:midi_capture_123" -> "123"
482 lbl = "M " + cns[0].substr (20);
484 } else if (lbl.find (program_port_prefix) == 0) {
485 lbl = lbl.substr (program_port_prefix.size());
488 for (std::vector<std::string>::const_iterator i = cns.begin(); i != cns.end(); ++i) {
492 replace_all (lbl, "_", " ");
494 ArdourButton *pb = manage (new ArdourButton (lbl));
495 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
496 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
497 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
498 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
500 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::sc_input_press), boost::weak_ptr<Port> (p)), false);
501 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::sc_input_release), false);
503 pb = manage (new ArdourButton ("-"));
504 _sidechain_tbl->attach (*pb, 1, 2, r, r +1 , FILL, SHRINK);
506 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::remove_port), boost::weak_ptr<Port> (p)));
508 pb->set_sensitive (false);
513 PluginPinDialog::update_element_pos ()
516 _innerwidth = _width - 2. * _margin_x;
518 const double yc = rint (_height * .5);
519 const double bxh2 = rint (_margin_y * .45); // TODO grow?
520 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
521 const double bxw2 = rint (bxw * .5);
522 const double y_in = _margin_y;
523 const double y_out = _height - _margin_y;
528 const double dx = _pin_box_size * .5;
531 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
535 i->x = _innerwidth + _margin_x - dx;
536 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
537 i->h = _pin_box_size;
538 i->w = 1.5 * _pin_box_size;
541 uint32_t idx = i->e->id;
542 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
543 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
544 i->w = _pin_box_size;
545 i->h = 1.5 * _pin_box_size;
551 uint32_t idx = i->e->id;
552 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
553 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
555 i->w = _pin_box_size;
556 i->h = 1.5 * _pin_box_size;
561 uint32_t idx = i->e->id;
562 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
563 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
564 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
565 i->y = yc - bxh2 - dx;
566 i->w = _pin_box_size;
567 i->h = _pin_box_size;
572 uint32_t idx = i->e->id;
573 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
574 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
575 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
576 i->y = yc + bxh2 - dx;
577 i->w = _pin_box_size;
578 i->h = _pin_box_size;
586 PluginPinDialog::set_color (cairo_t* cr, bool midi)
588 // see also gtk2_ardour/processor_box.cc
589 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
590 static const uint32_t midi_port_color = 0x960909FF; //Red
593 cairo_set_source_rgb (cr,
594 UINT_RGBA_R_FLT (midi_port_color),
595 UINT_RGBA_G_FLT (midi_port_color),
596 UINT_RGBA_B_FLT (midi_port_color));
598 cairo_set_source_rgb (cr,
599 UINT_RGBA_R_FLT (audio_port_color),
600 UINT_RGBA_G_FLT (audio_port_color),
601 UINT_RGBA_B_FLT (audio_port_color));
606 PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
609 const double dy = w.h * .5;
610 const double dx = w.w - dy;
611 cairo_move_to (cr, w.x, w.y + dy);
612 cairo_rel_line_to (cr, dy, -dy);
613 cairo_rel_line_to (cr, dx, 0);
614 cairo_rel_line_to (cr, 0, w.h);
615 cairo_rel_line_to (cr, -dx, 0);
617 const double dir = (w.e->ct == Input) ? 1 : -1;
618 const double dx = w.w * .5;
619 const double dy = w.h - dx;
621 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
622 cairo_rel_line_to (cr, -dx, -dx * dir);
623 cairo_rel_line_to (cr, 0., -dy * dir);
624 cairo_rel_line_to (cr, 2. * dx, 0.);
625 cairo_rel_line_to (cr, 0., dy * dir);
627 cairo_close_path (cr);
629 cairo_set_line_width (cr, 1.0);
630 cairo_set_source_rgb (cr, 0, 0, 0);
631 cairo_stroke_preserve (cr);
633 set_color (cr, w.e->dt == DataType::MIDI);
636 assert (w.e->ct == Input);
637 cairo_fill_preserve (cr);
638 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
641 if (w.e == _selection || w.e == _actor) {
642 cairo_fill_preserve (cr);
643 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
644 } else if (w.prelight) {
645 cairo_fill_preserve (cr);
646 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
652 PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
654 const double dx = w.w * .5;
655 const double dy = w.h * .5;
657 cairo_move_to (cr, w.x + dx, w.y);
658 cairo_rel_line_to (cr, -dx, dy);
659 cairo_rel_line_to (cr, dx, dy);
660 cairo_rel_line_to (cr, dx, -dy);
661 cairo_close_path (cr);
663 cairo_set_line_width (cr, 1.0);
664 cairo_set_source_rgb (cr, 0, 0, 0);
665 cairo_stroke_preserve (cr);
667 set_color (cr, w.e->dt == DataType::MIDI);
670 assert (w.e->ct == Sink);
671 cairo_fill_preserve (cr);
672 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
675 if (w.e == _selection || w.e == _actor) {
676 cairo_fill_preserve (cr);
677 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
678 } else if (w.prelight) {
679 cairo_fill_preserve (cr);
680 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
684 if ((w.prelight || w.e == _selection) && !w.name.empty()) {
687 Glib::RefPtr<Pango::Layout> layout;
688 layout = Pango::Layout::create (get_pango_context ());
689 layout->set_text (w.name);
690 layout->get_pixel_size (text_width, text_height);
692 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
693 cairo_set_source_rgba (cr, 0, 0, 0, .5);
696 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
697 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
698 pango_cairo_show_layout (cr, layout->gobj ());
703 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
705 if (!midi) { i += n_midi; }
706 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
709 const PluginPinDialog::CtrlWidget&
710 PluginPinDialog::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
712 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
713 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
718 fatal << string_compose (_("programming error: %1"),
719 X_("Invalid Plugin I/O Port."))
721 abort (); /*NOTREACHED*/
722 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
723 return screw_old_compilers;
727 PluginPinDialog::edge_coordinates (const CtrlWidget& w, double &x, double &y)
755 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
757 const double bz = 2 * _pin_box_size;
758 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
759 if (x0 > _width * .5) { bc *= -1; }
761 cairo_move_to (cr, x0, y0);
763 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
765 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
767 cairo_set_line_width (cr, 3.0);
768 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
769 cairo_set_source_rgb (cr, 1, 0, 0);
771 const double dashes[] = { 5, 7 };
772 cairo_set_dash (cr, dashes, 2, 0);
774 set_color (cr, midi);
777 cairo_set_dash (cr, 0, 0, 0);
782 PluginPinDialog::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
784 double x0, x1, y0, y1;
785 edge_coordinates (w0, x0, y0);
786 edge_coordinates (w1, x1, y1);
787 assert (w0.e->dt == w1.e->dt);
788 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
793 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
795 Gtk::Allocation a = darea.get_allocation ();
796 double const width = a.get_width ();
797 double const height = a.get_height ();
799 if (!_position_valid) {
802 update_element_pos ();
803 _position_valid = true;
806 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
807 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
810 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
811 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
812 cairo_rectangle (cr, 0, 0, width, height);
815 const double yc = rint (_height * .5);
818 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
819 cairo_set_line_width (cr, 1.0);
820 cairo_set_source_rgb (cr, .1, .1, .3);
821 cairo_stroke_preserve (cr);
822 cairo_set_source_rgb (cr, .3, .3, .3);
826 Glib::RefPtr<Pango::Layout> layout;
827 layout = Pango::Layout::create (get_pango_context ());
829 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
830 layout->set_width (_height * PANGO_SCALE);
835 layout->set_text (_route ()->name ());
836 layout->get_pixel_size (text_width, text_height);
838 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
839 cairo_rotate (cr, M_PI * -.5);
840 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
841 pango_cairo_show_layout (cr, layout->gobj ());
845 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
846 layout->set_text (_pi->name ());
847 layout->get_pixel_size (text_width, text_height);
848 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
849 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
850 pango_cairo_show_layout (cr, layout->gobj ());
852 if (_pi->signal_latency () > 0) {
853 // TODO: this needs a better location also format to msec (and cache)
854 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
855 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
856 layout->get_pixel_size (text_width, text_height);
857 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
858 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
859 pango_cairo_show_layout (cr, layout->gobj ());
862 if (_pi->strict_io () && !Profile->get_mixbus ()) {
863 layout->set_text (_("Strict I/O"));
864 layout->get_pixel_size (text_width, text_height);
865 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
866 const double sy0 = _height - 3 - text_height;
868 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
869 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
872 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
873 cairo_move_to (cr, sx0, sy0);
874 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
875 pango_cairo_show_layout (cr, layout->gobj ());
878 /* draw midi-bypass (behind) */
879 if (_pi->has_midi_bypass ()) {
880 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
881 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
882 draw_connection (cr, cw0, cw1, true);
885 /* thru connections */
886 const ChanMapping::Mappings thru_map = _pi->thru_map ().mappings ();
887 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
888 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
889 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
890 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
891 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
892 draw_connection (cr, cw1, cw0, true);
898 /* plugins & connection wires */
899 for (uint32_t i = 0; i < _n_plugins; ++i) {
900 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
903 cairo_set_source_rgb (cr, .5, .5, .5);
904 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
907 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
908 layout->set_text (string_compose (_("Instance #%1"), i + 1));
909 layout->get_pixel_size (text_width, text_height);
910 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
911 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
912 pango_cairo_show_layout (cr, layout->gobj ());
914 const ChanMapping::Mappings in_map = _pi->input_map (i).mappings ();
915 const ChanMapping::Mappings out_map = _pi->output_map (i).mappings ();
917 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
918 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
919 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
920 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
921 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
922 draw_connection (cr, cw0, cw1);
927 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
928 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
929 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
930 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
931 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
932 draw_connection (cr, cw0, cw1);
939 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
943 draw_io_pin (cr, *i);
947 draw_plugin_pin (cr, *i);
953 CtrlWidget *drag_src = NULL;
955 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
956 if (i->e == _selection ) {
964 if (_selection->ct == Input || _selection->ct == Source) {
965 edge_coordinates (*drag_src, x0, y0);
966 draw_connection (cr, x0, _drag_x, y0, _drag_y,
967 _selection->dt == DataType::MIDI, _selection->sc);
969 edge_coordinates (*drag_src, x0, y0);
970 draw_connection (cr, _drag_x, x0, _drag_y, y0,
971 _selection->dt == DataType::MIDI, _selection->sc);
980 PluginPinDialog::darea_size_request (Gtk::Requisition* req)
982 req->width = _min_width;
983 req->height = _min_height;
987 PluginPinDialog::darea_size_allocate (Gtk::Allocation&)
989 _position_valid = false;
993 PluginPinDialog::drag_type_matches (const CtrlElem& e)
995 if (!_dragging || !_selection) {
998 if (_selection->dt != e->dt) {
1001 if (_selection->ct == Input && e->ct == Sink) { return true; }
1002 if (_selection->ct == Sink && e->ct == Input) { return true; }
1003 if (_selection->ct == Output && e->ct == Source) { return true; }
1004 if (_selection->ct == Source && e->ct == Output) { return true; }
1005 if (_selection->ct == Input && e->ct == Output) { return true; }
1006 if (_selection->ct == Output && e->ct == Input) { return true; }
1011 PluginPinDialog::start_drag (const CtrlElem& e, double x, double y)
1013 assert (_selection == e);
1015 if (e->ct == Sink) {
1017 const ChanMapping& map (_pi->input_map (e->ip));
1018 uint32_t idx = map.get (e->dt, e->id, &valid);
1020 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1025 else if (e->ct == Output) {
1026 for (uint32_t i = 0; i < _n_plugins; ++i) {
1028 const ChanMapping& map (_pi->output_map (i));
1029 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1031 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1039 const ChanMapping& map (_pi->thru_map ());
1040 uint32_t idx = map.get (e->dt, e->id, &valid);
1042 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1054 PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev)
1056 bool changed = false;
1058 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1059 if (ev->x >= i->x && ev->x <= i->x + i->w
1060 && ev->y >= i->y && ev->y <= i->y + i->h
1061 && drag_type_matches (i->e))
1063 if (!i->prelight) changed = true;
1067 if (i->prelight) changed = true;
1068 i->prelight = false;
1075 if (changed || _dragging) {
1076 darea.queue_draw ();
1082 PluginPinDialog::darea_button_press_event (GdkEventButton* ev)
1084 if (ev->type != GDK_BUTTON_PRESS) {
1088 switch (ev->button) {
1091 if (!_selection || (_selection && !_hover)) {
1092 _selection = _hover;
1095 start_drag (_selection, ev->x, ev->y);
1097 darea.queue_draw ();
1099 } else if (_selection && _hover && _selection != _hover) {
1100 if (_selection->dt != _hover->dt) { _actor.reset (); }
1101 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1102 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1103 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1104 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1105 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1106 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1108 _selection = _hover;
1109 start_drag (_selection, ev->x, ev->y);
1111 darea.queue_draw ();
1113 } else if (_hover) {
1114 _selection = _hover;
1116 start_drag (_selection, ev->x, ev->y);
1121 if (_selection != _hover) {
1122 _selection = _hover;
1123 darea.queue_draw ();
1135 PluginPinDialog::darea_button_release_event (GdkEventButton* ev)
1137 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1138 // select click. (or re-connect same)
1139 assert (_selection != _hover);
1144 darea.queue_draw ();
1148 if (_dragging && _hover && _hover != _selection) {
1152 if (_hover == _actor && _actor && ev->button == 1) {
1153 assert (_selection);
1154 assert (_selection->dt == _actor->dt);
1156 assert (_dragging && _selection != _drag_dst);
1157 handle_disconnect (_drag_dst, true);
1159 if (_selection->ct == Input && _actor->ct == Sink) {
1160 handle_input_action (_actor, _selection);
1162 else if (_selection->ct == Sink && _actor->ct == Input) {
1163 handle_input_action (_selection, _actor);
1165 else if (_selection->ct == Output && _actor->ct == Source) {
1166 handle_output_action (_actor, _selection);
1168 else if (_selection->ct == Source && _actor->ct == Output) {
1169 handle_output_action (_selection, _actor);
1171 else if (_selection->ct == Input && _actor->ct == Output) {
1172 handle_thru_action (_actor, _selection);
1174 else if (_selection->ct == Output && _actor->ct == Input) {
1175 handle_thru_action (_selection, _actor);
1177 _selection.reset ();
1178 } else if (_hover == _selection && _selection && ev->button == 3) {
1179 handle_disconnect (_selection);
1180 } else if (!_hover && ev->button == 3) {
1181 reset_menu.popup (1, ev->time);
1184 if (_dragging && _hover != _selection) {
1185 _selection.reset ();
1190 darea.queue_draw ();
1195 PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1197 const int pc = s->ip;
1199 ChanMapping in_map (_pi->input_map (pc));
1200 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1202 if (valid && idx == i->id) {
1205 in_map.unset (s->dt, s->id);
1206 _pi->set_input_map (pc, in_map);
1208 plugin_reconfigured ();
1213 in_map.set (s->dt, s->id, i->id);
1214 _pi->set_input_map (pc, in_map);
1218 in_map.unset (s->dt, s->id);
1219 in_map.set (s->dt, s->id, i->id);
1220 _pi->set_input_map (pc, in_map);
1225 PluginPinDialog::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1227 _ignore_updates = true;
1228 for (uint32_t n = 0; n < _n_plugins; ++n) {
1233 ChanMapping n_out_map (_pi->output_map (n));
1234 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1236 n_out_map.unset (dt, idx);
1237 _pi->set_output_map (n, n_out_map);
1240 _ignore_updates = false;
1244 PluginPinDialog::disconnect_other_thru (DataType dt, uint32_t id)
1246 _ignore_updates = true;
1248 ChanMapping n_thru_map (_pi->thru_map ());
1249 n_thru_map.get (dt, id, &valid);
1251 n_thru_map.unset (dt, id);
1252 _pi->set_thru_map (n_thru_map);
1254 _ignore_updates = false;
1258 PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1260 const uint32_t pc = s->ip;
1262 ChanMapping out_map (_pi->output_map (pc));
1263 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1265 if (valid && idx == o->id) {
1268 out_map.unset (s->dt, s->id);
1269 _pi->set_output_map (pc, out_map);
1271 plugin_reconfigured ();
1275 // disconnect source
1276 disconnect_other_outputs (pc, s->dt, o->id);
1277 disconnect_other_thru (s->dt, o->id);
1278 out_map = _pi->output_map (pc); // re-read map
1280 out_map.unset (s->dt, s->id);
1282 idx = out_map.get_src (s->dt, o->id, &valid);
1284 out_map.unset (s->dt, idx);
1287 out_map.set (s->dt, s->id, o->id);
1288 _pi->set_output_map (pc, out_map);
1293 PluginPinDialog::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1296 ChanMapping thru_map (_pi->thru_map ());
1297 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1299 if (valid && idx == i->id) {
1301 thru_map.unset (o->dt, o->id);
1304 // disconnect other outputs first
1305 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1306 disconnect_other_thru (o->dt, o->id);
1307 thru_map = _pi->thru_map (); // re-read map
1309 thru_map.set (o->dt, o->id, i->id);
1311 _pi->set_thru_map (thru_map);
1315 PluginPinDialog::handle_disconnect (const CtrlElem &e, bool no_signal)
1317 _ignore_updates = true;
1318 bool changed = false;
1324 ChanMapping n_thru_map (_pi->thru_map ());
1325 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1326 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1327 if (valid && idx == e->id) {
1328 n_thru_map.unset (e->dt, i);
1333 _pi->set_thru_map (n_thru_map);
1336 for (uint32_t n = 0; n < _n_plugins; ++n) {
1337 ChanMapping map (_pi->input_map (n));
1338 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1339 uint32_t idx = map.get (e->dt, i, &valid);
1340 if (valid && idx == e->id) {
1341 map.unset (e->dt, i);
1345 _pi->set_input_map (n, map);
1350 ChanMapping map (_pi->input_map (e->ip));
1351 map.get (e->dt, e->id, &valid);
1353 map.unset (e->dt, e->id);
1354 _pi->set_input_map (e->ip, map);
1361 ChanMapping map (_pi->output_map (e->ip));
1362 map.get (e->dt, e->id, &valid);
1364 map.unset (e->dt, e->id);
1365 _pi->set_output_map (e->ip, map);
1371 for (uint32_t n = 0; n < _n_plugins; ++n) {
1372 ChanMapping map (_pi->output_map (n));
1373 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1374 uint32_t idx = map.get (e->dt, i, &valid);
1375 if (valid && idx == e->id) {
1376 map.unset (e->dt, i);
1381 _pi->set_output_map (n, map);
1385 ChanMapping n_thru_map (_pi->thru_map ());
1386 n_thru_map.get (e->dt, e->id, &valid);
1388 n_thru_map.unset (e->dt, e->id);
1390 _pi->set_thru_map (n_thru_map);
1395 _ignore_updates = false;
1396 if (changed && !no_signal) {
1397 plugin_reconfigured ();
1403 PluginPinDialog::toggle_sidechain ()
1405 if (_session && _session->actively_recording()) { return; }
1406 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1410 PluginPinDialog::connect_sidechain ()
1412 if (!_session) { return; }
1414 if (_sidechain_selector == 0) {
1415 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1418 if (_sidechain_selector->is_visible ()) {
1419 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1421 _sidechain_selector->present ();
1426 PluginPinDialog::reset_configuration ()
1428 if (_set_config.get_active ()) {
1429 _route ()->reset_plugin_insert (_pi);
1431 _route ()->customize_plugin_insert (_pi, _n_plugins, _out);
1436 PluginPinDialog::reset_mapping ()
1442 PluginPinDialog::select_output_preset (uint32_t n_audio)
1444 if (_session && _session->actively_recording()) { return; }
1445 ChanCount out (DataType::AUDIO, n_audio);
1446 _route ()->plugin_preset_output (_pi, out);
1450 PluginPinDialog::add_remove_plugin_clicked (bool add)
1452 if (_session && _session->actively_recording()) { return; }
1453 ChanCount out = _out;
1454 assert (add || _n_plugins > 0);
1455 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out);
1459 PluginPinDialog::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1461 if (_session && _session->actively_recording()) { return; }
1462 ChanCount out = _out;
1463 assert (add || out.get (dt) > 0);
1464 out.set (dt, out.get (dt) + (add ? 1 : -1));
1465 _route ()->customize_plugin_insert (_pi, _n_plugins, out);
1469 PluginPinDialog::add_sidechain_port (DataType dt)
1471 if (_session && _session->actively_recording()) { return; }
1472 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1476 io->add_port ("", this, dt);
1480 PluginPinDialog::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1482 if (_session && _session->actively_recording()) { return; }
1483 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1484 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1488 io->remove_port (p, this);
1492 PluginPinDialog::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1494 if (_session && _session->actively_recording()) { return; }
1495 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1496 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1500 p->disconnect_all ();
1504 PluginPinDialog::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1506 if (_session && _session->actively_recording()) { return; }
1507 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1508 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1509 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1510 if (!io || !p0 || !p1) {
1513 _ignore_updates = true;
1514 p0->disconnect_all ();
1515 _ignore_updates = false;
1516 p0->connect (p1->name ());
1520 PluginPinDialog::sc_input_release (GdkEventButton *ev)
1522 if (_session && _session->actively_recording()) { return false; }
1523 if (ev->button == 3) {
1524 connect_sidechain ();
1529 struct RouteCompareByName {
1530 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1531 return a->name().compare (b->name()) < 0;
1536 PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1538 using namespace Menu_Helpers;
1539 if (!_session || _session->actively_recording()) { return false; }
1540 if (!_session->engine().connected()) { return false; }
1542 if (ev->button == 1) {
1543 MenuList& citems = input_menu.items();
1544 input_menu.set_name ("ArdourContextMenu");
1547 boost::shared_ptr<Port> p = wp.lock ();
1548 if (p && p->connected ()) {
1549 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::disconnect_port), wp)));
1550 citems.push_back (SeparatorElem());
1554 // TODO add system inputs, too ?!
1555 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1556 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1557 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1559 //maybe_add_bundle_to_input_menu (*i, current);
1563 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1564 RouteList copy = *routes;
1565 copy.sort (RouteCompareByName ());
1567 for (ARDOUR::RouteList::const_iterator i = copy.begin(); i != copy.end(); ++i) {
1568 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1572 citems.push_back (SeparatorElem());
1574 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinDialog::connect_sidechain)));
1575 input_menu.popup (1, ev->time);
1581 PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1584 using namespace Menu_Helpers;
1585 if (r->output () == _route()->output()) {
1589 if (_route ()->feeds_according_to_graph (r)) {
1593 MenuList& citems = input_menu.items();
1594 const IOVector& iov (r->all_outputs());
1596 for (IOVector::const_iterator o = iov.begin(); o != iov.end(); ++o) {
1597 boost::shared_ptr<IO> op = o->lock();
1601 PortSet& p (op->ports ());
1602 for (PortSet::iterator i = p.begin (dt); i != p.end (dt); ++i) {
1603 std::string n = i->name ();
1604 replace_all (n, "_", " ");
1605 citems.push_back (MenuElem (n, sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::connect_port), wp, boost::weak_ptr<Port> (*i))));
1613 PluginPinDialog::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1615 boost::shared_ptr<Port> p0 = w0.lock ();
1616 boost::shared_ptr<Port> p1 = w1.lock ();
1618 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1619 if (!io) { return; }
1621 if (p0 && io->has_port (p0)) {
1622 plugin_reconfigured ();
1624 else if (p1 && io->has_port (p1)) {
1625 plugin_reconfigured ();