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/amp.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/pannable.h"
35 #include "ardour/plugin.h"
36 #include "ardour/port.h"
37 #include "ardour/profile.h"
38 #include "ardour/send.h"
39 #include "ardour/session.h"
41 #include "plugin_pin_dialog.h"
42 #include "gui_thread.h"
45 #include "ui_config.h"
49 using namespace ARDOUR;
53 using namespace Gtkmm2ext;
55 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
56 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
57 , _set_config (_("Manual Config"), ArdourButton::led_default_elements)
58 , _tgl_sidechain (_("Side Chain"), ArdourButton::led_default_elements)
59 , _add_plugin (_("+"))
60 , _del_plugin (_("-"))
61 , _add_output_audio (_("+"))
62 , _del_output_audio (_("-"))
63 , _add_output_midi (_("+"))
64 , _del_output_midi (_("-"))
65 , _add_sc_audio (_("Audio"))
66 , _add_sc_midi (_("MIDI"))
78 , _position_valid (false)
79 , _ignore_updates (false)
80 , _sidechain_selector (0)
83 assert (pi->owner ()); // Route
85 _pi->PluginIoReConfigure.connect (
86 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
89 _pi->PluginMapChanged.connect (
90 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
93 _pi->PluginConfigChanged.connect (
94 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
97 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
98 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
99 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
101 _tgl_sidechain.set_name ("pinrouting sidechain");
102 _set_config.set_name ("pinrouting custom");
104 Menu_Helpers::MenuList& citems = reset_menu.items ();
105 reset_menu.set_name ("ArdourContextMenu");
107 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinDialog::reset_mapping)));
109 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
110 _add_plugin.set_tweaks (ArdourButton::Square);
111 _del_plugin.set_tweaks (ArdourButton::Square);
112 _pm_size_group->add_widget (_add_plugin);
113 _pm_size_group->add_widget (_del_plugin);
114 _pm_size_group->add_widget (_add_output_audio);
115 _pm_size_group->add_widget (_del_output_audio);
116 _pm_size_group->add_widget (_add_output_midi);
117 _pm_size_group->add_widget (_del_output_midi);
122 VBox* tl = manage (new VBox ());
123 tl->set_border_width (2);
126 VBox* tr = manage (new VBox ());
127 tr->set_border_width (2);
131 tl->pack_start (_set_config, false, false);
133 box = manage (new HBox ());
134 box->set_border_width (2);
135 box->pack_start (_add_plugin, true, false);
136 box->pack_start (_del_plugin, true, false);
137 f = manage (new Frame ());
138 f->set_label (_("Instances"));
140 tl->pack_start (*f, false, false);
142 box = manage (new HBox ());
143 box->set_border_width (2);
144 box->pack_start (_add_output_audio, true, false);
145 box->pack_start (_del_output_audio, true, false);
146 f = manage (new Frame ());
147 f->set_label (_("Audio Out"));
149 tl->pack_start (*f, false, false);
151 box = manage (new HBox ());
152 box->set_border_width (2);
153 box->pack_start (_add_output_midi, true, false);
154 box->pack_start (_del_output_midi, true, false);
155 f = manage (new Frame ());
156 f->set_label (_("MIDI Out"));
158 tl->pack_start (*f, false, false);
160 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
161 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
162 _out_presets.disable_scrolling ();
163 ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
164 tl->pack_start (_out_presets, false, false);
167 _sidechain_tbl = manage (new Gtk::Table ());
168 _sidechain_tbl->set_spacings (2);
170 tr->pack_start (_tgl_sidechain, false, false);
171 tr->pack_start (*_sidechain_tbl, true, true);
173 box = manage (new VBox ());
174 box->set_border_width (2);
175 box->set_spacing (2);
176 box->pack_start (_add_sc_audio, false, false);
177 box->pack_start (_add_sc_midi , false, false);
178 f = manage (new Frame ());
179 f->set_label (_("Add Sidechain Input"));
182 tr->pack_start (*f, false, false);
185 HBox* hbox = manage (new HBox ());
186 hbox->set_spacing (4);
187 hbox->pack_start (*tl, false, false);
188 hbox->pack_start (darea, true, true);
189 hbox->pack_start (*tr, false, false);
191 VBox* vbox = manage (new VBox ());
192 vbox->pack_start (*hbox, true, true);
193 set_border_width (4);
197 plugin_reconfigured ();
199 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
200 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_request));
201 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_allocate));
202 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event));
203 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_press_event));
204 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_release_event));
205 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_motion_notify_event));
207 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::toggle_sidechain));
209 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::reset_configuration));
210 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), true));
211 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), false));
213 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::AUDIO));
214 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::AUDIO));
215 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::MIDI));
216 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::MIDI));
217 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::AUDIO));
218 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::MIDI));
220 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
221 _io_connection, invalidator (*this), boost::bind (&PluginPinDialog::port_connected_or_disconnected, this, _1, _3), gui_context ()
225 PluginPinDialog::~PluginPinDialog ()
227 delete _sidechain_selector;
231 PluginPinDialog::set_session (ARDOUR::Session *s)
233 SessionHandlePtr::set_session (s);
234 plugin_reconfigured ();
238 PluginPinDialog::queue_idle_update ()
240 /* various actions here are directly executed, in the GUI thread,
241 * with the GUI-thread eventually taking the process and processor lock.
242 * "connect gui_context()" will call back immediately and this
243 * signal-handler will run with the locks held.
245 * This will lead to a crash with calling nth_send() which takes
246 * a processor read-lock while holding a write lock in the same thread.
248 * decouple update to GUI idle.
250 * BUT, do delete existing controls here (in case they're affected by
251 * the change and hit by the Timer before idle comes around)
253 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
254 _sidechain_tbl->remove ((*i)->box);
258 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinDialog::idle_update));
262 PluginPinDialog::idle_update ()
264 plugin_reconfigured ();
270 PluginPinDialog::plugin_reconfigured ()
272 ENSURE_GUI_THREAD (*this, &PluginPinDialog::plugin_reconfigured);
273 if (_ignore_updates) {
276 _n_plugins = _pi->get_count ();
277 _pi->configured_io (_in, _out);
278 _ins = _pi->internal_streams (); // with sidechain
279 _sinks = _pi->natural_input_streams ();
280 _sources = _pi->natural_output_streams ();
283 _tgl_sidechain.set_active (_pi->has_sidechain ());
284 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
285 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
287 if (_pi->custom_cfg ()) {
288 _set_config.set_active (true);
289 _add_plugin.set_sensitive (true);
290 _add_output_audio.set_sensitive (true);
291 _add_output_midi.set_sensitive (true);
292 _del_plugin.set_sensitive (_n_plugins > 1);
293 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
294 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
295 _out_presets.set_sensitive (false);
296 _out_presets.set_text (_("Manual"));
298 _set_config.set_active (false);
299 _add_plugin.set_sensitive (false);
300 _add_output_audio.set_sensitive (false);
301 _add_output_midi.set_sensitive (false);
302 _del_plugin.set_sensitive (false);
303 _del_output_audio.set_sensitive (false);
304 _del_output_midi.set_sensitive (false);
305 _out_presets.set_sensitive (true);
306 refill_output_presets ();
309 if (!_pi->has_sidechain () && _sidechain_selector) {
310 delete _sidechain_selector;
311 _sidechain_selector = 0;
314 refill_sidechain_table ();
316 /* update elements */
325 _n_inputs = _n_sidechains = 0;
327 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
328 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
329 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
330 bool sidechain = id >= _in.get (dt) ? true : false;
337 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
338 _elements.push_back (cw);
341 for (uint32_t i = 0; i < _out.n_total (); ++i) {
342 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
343 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
349 for (uint32_t n = 0; n < _n_plugins; ++n) {
350 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
351 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
352 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
353 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
354 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
355 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
356 _elements.push_back (cw);
358 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
359 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
360 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
361 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
362 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
364 _in_map[n] = _pi->input_map (n);
365 _out_map[n] = _pi->output_map (n);
367 _has_midi_bypass = _pi->has_midi_bypass ();
368 _thru_map = _pi->thru_map ();
372 /* calc minimum size */
373 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
374 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
375 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
376 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
377 min_width = std::max ((uint32_t)300, min_width);
379 min_width = 50 + 10 * ceilf (min_width / 10.f);
381 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
382 min_height = std::max ((uint32_t)200, min_height);
383 min_height = 4 * ceilf (min_height / 4.f);
385 if (min_width != _min_width || min_height != _min_height) {
386 _min_width = min_width;
387 _min_height = min_height;
388 darea.queue_resize ();
391 _position_valid = false;
396 PluginPinDialog::refill_sidechain_table ()
398 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
399 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
402 _sidechain_tbl->resize (1, 1);
403 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
407 if (!_pi->has_sidechain () && _sidechain_selector) {
410 boost::shared_ptr<IO> io = _pi->sidechain_input ();
416 PortSet& p (io->ports ());
417 bool can_remove = p.num_ports () > 1;
418 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
419 r += add_port_to_table (*i, r, can_remove);
421 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
422 r += add_port_to_table (*i, r, can_remove);
424 _sidechain_tbl->show_all ();
428 PluginPinDialog::refill_output_presets ()
430 using namespace Menu_Helpers;
431 _out_presets.clear_items ();
432 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
434 bool need_dropdown = true;
436 if (ppc.size () == 0) {
437 need_dropdown = false;
440 if (!_pi->strict_io () && ppc.size () == 1) {
441 need_dropdown = false;
444 if (_pi->strict_io () && ppc.size () == 1) {
445 // "stereo" is currently preferred default for instruments, see PluginInsert
446 if (ppc.find (2) != ppc.end ()) {
447 need_dropdown = false;
451 if (!_pi->needs_midi_input ()) {
452 /* loose definition of instruments, maybe impose additional
453 * || _pi->natural_input_streams ().n_audio () != 0
454 * and special case variable output plugins
455 * && !_pi->plugin (0)->info->reconfigurable_io()
457 need_dropdown = false;
460 if (!need_dropdown) {
461 _out_presets.set_sensitive (false);
462 _out_presets.set_text (_("Automatic"));
466 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), 0)));
468 const uint32_t n_audio = _pi->preset_out ().n_audio ();
470 _out_presets.set_text (_("Automatic"));
473 if (ppc.find (0) != ppc.end ()) {
477 ppc.insert (n_audio);
487 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
498 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
501 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), *i)));
503 _out_presets.set_text (tmp);
509 PluginPinDialog::port_label (const std::string& portname, bool strip)
511 // compare to MixerStrip::update_io_button()
512 string lpn (PROGRAM_NAME);
513 boost::to_lower (lpn);
514 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
516 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
518 string::size_type slash = pn.find ("/");
519 if (slash != string::npos) {
520 pn = pn.substr (0, slash);
524 std::string label (portname);
525 if (label.find ("system:capture_") == 0) {
526 if (label.empty ()) {
527 label = portname.substr (15);
529 } else if (label.find ("system:midi_capture_") == 0) {
530 if (label.empty ()) {
531 // "system:midi_capture_123" -> "123"
532 label = "M " + portname.substr (20);
534 } else if (label.find (program_port_prefix) == 0) {
535 label = label.substr (program_port_prefix.size ());
537 string::size_type slash = label.find ("/");
538 if (slash != string::npos) {
539 label = label.substr (0, slash);
547 PluginPinDialog::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
550 std::string tip = p->name ();
551 std::vector<std::string> cns;
552 bool single_source = true;
553 p->get_connections (cns);
555 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
557 lbl = port_label (*i, true);
560 if (port_label (*i, true) != lbl) {
562 single_source = false;
567 if (cns.size () == 0) {
569 single_source = false;
570 } else if (cns.size () == 1) {
572 lbl = port_label (cns[0], false);
576 replace_all (lbl, "_", " ");
578 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
583 ArdourButton *pb = manage (new ArdourButton (lbl));
584 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
585 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
586 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
587 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
589 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::sc_input_press), boost::weak_ptr<Port> (p)), false);
590 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::sc_input_release), false);
592 pb = manage (new ArdourButton ("-"));
593 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
595 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::remove_port), boost::weak_ptr<Port> (p)));
597 pb->set_sensitive (false);
602 if (single_source && _session) {
603 /* check if it's an Ardour Send feeding.. */
604 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
605 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
607 boost::shared_ptr<Processor> proc;
608 /* nth_send () takes a processor read-lock */
609 while ((proc = (*i)->nth_send (nth))) {
610 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
611 if (!send || !send->output ()) {
615 if (!send->output ()->connected_to (p->name ())) {
619 /* if processor goes away, we're notified by the port disconnect,
620 * there should be no need to explicily connect to proc->DropReferences
622 set<Evoral::Parameter> p = proc->what_can_be_automated ();
623 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
624 Control* c = new Control (proc->automation_control (*i), _("Send"));
625 _controls.push_back (c);
627 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
637 PluginPinDialog::update_element_pos ()
640 _innerwidth = _width - 2. * _margin_x;
642 const double yc = rint (_height * .5);
643 const double bxh2 = rint (_margin_y * .45); // TODO grow?
644 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
645 const double bxw2 = rint (bxw * .5);
646 const double y_in = _margin_y;
647 const double y_out = _height - _margin_y;
652 const double dx = _pin_box_size * .5;
655 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
659 i->x = _innerwidth + _margin_x - dx;
660 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
661 i->h = _pin_box_size;
662 i->w = 1.5 * _pin_box_size;
665 uint32_t idx = i->e->id;
666 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
667 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
668 i->w = _pin_box_size;
669 i->h = 1.5 * _pin_box_size;
675 uint32_t idx = i->e->id;
676 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
677 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
679 i->w = _pin_box_size;
680 i->h = 1.5 * _pin_box_size;
685 uint32_t idx = i->e->id;
686 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
687 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
688 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
689 i->y = yc - bxh2 - dx;
690 i->w = _pin_box_size;
691 i->h = _pin_box_size;
696 uint32_t idx = i->e->id;
697 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
698 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
699 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
700 i->y = yc + bxh2 - dx;
701 i->w = _pin_box_size;
702 i->h = _pin_box_size;
710 PluginPinDialog::set_color (cairo_t* cr, bool midi)
712 // see also gtk2_ardour/processor_box.cc
713 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
714 static const uint32_t midi_port_color = 0x960909FF; //Red
717 cairo_set_source_rgb (cr,
718 UINT_RGBA_R_FLT (midi_port_color),
719 UINT_RGBA_G_FLT (midi_port_color),
720 UINT_RGBA_B_FLT (midi_port_color));
722 cairo_set_source_rgb (cr,
723 UINT_RGBA_R_FLT (audio_port_color),
724 UINT_RGBA_G_FLT (audio_port_color),
725 UINT_RGBA_B_FLT (audio_port_color));
730 PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
733 const double dy = w.h * .5;
734 const double dx = w.w - dy;
735 cairo_move_to (cr, w.x, w.y + dy);
736 cairo_rel_line_to (cr, dy, -dy);
737 cairo_rel_line_to (cr, dx, 0);
738 cairo_rel_line_to (cr, 0, w.h);
739 cairo_rel_line_to (cr, -dx, 0);
741 const double dir = (w.e->ct == Input) ? 1 : -1;
742 const double dx = w.w * .5;
743 const double dy = w.h - dx;
745 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
746 cairo_rel_line_to (cr, -dx, -dx * dir);
747 cairo_rel_line_to (cr, 0., -dy * dir);
748 cairo_rel_line_to (cr, 2. * dx, 0.);
749 cairo_rel_line_to (cr, 0., dy * dir);
751 cairo_close_path (cr);
753 cairo_set_line_width (cr, 1.0);
754 cairo_set_source_rgb (cr, 0, 0, 0);
755 cairo_stroke_preserve (cr);
757 set_color (cr, w.e->dt == DataType::MIDI);
760 assert (w.e->ct == Input);
761 cairo_fill_preserve (cr);
762 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
765 if (w.e == _selection || w.e == _actor) {
766 cairo_fill_preserve (cr);
767 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
768 } else if (w.prelight) {
769 cairo_fill_preserve (cr);
770 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
776 PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
778 const double dx = w.w * .5;
779 const double dy = w.h * .5;
781 cairo_move_to (cr, w.x + dx, w.y);
782 cairo_rel_line_to (cr, -dx, dy);
783 cairo_rel_line_to (cr, dx, dy);
784 cairo_rel_line_to (cr, dx, -dy);
785 cairo_close_path (cr);
787 cairo_set_line_width (cr, 1.0);
788 cairo_set_source_rgb (cr, 0, 0, 0);
789 cairo_stroke_preserve (cr);
791 set_color (cr, w.e->dt == DataType::MIDI);
794 assert (w.e->ct == Sink);
795 cairo_fill_preserve (cr);
796 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
799 if (w.e == _selection || w.e == _actor) {
800 cairo_fill_preserve (cr);
801 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
802 } else if (w.prelight) {
803 cairo_fill_preserve (cr);
804 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
808 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
811 Glib::RefPtr<Pango::Layout> layout;
812 layout = Pango::Layout::create (get_pango_context ());
813 layout->set_text (w.name);
814 layout->get_pixel_size (text_width, text_height);
816 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
817 cairo_set_source_rgba (cr, 0, 0, 0, .5);
820 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
821 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
822 pango_cairo_show_layout (cr, layout->gobj ());
827 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
829 if (!midi) { i += n_midi; }
830 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
833 const PluginPinDialog::CtrlWidget&
834 PluginPinDialog::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
836 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
837 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
842 fatal << string_compose (_("programming error: %1"),
843 X_("Invalid Plugin I/O Port."))
845 abort (); /*NOTREACHED*/
846 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
847 return screw_old_compilers;
851 PluginPinDialog::edge_coordinates (const CtrlWidget& w, double &x, double &y)
879 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
881 const double bz = 2 * _pin_box_size;
882 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
883 if (x0 > _width * .5) { bc *= -1; }
885 cairo_move_to (cr, x0, y0);
887 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
889 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
891 cairo_set_line_width (cr, 3.0);
892 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
893 cairo_set_source_rgb (cr, 1, 0, 0);
895 const double dashes[] = { 5, 7 };
896 cairo_set_dash (cr, dashes, 2, 0);
898 set_color (cr, midi);
901 cairo_set_dash (cr, 0, 0, 0);
906 PluginPinDialog::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
908 double x0, x1, y0, y1;
909 edge_coordinates (w0, x0, y0);
910 edge_coordinates (w1, x1, y1);
911 assert (w0.e->dt == w1.e->dt);
912 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
917 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
919 Gtk::Allocation a = darea.get_allocation ();
920 double const width = a.get_width ();
921 double const height = a.get_height ();
923 if (!_position_valid) {
926 update_element_pos ();
927 _position_valid = true;
930 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
931 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
934 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
935 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
936 cairo_rectangle (cr, 0, 0, width, height);
939 const double yc = rint (_height * .5);
942 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
943 cairo_set_line_width (cr, 1.0);
944 cairo_set_source_rgb (cr, .1, .1, .3);
945 cairo_stroke_preserve (cr);
946 cairo_set_source_rgb (cr, .3, .3, .3);
950 Glib::RefPtr<Pango::Layout> layout;
951 layout = Pango::Layout::create (get_pango_context ());
953 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
954 layout->set_width (_height * PANGO_SCALE);
959 layout->set_text (_route ()->name ());
960 layout->get_pixel_size (text_width, text_height);
962 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
963 cairo_rotate (cr, M_PI * -.5);
964 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
965 pango_cairo_show_layout (cr, layout->gobj ());
969 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
970 layout->set_text (_pi->name ());
971 layout->get_pixel_size (text_width, text_height);
972 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
973 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
974 pango_cairo_show_layout (cr, layout->gobj ());
976 if (_pi->signal_latency () > 0) {
977 // TODO: this needs a better location also format to msec (and cache)
978 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
979 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
980 layout->get_pixel_size (text_width, text_height);
981 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
982 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
983 pango_cairo_show_layout (cr, layout->gobj ());
986 if (_pi->strict_io () && !Profile->get_mixbus ()) {
987 layout->set_text (_("Strict I/O"));
988 layout->get_pixel_size (text_width, text_height);
989 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
990 const double sy0 = _height - 3 - text_height;
992 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
993 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
996 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
997 cairo_move_to (cr, sx0, sy0);
998 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
999 pango_cairo_show_layout (cr, layout->gobj ());
1002 /* draw midi-bypass (behind) */
1003 if (_has_midi_bypass) {
1004 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1005 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1006 draw_connection (cr, cw0, cw1, true);
1009 /* thru connections */
1010 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1011 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1012 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1013 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1014 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1015 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1016 draw_connection (cr, cw1, cw0, true);
1021 /* plugins & connection wires */
1022 for (uint32_t i = 0; i < _n_plugins; ++i) {
1023 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1026 cairo_set_source_rgb (cr, .5, .5, .5);
1027 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1030 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1031 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1032 layout->get_pixel_size (text_width, text_height);
1033 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1034 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1035 pango_cairo_show_layout (cr, layout->gobj ());
1037 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1038 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1040 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1041 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1042 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1043 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1044 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1045 draw_connection (cr, cw0, cw1);
1050 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1051 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1052 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1053 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1054 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1055 draw_connection (cr, cw0, cw1);
1061 /* pins and ports */
1062 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1066 draw_io_pin (cr, *i);
1070 draw_plugin_pin (cr, *i);
1076 CtrlWidget *drag_src = NULL;
1078 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1079 if (i->e == _selection ) {
1087 if (_selection->ct == Input || _selection->ct == Source) {
1088 edge_coordinates (*drag_src, x0, y0);
1089 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1090 _selection->dt == DataType::MIDI, _selection->sc);
1092 edge_coordinates (*drag_src, x0, y0);
1093 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1094 _selection->dt == DataType::MIDI, _selection->sc);
1103 PluginPinDialog::darea_size_request (Gtk::Requisition* req)
1105 req->width = _min_width;
1106 req->height = _min_height;
1110 PluginPinDialog::darea_size_allocate (Gtk::Allocation&)
1112 _position_valid = false;
1116 PluginPinDialog::drag_type_matches (const CtrlElem& e)
1118 if (!_dragging || !_selection) {
1121 if (_selection->dt != e->dt) {
1124 if (_selection->ct == Input && e->ct == Sink) { return true; }
1125 if (_selection->ct == Sink && e->ct == Input) { return true; }
1126 if (_selection->ct == Output && e->ct == Source) { return true; }
1127 if (_selection->ct == Source && e->ct == Output) { return true; }
1128 if (_selection->ct == Input && e->ct == Output) { return true; }
1129 if (_selection->ct == Output && e->ct == Input) { return true; }
1134 PluginPinDialog::start_drag (const CtrlElem& e, double x, double y)
1136 assert (_selection == e);
1138 if (e->ct == Sink) {
1140 const ChanMapping& map (_in_map[e->ip]);
1141 uint32_t idx = map.get (e->dt, e->id, &valid);
1143 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1148 else if (e->ct == Output) {
1149 for (uint32_t i = 0; i < _n_plugins; ++i) {
1151 const ChanMapping& map (_out_map[i]);
1152 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1154 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1162 const ChanMapping& map (_thru_map);
1163 uint32_t idx = map.get (e->dt, e->id, &valid);
1165 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1177 PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev)
1179 bool changed = false;
1181 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1182 if (ev->x >= i->x && ev->x <= i->x + i->w
1183 && ev->y >= i->y && ev->y <= i->y + i->h
1184 && drag_type_matches (i->e))
1186 if (!i->prelight) changed = true;
1190 if (i->prelight) changed = true;
1191 i->prelight = false;
1198 if (changed || _dragging) {
1199 darea.queue_draw ();
1205 PluginPinDialog::darea_button_press_event (GdkEventButton* ev)
1207 if (ev->type != GDK_BUTTON_PRESS) {
1211 switch (ev->button) {
1214 if (!_selection || (_selection && !_hover)) {
1215 _selection = _hover;
1218 start_drag (_selection, ev->x, ev->y);
1220 darea.queue_draw ();
1222 } else if (_selection && _hover && _selection != _hover) {
1223 if (_selection->dt != _hover->dt) { _actor.reset (); }
1224 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1225 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1226 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1227 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1228 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1229 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1231 _selection = _hover;
1232 start_drag (_selection, ev->x, ev->y);
1234 darea.queue_draw ();
1236 } else if (_hover) {
1237 _selection = _hover;
1239 start_drag (_selection, ev->x, ev->y);
1244 if (_selection != _hover) {
1245 _selection = _hover;
1246 darea.queue_draw ();
1258 PluginPinDialog::darea_button_release_event (GdkEventButton* ev)
1260 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1261 // select click. (or re-connect same)
1262 assert (_selection != _hover);
1267 darea.queue_draw ();
1271 if (_dragging && _hover && _hover != _selection) {
1275 if (_hover == _actor && _actor && ev->button == 1) {
1276 assert (_selection);
1277 assert (_selection->dt == _actor->dt);
1279 assert (_dragging && _selection != _drag_dst);
1280 handle_disconnect (_drag_dst, true);
1282 if (_selection->ct == Input && _actor->ct == Sink) {
1283 handle_input_action (_actor, _selection);
1285 else if (_selection->ct == Sink && _actor->ct == Input) {
1286 handle_input_action (_selection, _actor);
1288 else if (_selection->ct == Output && _actor->ct == Source) {
1289 handle_output_action (_actor, _selection);
1291 else if (_selection->ct == Source && _actor->ct == Output) {
1292 handle_output_action (_selection, _actor);
1294 else if (_selection->ct == Input && _actor->ct == Output) {
1295 handle_thru_action (_actor, _selection);
1297 else if (_selection->ct == Output && _actor->ct == Input) {
1298 handle_thru_action (_selection, _actor);
1300 _selection.reset ();
1301 } else if (_hover == _selection && _selection && ev->button == 3) {
1302 handle_disconnect (_selection);
1303 } else if (!_hover && ev->button == 3) {
1304 reset_menu.popup (1, ev->time);
1307 if (_dragging && _hover != _selection) {
1308 _selection.reset ();
1313 darea.queue_draw ();
1318 PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1320 const int pc = s->ip;
1322 ChanMapping in_map (_pi->input_map (pc));
1323 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1325 if (valid && idx == i->id) {
1328 in_map.unset (s->dt, s->id);
1329 _pi->set_input_map (pc, in_map);
1331 plugin_reconfigured ();
1336 in_map.set (s->dt, s->id, i->id);
1337 _pi->set_input_map (pc, in_map);
1341 in_map.unset (s->dt, s->id);
1342 in_map.set (s->dt, s->id, i->id);
1343 _pi->set_input_map (pc, in_map);
1348 PluginPinDialog::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1350 _ignore_updates = true;
1351 for (uint32_t n = 0; n < _n_plugins; ++n) {
1356 ChanMapping n_out_map (_pi->output_map (n));
1357 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1359 n_out_map.unset (dt, idx);
1360 _pi->set_output_map (n, n_out_map);
1363 _ignore_updates = false;
1367 PluginPinDialog::disconnect_other_thru (DataType dt, uint32_t id)
1369 _ignore_updates = true;
1371 ChanMapping n_thru_map (_pi->thru_map ());
1372 n_thru_map.get (dt, id, &valid);
1374 n_thru_map.unset (dt, id);
1375 _pi->set_thru_map (n_thru_map);
1377 _ignore_updates = false;
1381 PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1383 const uint32_t pc = s->ip;
1385 ChanMapping out_map (_pi->output_map (pc));
1386 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1388 if (valid && idx == o->id) {
1391 out_map.unset (s->dt, s->id);
1392 _pi->set_output_map (pc, out_map);
1394 plugin_reconfigured ();
1398 // disconnect source
1399 disconnect_other_outputs (pc, s->dt, o->id);
1400 disconnect_other_thru (s->dt, o->id);
1401 out_map = _pi->output_map (pc); // re-read map
1403 out_map.unset (s->dt, s->id);
1405 idx = out_map.get_src (s->dt, o->id, &valid);
1407 out_map.unset (s->dt, idx);
1410 out_map.set (s->dt, s->id, o->id);
1411 _pi->set_output_map (pc, out_map);
1416 PluginPinDialog::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1419 ChanMapping thru_map (_pi->thru_map ());
1420 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1422 if (valid && idx == i->id) {
1424 thru_map.unset (o->dt, o->id);
1427 // disconnect other outputs first
1428 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1429 disconnect_other_thru (o->dt, o->id);
1430 thru_map = _pi->thru_map (); // re-read map
1432 thru_map.set (o->dt, o->id, i->id);
1434 _pi->set_thru_map (thru_map);
1438 PluginPinDialog::handle_disconnect (const CtrlElem &e, bool no_signal)
1440 _ignore_updates = true;
1441 bool changed = false;
1447 ChanMapping n_thru_map (_pi->thru_map ());
1448 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1449 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1450 if (valid && idx == e->id) {
1451 n_thru_map.unset (e->dt, i);
1456 _pi->set_thru_map (n_thru_map);
1459 for (uint32_t n = 0; n < _n_plugins; ++n) {
1460 ChanMapping map (_pi->input_map (n));
1461 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1462 uint32_t idx = map.get (e->dt, i, &valid);
1463 if (valid && idx == e->id) {
1464 map.unset (e->dt, i);
1468 _pi->set_input_map (n, map);
1473 ChanMapping map (_pi->input_map (e->ip));
1474 map.get (e->dt, e->id, &valid);
1476 map.unset (e->dt, e->id);
1477 _pi->set_input_map (e->ip, map);
1484 ChanMapping map (_pi->output_map (e->ip));
1485 map.get (e->dt, e->id, &valid);
1487 map.unset (e->dt, e->id);
1488 _pi->set_output_map (e->ip, map);
1494 for (uint32_t n = 0; n < _n_plugins; ++n) {
1495 ChanMapping map (_pi->output_map (n));
1496 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1497 uint32_t idx = map.get (e->dt, i, &valid);
1498 if (valid && idx == e->id) {
1499 map.unset (e->dt, i);
1504 _pi->set_output_map (n, map);
1508 ChanMapping n_thru_map (_pi->thru_map ());
1509 n_thru_map.get (e->dt, e->id, &valid);
1511 n_thru_map.unset (e->dt, e->id);
1513 _pi->set_thru_map (n_thru_map);
1518 _ignore_updates = false;
1519 if (changed && !no_signal) {
1520 plugin_reconfigured ();
1526 PluginPinDialog::toggle_sidechain ()
1528 if (_session && _session->actively_recording ()) { return; }
1529 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1533 PluginPinDialog::connect_sidechain ()
1535 if (!_session) { return; }
1537 if (_sidechain_selector == 0) {
1538 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1541 if (_sidechain_selector->is_visible ()) {
1542 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1544 _sidechain_selector->present ();
1549 PluginPinDialog::reset_configuration ()
1551 if (_set_config.get_active ()) {
1552 _route ()->reset_plugin_insert (_pi);
1554 _route ()->customize_plugin_insert (_pi, _n_plugins, _out);
1559 PluginPinDialog::reset_mapping ()
1565 PluginPinDialog::select_output_preset (uint32_t n_audio)
1567 if (_session && _session->actively_recording ()) { return; }
1568 ChanCount out (DataType::AUDIO, n_audio);
1569 _route ()->plugin_preset_output (_pi, out);
1573 PluginPinDialog::add_remove_plugin_clicked (bool add)
1575 if (_session && _session->actively_recording ()) { return; }
1576 ChanCount out = _out;
1577 assert (add || _n_plugins > 0);
1578 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out);
1582 PluginPinDialog::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1584 if (_session && _session->actively_recording ()) { return; }
1585 ChanCount out = _out;
1586 assert (add || out.get (dt) > 0);
1587 out.set (dt, out.get (dt) + (add ? 1 : -1));
1588 _route ()->customize_plugin_insert (_pi, _n_plugins, out);
1592 PluginPinDialog::add_sidechain_port (DataType dt)
1594 if (_session && _session->actively_recording ()) { return; }
1595 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1600 // this triggers a PluginIoReConfigure with process and processor write lock held
1601 // from /this/ thread.
1602 io->add_port ("", this, dt);
1606 PluginPinDialog::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1608 if (_session && _session->actively_recording ()) { return; }
1609 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1610 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1614 io->remove_port (p, this);
1618 PluginPinDialog::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1620 if (_session && _session->actively_recording ()) { return; }
1621 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1622 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1626 p->disconnect_all ();
1630 PluginPinDialog::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1632 if (_session && _session->actively_recording ()) { return; }
1633 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1634 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1635 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1636 if (!io || !p0 || !p1) {
1639 _ignore_updates = true;
1640 p0->disconnect_all ();
1641 _ignore_updates = false;
1642 p0->connect (p1->name ());
1646 PluginPinDialog::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1648 if (_session && _session->actively_recording ()) { return; }
1649 boost::shared_ptr<Port> p = wp.lock ();
1650 boost::shared_ptr<Route> r = wr.lock ();
1651 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1652 if (!p || !r || !io || !_session) {
1656 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1657 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1658 const ChanCount& outs (r->amp ()->input_streams ());
1660 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1661 send->output()->ensure_io (outs, false, this);
1662 } catch (AudioEngine::PortRegistrationFailure& err) {
1663 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1667 std::string sendname = send->name ();
1668 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1669 if (last_letter != string::npos) {
1670 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1672 sendname.substr (last_letter + 1)));
1675 _ignore_updates = true;
1676 p->disconnect_all ();
1678 DataType dt = p->type ();
1679 PortSet& ps (send->output ()->ports ());
1680 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1681 p->connect (&(**i));
1684 send->set_remove_on_disconnect (true);
1685 r->add_processor (send, PreFader);
1686 _ignore_updates = false;
1687 queue_idle_update ();
1691 PluginPinDialog::sc_input_release (GdkEventButton *ev)
1693 if (_session && _session->actively_recording ()) { return false; }
1694 if (ev->button == 3) {
1695 connect_sidechain ();
1700 struct RouteCompareByName {
1701 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1702 return a->name ().compare (b->name ()) < 0;
1707 PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1709 using namespace Menu_Helpers;
1710 if (!_session || _session->actively_recording ()) { return false; }
1711 if (!_session->engine ().connected ()) { return false; }
1713 if (ev->button == 1) {
1714 MenuList& citems = input_menu.items ();
1715 input_menu.set_name ("ArdourContextMenu");
1718 boost::shared_ptr<Port> p = wp.lock ();
1719 if (p && p->connected ()) {
1720 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::disconnect_port), wp)));
1721 citems.push_back (SeparatorElem ());
1725 // TODO add system inputs, too ?!
1726 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1727 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1728 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1730 //maybe_add_bundle_to_input_menu (*i, current);
1734 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1735 RouteList copy = *routes;
1736 copy.sort (RouteCompareByName ());
1738 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1739 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1743 citems.push_back (SeparatorElem ());
1745 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinDialog::connect_sidechain)));
1746 input_menu.popup (1, ev->time);
1752 PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1755 using namespace Menu_Helpers;
1756 if (r->output () == _route ()->output ()) {
1760 if (_route ()->feeds_according_to_graph (r)) {
1764 MenuList& citems = input_menu.items ();
1766 /*check if there's already a send.. */
1767 bool already_present = false;
1769 boost::shared_ptr<Processor> proc;
1770 /* Note: nth_send () takes a processor read-lock */
1771 while ((proc = r->nth_send (nth))) {
1772 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1773 if (!send || !send->output ()) {
1777 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1778 // only if (send->remove_on_disconnect ()) ??
1779 already_present = true;
1784 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1785 const ChanCount& rc (r->amp ()->input_streams ());
1786 if (!already_present && rc.get (dt) > 0) {
1787 citems.push_back (MenuElem (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_send_from), wp, boost::weak_ptr<Route> (r))));
1794 PluginPinDialog::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1796 boost::shared_ptr<Port> p0 = w0.lock ();
1797 boost::shared_ptr<Port> p1 = w1.lock ();
1799 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1800 if (!io) { return; }
1802 if (p0 && io->has_port (p0)) {
1803 queue_idle_update ();
1805 else if (p1 && io->has_port (p1)) {
1806 queue_idle_update ();
1810 /* lifted from ProcessorEntry::Control */
1811 PluginPinDialog::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1813 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1814 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1815 , _slider_persistant_tooltip (&_slider)
1816 , _ignore_ui_adjustment (false)
1819 _slider.set_controllable (c);
1820 box.set_padding (0, 0, 4, 4);
1822 _slider.set_name ("ProcessorControlSlider");
1823 _slider.set_text (_name);
1828 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1829 double const lo = c->internal_to_interface (desc.lower);
1830 double const up = c->internal_to_interface (desc.upper);
1831 double const normal = c->internal_to_interface (desc.normal);
1832 double smallstep = desc.smallstep;
1833 double largestep = desc.largestep;
1835 if (smallstep == 0.0) {
1836 smallstep = up / 1000.;
1838 smallstep = c->internal_to_interface (desc.lower + smallstep);
1841 if (largestep == 0.0) {
1842 largestep = up / 40.;
1844 largestep = c->internal_to_interface (desc.lower + largestep);
1847 _adjustment.set_lower (lo);
1848 _adjustment.set_upper (up);
1849 _adjustment.set_step_increment (smallstep);
1850 _adjustment.set_page_increment (largestep);
1851 _slider.set_default_value (normal);
1853 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1854 // dup. currently timers are used :(
1855 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1857 // yuck, do we really need to do this?
1858 // according to c404374 this is only needed for send automation
1859 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1864 /* We're providing our own PersistentTooltip */
1865 set_no_tooltip_whatsoever (_slider);
1868 PluginPinDialog::Control::~Control ()
1870 timer_connection.disconnect ();
1874 PluginPinDialog::Control::set_tooltip ()
1876 boost::shared_ptr<AutomationControl> c = _control.lock ();
1881 snprintf (tmp, sizeof (tmp), "%s: %.2f", _name.c_str (), c->internal_to_user (c->get_value ()));
1883 string sm = Gtkmm2ext::markup_escape_text (tmp);
1884 _slider_persistant_tooltip.set_tip (sm);
1888 PluginPinDialog::Control::slider_adjusted ()
1890 if (_ignore_ui_adjustment) {
1893 boost::shared_ptr<AutomationControl> c = _control.lock ();
1897 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1903 PluginPinDialog::Control::control_changed ()
1905 boost::shared_ptr<AutomationControl> c = _control.lock ();
1910 _ignore_ui_adjustment = true;
1912 // as long as rapid timers are used, only update the tooltip
1913 // if the value has changed.
1914 const double nval = c->internal_to_interface (c->get_value ());
1915 if (_adjustment.get_value () != nval) {
1916 _adjustment.set_value (nval);
1920 _ignore_ui_adjustment = false;