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 ());
288 if (_pi->plugin (0)->get_info()->type == ARDOUR::AudioUnit) {
289 _set_config.set_sensitive (false);
290 _tgl_sidechain.set_sensitive (false);
294 if (_pi->custom_cfg ()) {
295 _set_config.set_active (true);
296 _add_plugin.set_sensitive (true);
297 _add_output_audio.set_sensitive (true);
298 _add_output_midi.set_sensitive (true);
299 _del_plugin.set_sensitive (_n_plugins > 1);
300 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
301 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
302 _out_presets.set_sensitive (false);
303 _out_presets.set_text (_("Manual"));
305 _set_config.set_active (false);
306 _add_plugin.set_sensitive (false);
307 _add_output_audio.set_sensitive (false);
308 _add_output_midi.set_sensitive (false);
309 _del_plugin.set_sensitive (false);
310 _del_output_audio.set_sensitive (false);
311 _del_output_midi.set_sensitive (false);
312 _out_presets.set_sensitive (true);
313 refill_output_presets ();
316 if (!_pi->has_sidechain () && _sidechain_selector) {
317 delete _sidechain_selector;
318 _sidechain_selector = 0;
321 refill_sidechain_table ();
323 /* update elements */
332 _n_inputs = _n_sidechains = 0;
334 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
335 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
336 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
337 bool sidechain = id >= _in.get (dt) ? true : false;
344 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
345 _elements.push_back (cw);
348 for (uint32_t i = 0; i < _out.n_total (); ++i) {
349 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
350 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
356 for (uint32_t n = 0; n < _n_plugins; ++n) {
357 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
358 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
359 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
360 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
361 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
362 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
363 _elements.push_back (cw);
365 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
366 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
367 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
368 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
369 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
371 _in_map[n] = _pi->input_map (n);
372 _out_map[n] = _pi->output_map (n);
374 _has_midi_bypass = _pi->has_midi_bypass ();
375 _thru_map = _pi->thru_map ();
379 /* calc minimum size */
380 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
381 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
382 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
383 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
384 min_width = std::max ((uint32_t)300, min_width);
386 min_width = 50 + 10 * ceilf (min_width / 10.f);
388 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
389 min_height = std::max ((uint32_t)200, min_height);
390 min_height = 4 * ceilf (min_height / 4.f);
392 if (min_width != _min_width || min_height != _min_height) {
393 _min_width = min_width;
394 _min_height = min_height;
395 darea.queue_resize ();
398 _position_valid = false;
403 PluginPinDialog::refill_sidechain_table ()
405 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
406 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
409 _sidechain_tbl->resize (1, 1);
410 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
414 if (!_pi->has_sidechain () && _sidechain_selector) {
417 boost::shared_ptr<IO> io = _pi->sidechain_input ();
423 PortSet& p (io->ports ());
424 bool can_remove = p.num_ports () > 1;
425 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
426 r += add_port_to_table (*i, r, can_remove);
428 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
429 r += add_port_to_table (*i, r, can_remove);
431 _sidechain_tbl->show_all ();
435 PluginPinDialog::refill_output_presets ()
437 using namespace Menu_Helpers;
438 _out_presets.clear_items ();
439 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
441 bool need_dropdown = true;
443 if (ppc.size () == 0) {
444 need_dropdown = false;
447 if (!_pi->strict_io () && ppc.size () == 1) {
448 need_dropdown = false;
451 if (_pi->strict_io () && ppc.size () == 1) {
452 // "stereo" is currently preferred default for instruments, see PluginInsert
453 if (ppc.find (2) != ppc.end ()) {
454 need_dropdown = false;
458 if (!_pi->needs_midi_input ()) {
459 /* loose definition of instruments, maybe impose additional
460 * || _pi->natural_input_streams ().n_audio () != 0
461 * and special case variable output plugins
462 * && !_pi->plugin (0)->info->reconfigurable_io()
464 need_dropdown = false;
467 if (!need_dropdown) {
468 _out_presets.set_sensitive (false);
469 _out_presets.set_text (_("Automatic"));
473 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), 0)));
475 const uint32_t n_audio = _pi->preset_out ().n_audio ();
477 _out_presets.set_text (_("Automatic"));
480 if (ppc.find (0) != ppc.end ()) {
484 ppc.insert (n_audio);
494 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
505 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
508 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), *i)));
510 _out_presets.set_text (tmp);
516 PluginPinDialog::port_label (const std::string& portname, bool strip)
518 // compare to MixerStrip::update_io_button()
519 string lpn (PROGRAM_NAME);
520 boost::to_lower (lpn);
521 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
523 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
525 string::size_type slash = pn.find ("/");
526 if (slash != string::npos) {
527 pn = pn.substr (0, slash);
531 std::string label (portname);
532 if (label.find ("system:capture_") == 0) {
533 if (label.empty ()) {
534 label = portname.substr (15);
536 } else if (label.find ("system:midi_capture_") == 0) {
537 if (label.empty ()) {
538 // "system:midi_capture_123" -> "123"
539 label = "M " + portname.substr (20);
541 } else if (label.find (program_port_prefix) == 0) {
542 label = label.substr (program_port_prefix.size ());
544 string::size_type slash = label.find ("/");
545 if (slash != string::npos) {
546 label = label.substr (0, slash);
554 PluginPinDialog::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
557 std::string tip = p->name ();
558 std::vector<std::string> cns;
559 bool single_source = true;
560 p->get_connections (cns);
562 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
564 lbl = port_label (*i, true);
567 if (port_label (*i, true) != lbl) {
569 single_source = false;
574 if (cns.size () == 0) {
576 single_source = false;
577 } else if (cns.size () == 1) {
579 lbl = port_label (cns[0], false);
583 replace_all (lbl, "_", " ");
585 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
590 ArdourButton *pb = manage (new ArdourButton (lbl));
591 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
592 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
593 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
594 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
596 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::sc_input_press), boost::weak_ptr<Port> (p)), false);
597 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::sc_input_release), false);
599 pb = manage (new ArdourButton ("-"));
600 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
602 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::remove_port), boost::weak_ptr<Port> (p)));
604 pb->set_sensitive (false);
609 if (single_source && _session) {
610 /* check if it's an Ardour Send feeding.. */
611 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
612 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
614 boost::shared_ptr<Processor> proc;
615 /* nth_send () takes a processor read-lock */
616 while ((proc = (*i)->nth_send (nth))) {
617 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
618 if (!send || !send->output ()) {
622 if (!send->output ()->connected_to (p->name ())) {
626 /* if processor goes away, we're notified by the port disconnect,
627 * there should be no need to explicily connect to proc->DropReferences
629 set<Evoral::Parameter> p = proc->what_can_be_automated ();
630 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
631 Control* c = new Control (proc->automation_control (*i), _("Send"));
632 _controls.push_back (c);
634 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
644 PluginPinDialog::update_element_pos ()
647 _innerwidth = _width - 2. * _margin_x;
649 const double yc = rint (_height * .5);
650 const double bxh2 = rint (_margin_y * .45); // TODO grow?
651 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
652 const double bxw2 = rint (bxw * .5);
653 const double y_in = _margin_y;
654 const double y_out = _height - _margin_y;
659 const double dx = _pin_box_size * .5;
662 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
666 i->x = _innerwidth + _margin_x - dx;
667 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
668 i->h = _pin_box_size;
669 i->w = 1.5 * _pin_box_size;
672 uint32_t idx = i->e->id;
673 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
674 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
675 i->w = _pin_box_size;
676 i->h = 1.5 * _pin_box_size;
682 uint32_t idx = i->e->id;
683 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
684 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
686 i->w = _pin_box_size;
687 i->h = 1.5 * _pin_box_size;
692 uint32_t idx = i->e->id;
693 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
694 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
695 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
696 i->y = yc - bxh2 - dx;
697 i->w = _pin_box_size;
698 i->h = _pin_box_size;
703 uint32_t idx = i->e->id;
704 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
705 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
706 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
707 i->y = yc + bxh2 - dx;
708 i->w = _pin_box_size;
709 i->h = _pin_box_size;
717 PluginPinDialog::set_color (cairo_t* cr, bool midi)
719 // see also gtk2_ardour/processor_box.cc
720 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
721 static const uint32_t midi_port_color = 0x960909FF; //Red
724 cairo_set_source_rgb (cr,
725 UINT_RGBA_R_FLT (midi_port_color),
726 UINT_RGBA_G_FLT (midi_port_color),
727 UINT_RGBA_B_FLT (midi_port_color));
729 cairo_set_source_rgb (cr,
730 UINT_RGBA_R_FLT (audio_port_color),
731 UINT_RGBA_G_FLT (audio_port_color),
732 UINT_RGBA_B_FLT (audio_port_color));
737 PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
740 const double dy = w.h * .5;
741 const double dx = w.w - dy;
742 cairo_move_to (cr, w.x, w.y + dy);
743 cairo_rel_line_to (cr, dy, -dy);
744 cairo_rel_line_to (cr, dx, 0);
745 cairo_rel_line_to (cr, 0, w.h);
746 cairo_rel_line_to (cr, -dx, 0);
748 const double dir = (w.e->ct == Input) ? 1 : -1;
749 const double dx = w.w * .5;
750 const double dy = w.h - dx;
752 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
753 cairo_rel_line_to (cr, -dx, -dx * dir);
754 cairo_rel_line_to (cr, 0., -dy * dir);
755 cairo_rel_line_to (cr, 2. * dx, 0.);
756 cairo_rel_line_to (cr, 0., dy * dir);
758 cairo_close_path (cr);
760 cairo_set_line_width (cr, 1.0);
761 cairo_set_source_rgb (cr, 0, 0, 0);
762 cairo_stroke_preserve (cr);
764 set_color (cr, w.e->dt == DataType::MIDI);
767 assert (w.e->ct == Input);
768 cairo_fill_preserve (cr);
769 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
772 if (w.e == _selection || w.e == _actor) {
773 cairo_fill_preserve (cr);
774 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
775 } else if (w.prelight) {
776 cairo_fill_preserve (cr);
777 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
783 PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
785 const double dx = w.w * .5;
786 const double dy = w.h * .5;
788 cairo_move_to (cr, w.x + dx, w.y);
789 cairo_rel_line_to (cr, -dx, dy);
790 cairo_rel_line_to (cr, dx, dy);
791 cairo_rel_line_to (cr, dx, -dy);
792 cairo_close_path (cr);
794 cairo_set_line_width (cr, 1.0);
795 cairo_set_source_rgb (cr, 0, 0, 0);
796 cairo_stroke_preserve (cr);
798 set_color (cr, w.e->dt == DataType::MIDI);
801 assert (w.e->ct == Sink);
802 cairo_fill_preserve (cr);
803 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
806 if (w.e == _selection || w.e == _actor) {
807 cairo_fill_preserve (cr);
808 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
809 } else if (w.prelight) {
810 cairo_fill_preserve (cr);
811 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
815 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
818 Glib::RefPtr<Pango::Layout> layout;
819 layout = Pango::Layout::create (get_pango_context ());
820 layout->set_text (w.name);
821 layout->get_pixel_size (text_width, text_height);
823 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
824 cairo_set_source_rgba (cr, 0, 0, 0, .5);
827 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
828 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
829 pango_cairo_show_layout (cr, layout->gobj ());
834 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
836 if (!midi) { i += n_midi; }
837 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
840 const PluginPinDialog::CtrlWidget&
841 PluginPinDialog::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
843 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
844 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
849 fatal << string_compose (_("programming error: %1"),
850 X_("Invalid Plugin I/O Port."))
852 abort (); /*NOTREACHED*/
853 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
854 return screw_old_compilers;
858 PluginPinDialog::edge_coordinates (const CtrlWidget& w, double &x, double &y)
886 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
888 const double bz = 2 * _pin_box_size;
889 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
890 if (x0 > _width * .5) { bc *= -1; }
892 cairo_move_to (cr, x0, y0);
894 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
896 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
898 cairo_set_line_width (cr, 3.0);
899 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
900 cairo_set_source_rgb (cr, 1, 0, 0);
902 const double dashes[] = { 5, 7 };
903 cairo_set_dash (cr, dashes, 2, 0);
905 set_color (cr, midi);
908 cairo_set_dash (cr, 0, 0, 0);
913 PluginPinDialog::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
915 double x0, x1, y0, y1;
916 edge_coordinates (w0, x0, y0);
917 edge_coordinates (w1, x1, y1);
918 assert (w0.e->dt == w1.e->dt);
919 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
924 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
926 Gtk::Allocation a = darea.get_allocation ();
927 double const width = a.get_width ();
928 double const height = a.get_height ();
930 if (!_position_valid) {
933 update_element_pos ();
934 _position_valid = true;
937 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
938 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
941 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
942 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
943 cairo_rectangle (cr, 0, 0, width, height);
946 const double yc = rint (_height * .5);
949 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
950 cairo_set_line_width (cr, 1.0);
951 cairo_set_source_rgb (cr, .1, .1, .3);
952 cairo_stroke_preserve (cr);
953 cairo_set_source_rgb (cr, .3, .3, .3);
957 Glib::RefPtr<Pango::Layout> layout;
958 layout = Pango::Layout::create (get_pango_context ());
960 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
961 layout->set_width (_height * PANGO_SCALE);
966 layout->set_text (_route ()->name ());
967 layout->get_pixel_size (text_width, text_height);
969 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
970 cairo_rotate (cr, M_PI * -.5);
971 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
972 pango_cairo_show_layout (cr, layout->gobj ());
976 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
977 layout->set_text (_pi->name ());
978 layout->get_pixel_size (text_width, text_height);
979 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
980 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
981 pango_cairo_show_layout (cr, layout->gobj ());
984 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
985 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
986 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
987 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
988 } else if (_pi->signal_latency () > 0) {
989 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
991 layout->set_text (_("no-inplace"));
993 layout->get_pixel_size (text_width, text_height);
994 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
995 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
996 pango_cairo_show_layout (cr, layout->gobj ());
1000 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1001 layout->set_text (_("Strict I/O"));
1002 layout->get_pixel_size (text_width, text_height);
1003 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1004 const double sy0 = _height - 3 - text_height;
1006 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1007 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1010 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1011 cairo_move_to (cr, sx0, sy0);
1012 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1013 pango_cairo_show_layout (cr, layout->gobj ());
1016 /* draw midi-bypass (behind) */
1017 if (_has_midi_bypass) {
1018 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1019 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1020 draw_connection (cr, cw0, cw1, true);
1023 /* thru connections */
1024 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1025 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1026 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1027 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1028 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1029 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1030 draw_connection (cr, cw1, cw0, true);
1035 /* plugins & connection wires */
1036 for (uint32_t i = 0; i < _n_plugins; ++i) {
1037 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1040 cairo_set_source_rgb (cr, .5, .5, .5);
1041 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1044 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1045 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1046 layout->get_pixel_size (text_width, text_height);
1047 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1048 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1049 pango_cairo_show_layout (cr, layout->gobj ());
1051 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1052 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1054 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1055 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1056 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1057 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1058 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1059 draw_connection (cr, cw0, cw1);
1064 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1065 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1066 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1067 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1068 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1069 draw_connection (cr, cw0, cw1);
1075 /* pins and ports */
1076 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1080 draw_io_pin (cr, *i);
1084 draw_plugin_pin (cr, *i);
1090 CtrlWidget *drag_src = NULL;
1092 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1093 if (i->e == _selection ) {
1101 if (_selection->ct == Input || _selection->ct == Source) {
1102 edge_coordinates (*drag_src, x0, y0);
1103 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1104 _selection->dt == DataType::MIDI, _selection->sc);
1106 edge_coordinates (*drag_src, x0, y0);
1107 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1108 _selection->dt == DataType::MIDI, _selection->sc);
1117 PluginPinDialog::darea_size_request (Gtk::Requisition* req)
1119 req->width = _min_width;
1120 req->height = _min_height;
1124 PluginPinDialog::darea_size_allocate (Gtk::Allocation&)
1126 _position_valid = false;
1130 PluginPinDialog::drag_type_matches (const CtrlElem& e)
1132 if (!_dragging || !_selection) {
1135 if (_selection->dt != e->dt) {
1138 if (_selection->ct == Input && e->ct == Sink) { return true; }
1139 if (_selection->ct == Sink && e->ct == Input) { return true; }
1140 if (_selection->ct == Output && e->ct == Source) { return true; }
1141 if (_selection->ct == Source && e->ct == Output) { return true; }
1142 if (_selection->ct == Input && e->ct == Output) { return true; }
1143 if (_selection->ct == Output && e->ct == Input) { return true; }
1148 PluginPinDialog::start_drag (const CtrlElem& e, double x, double y)
1150 assert (_selection == e);
1152 if (e->ct == Sink) {
1154 const ChanMapping& map (_in_map[e->ip]);
1155 uint32_t idx = map.get (e->dt, e->id, &valid);
1157 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1162 else if (e->ct == Output) {
1163 for (uint32_t i = 0; i < _n_plugins; ++i) {
1165 const ChanMapping& map (_out_map[i]);
1166 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1168 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1176 const ChanMapping& map (_thru_map);
1177 uint32_t idx = map.get (e->dt, e->id, &valid);
1179 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1191 PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev)
1193 bool changed = false;
1195 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1196 if (ev->x >= i->x && ev->x <= i->x + i->w
1197 && ev->y >= i->y && ev->y <= i->y + i->h
1198 && drag_type_matches (i->e))
1200 if (!i->prelight) changed = true;
1204 if (i->prelight) changed = true;
1205 i->prelight = false;
1212 if (changed || _dragging) {
1213 darea.queue_draw ();
1219 PluginPinDialog::darea_button_press_event (GdkEventButton* ev)
1221 if (ev->type != GDK_BUTTON_PRESS) {
1225 switch (ev->button) {
1228 if (!_selection || (_selection && !_hover)) {
1229 _selection = _hover;
1232 start_drag (_selection, ev->x, ev->y);
1234 darea.queue_draw ();
1236 } else if (_selection && _hover && _selection != _hover) {
1237 if (_selection->dt != _hover->dt) { _actor.reset (); }
1238 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1239 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1240 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1241 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1242 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1243 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1245 _selection = _hover;
1246 start_drag (_selection, ev->x, ev->y);
1248 darea.queue_draw ();
1250 } else if (_hover) {
1251 _selection = _hover;
1253 start_drag (_selection, ev->x, ev->y);
1258 if (_selection != _hover) {
1259 _selection = _hover;
1260 darea.queue_draw ();
1272 PluginPinDialog::darea_button_release_event (GdkEventButton* ev)
1274 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1275 // select click. (or re-connect same)
1276 assert (_selection != _hover);
1281 darea.queue_draw ();
1285 if (_dragging && _hover && _hover != _selection) {
1289 if (_hover == _actor && _actor && ev->button == 1) {
1290 assert (_selection);
1291 assert (_selection->dt == _actor->dt);
1293 assert (_dragging && _selection != _drag_dst);
1294 handle_disconnect (_drag_dst, true);
1296 if (_selection->ct == Input && _actor->ct == Sink) {
1297 handle_input_action (_actor, _selection);
1299 else if (_selection->ct == Sink && _actor->ct == Input) {
1300 handle_input_action (_selection, _actor);
1302 else if (_selection->ct == Output && _actor->ct == Source) {
1303 handle_output_action (_actor, _selection);
1305 else if (_selection->ct == Source && _actor->ct == Output) {
1306 handle_output_action (_selection, _actor);
1308 else if (_selection->ct == Input && _actor->ct == Output) {
1309 handle_thru_action (_actor, _selection);
1311 else if (_selection->ct == Output && _actor->ct == Input) {
1312 handle_thru_action (_selection, _actor);
1314 _selection.reset ();
1315 } else if (_hover == _selection && _selection && ev->button == 3) {
1316 handle_disconnect (_selection);
1317 } else if (!_hover && ev->button == 3) {
1318 reset_menu.popup (1, ev->time);
1321 if (_dragging && _hover != _selection) {
1322 _selection.reset ();
1327 darea.queue_draw ();
1332 PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1334 const int pc = s->ip;
1336 ChanMapping in_map (_pi->input_map (pc));
1337 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1339 if (valid && idx == i->id) {
1342 in_map.unset (s->dt, s->id);
1343 _pi->set_input_map (pc, in_map);
1345 plugin_reconfigured ();
1350 in_map.set (s->dt, s->id, i->id);
1351 _pi->set_input_map (pc, in_map);
1355 in_map.unset (s->dt, s->id);
1356 in_map.set (s->dt, s->id, i->id);
1357 _pi->set_input_map (pc, in_map);
1362 PluginPinDialog::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1364 _ignore_updates = true;
1365 for (uint32_t n = 0; n < _n_plugins; ++n) {
1370 ChanMapping n_out_map (_pi->output_map (n));
1371 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1373 n_out_map.unset (dt, idx);
1374 _pi->set_output_map (n, n_out_map);
1377 _ignore_updates = false;
1381 PluginPinDialog::disconnect_other_thru (DataType dt, uint32_t id)
1383 _ignore_updates = true;
1385 ChanMapping n_thru_map (_pi->thru_map ());
1386 n_thru_map.get (dt, id, &valid);
1388 n_thru_map.unset (dt, id);
1389 _pi->set_thru_map (n_thru_map);
1391 _ignore_updates = false;
1395 PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1397 const uint32_t pc = s->ip;
1399 ChanMapping out_map (_pi->output_map (pc));
1400 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1402 if (valid && idx == o->id) {
1405 out_map.unset (s->dt, s->id);
1406 _pi->set_output_map (pc, out_map);
1408 plugin_reconfigured ();
1412 // disconnect source
1413 disconnect_other_outputs (pc, s->dt, o->id);
1414 disconnect_other_thru (s->dt, o->id);
1415 out_map = _pi->output_map (pc); // re-read map
1417 out_map.unset (s->dt, s->id);
1419 idx = out_map.get_src (s->dt, o->id, &valid);
1421 out_map.unset (s->dt, idx);
1424 out_map.set (s->dt, s->id, o->id);
1425 _pi->set_output_map (pc, out_map);
1430 PluginPinDialog::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1433 ChanMapping thru_map (_pi->thru_map ());
1434 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1436 if (valid && idx == i->id) {
1438 thru_map.unset (o->dt, o->id);
1441 // disconnect other outputs first
1442 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1443 disconnect_other_thru (o->dt, o->id);
1444 thru_map = _pi->thru_map (); // re-read map
1446 thru_map.set (o->dt, o->id, i->id);
1448 _pi->set_thru_map (thru_map);
1452 PluginPinDialog::handle_disconnect (const CtrlElem &e, bool no_signal)
1454 _ignore_updates = true;
1455 bool changed = false;
1461 ChanMapping n_thru_map (_pi->thru_map ());
1462 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1463 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1464 if (valid && idx == e->id) {
1465 n_thru_map.unset (e->dt, i);
1470 _pi->set_thru_map (n_thru_map);
1473 for (uint32_t n = 0; n < _n_plugins; ++n) {
1474 ChanMapping map (_pi->input_map (n));
1475 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1476 uint32_t idx = map.get (e->dt, i, &valid);
1477 if (valid && idx == e->id) {
1478 map.unset (e->dt, i);
1482 _pi->set_input_map (n, map);
1487 ChanMapping map (_pi->input_map (e->ip));
1488 map.get (e->dt, e->id, &valid);
1490 map.unset (e->dt, e->id);
1491 _pi->set_input_map (e->ip, map);
1498 ChanMapping map (_pi->output_map (e->ip));
1499 map.get (e->dt, e->id, &valid);
1501 map.unset (e->dt, e->id);
1502 _pi->set_output_map (e->ip, map);
1508 for (uint32_t n = 0; n < _n_plugins; ++n) {
1509 ChanMapping map (_pi->output_map (n));
1510 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1511 uint32_t idx = map.get (e->dt, i, &valid);
1512 if (valid && idx == e->id) {
1513 map.unset (e->dt, i);
1518 _pi->set_output_map (n, map);
1522 ChanMapping n_thru_map (_pi->thru_map ());
1523 n_thru_map.get (e->dt, e->id, &valid);
1525 n_thru_map.unset (e->dt, e->id);
1527 _pi->set_thru_map (n_thru_map);
1532 _ignore_updates = false;
1533 if (changed && !no_signal) {
1534 plugin_reconfigured ();
1540 PluginPinDialog::toggle_sidechain ()
1542 if (_session && _session->actively_recording ()) { return; }
1543 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1547 PluginPinDialog::connect_sidechain ()
1549 if (!_session) { return; }
1551 if (_sidechain_selector == 0) {
1552 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1555 if (_sidechain_selector->is_visible ()) {
1556 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1558 _sidechain_selector->present ();
1563 PluginPinDialog::reset_configuration ()
1565 if (_set_config.get_active ()) {
1566 _route ()->reset_plugin_insert (_pi);
1568 _route ()->customize_plugin_insert (_pi, _n_plugins, _out);
1573 PluginPinDialog::reset_mapping ()
1579 PluginPinDialog::select_output_preset (uint32_t n_audio)
1581 if (_session && _session->actively_recording ()) { return; }
1582 ChanCount out (DataType::AUDIO, n_audio);
1583 _route ()->plugin_preset_output (_pi, out);
1587 PluginPinDialog::add_remove_plugin_clicked (bool add)
1589 if (_session && _session->actively_recording ()) { return; }
1590 ChanCount out = _out;
1591 assert (add || _n_plugins > 0);
1592 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out);
1596 PluginPinDialog::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1598 if (_session && _session->actively_recording ()) { return; }
1599 ChanCount out = _out;
1600 assert (add || out.get (dt) > 0);
1601 out.set (dt, out.get (dt) + (add ? 1 : -1));
1602 _route ()->customize_plugin_insert (_pi, _n_plugins, out);
1606 PluginPinDialog::add_sidechain_port (DataType dt)
1608 if (_session && _session->actively_recording ()) { return; }
1609 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1614 // this triggers a PluginIoReConfigure with process and processor write lock held
1615 // from /this/ thread.
1616 io->add_port ("", this, dt);
1620 PluginPinDialog::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1622 if (_session && _session->actively_recording ()) { return; }
1623 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1624 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1628 io->remove_port (p, this);
1632 PluginPinDialog::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1634 if (_session && _session->actively_recording ()) { return; }
1635 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1636 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1640 p->disconnect_all ();
1644 PluginPinDialog::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1646 if (_session && _session->actively_recording ()) { return; }
1647 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1648 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1649 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1650 if (!io || !p0 || !p1) {
1653 _ignore_updates = true;
1654 p0->disconnect_all ();
1655 _ignore_updates = false;
1656 p0->connect (p1->name ());
1660 PluginPinDialog::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1662 if (_session && _session->actively_recording ()) { return; }
1663 boost::shared_ptr<Port> p = wp.lock ();
1664 boost::shared_ptr<Route> r = wr.lock ();
1665 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1666 if (!p || !r || !io || !_session) {
1670 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1671 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1672 const ChanCount& outs (r->amp ()->input_streams ());
1674 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1675 send->output()->ensure_io (outs, false, this);
1676 } catch (AudioEngine::PortRegistrationFailure& err) {
1677 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1681 std::string sendname = send->name ();
1682 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1683 if (last_letter != string::npos) {
1684 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1686 sendname.substr (last_letter + 1)));
1689 _ignore_updates = true;
1690 p->disconnect_all ();
1692 DataType dt = p->type ();
1693 PortSet& ps (send->output ()->ports ());
1694 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1695 p->connect (&(**i));
1698 send->set_remove_on_disconnect (true);
1699 r->add_processor (send, PreFader);
1700 _ignore_updates = false;
1701 queue_idle_update ();
1705 PluginPinDialog::sc_input_release (GdkEventButton *ev)
1707 if (_session && _session->actively_recording ()) { return false; }
1708 if (ev->button == 3) {
1709 connect_sidechain ();
1714 struct RouteCompareByName {
1715 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1716 return a->name ().compare (b->name ()) < 0;
1721 PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1723 using namespace Menu_Helpers;
1724 if (!_session || _session->actively_recording ()) { return false; }
1725 if (!_session->engine ().connected ()) { return false; }
1727 if (ev->button == 1) {
1728 MenuList& citems = input_menu.items ();
1729 input_menu.set_name ("ArdourContextMenu");
1732 boost::shared_ptr<Port> p = wp.lock ();
1733 if (p && p->connected ()) {
1734 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::disconnect_port), wp)));
1735 citems.push_back (SeparatorElem ());
1739 // TODO add system inputs, too ?!
1740 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1741 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1742 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1744 //maybe_add_bundle_to_input_menu (*i, current);
1748 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1749 RouteList copy = *routes;
1750 copy.sort (RouteCompareByName ());
1752 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1753 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1757 citems.push_back (SeparatorElem ());
1759 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinDialog::connect_sidechain)));
1760 input_menu.popup (1, ev->time);
1766 PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1769 using namespace Menu_Helpers;
1770 if (r->output () == _route ()->output ()) {
1774 if (_route ()->feeds_according_to_graph (r)) {
1778 MenuList& citems = input_menu.items ();
1780 /*check if there's already a send.. */
1781 bool already_present = false;
1783 boost::shared_ptr<Processor> proc;
1784 /* Note: nth_send () takes a processor read-lock */
1785 while ((proc = r->nth_send (nth))) {
1786 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1787 if (!send || !send->output ()) {
1791 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1792 // only if (send->remove_on_disconnect ()) ??
1793 already_present = true;
1798 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1799 const ChanCount& rc (r->amp ()->input_streams ());
1800 if (!already_present && rc.get (dt) > 0) {
1801 citems.push_back (MenuElem (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_send_from), wp, boost::weak_ptr<Route> (r))));
1808 PluginPinDialog::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1810 boost::shared_ptr<Port> p0 = w0.lock ();
1811 boost::shared_ptr<Port> p1 = w1.lock ();
1813 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1814 if (!io) { return; }
1816 if (p0 && io->has_port (p0)) {
1817 queue_idle_update ();
1819 else if (p1 && io->has_port (p1)) {
1820 queue_idle_update ();
1824 /* lifted from ProcessorEntry::Control */
1825 PluginPinDialog::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1827 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1828 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1829 , _slider_persistant_tooltip (&_slider)
1830 , _ignore_ui_adjustment (false)
1833 _slider.set_controllable (c);
1834 box.set_padding (0, 0, 4, 4);
1836 _slider.set_name ("ProcessorControlSlider");
1837 _slider.set_text (_name);
1842 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1843 double const lo = c->internal_to_interface (desc.lower);
1844 double const up = c->internal_to_interface (desc.upper);
1845 double const normal = c->internal_to_interface (desc.normal);
1846 double smallstep = desc.smallstep;
1847 double largestep = desc.largestep;
1849 if (smallstep == 0.0) {
1850 smallstep = up / 1000.;
1852 smallstep = c->internal_to_interface (desc.lower + smallstep);
1855 if (largestep == 0.0) {
1856 largestep = up / 40.;
1858 largestep = c->internal_to_interface (desc.lower + largestep);
1861 _adjustment.set_lower (lo);
1862 _adjustment.set_upper (up);
1863 _adjustment.set_step_increment (smallstep);
1864 _adjustment.set_page_increment (largestep);
1865 _slider.set_default_value (normal);
1867 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1868 // dup. currently timers are used :(
1869 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1871 // yuck, do we really need to do this?
1872 // according to c404374 this is only needed for send automation
1873 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1878 /* We're providing our own PersistentTooltip */
1879 set_no_tooltip_whatsoever (_slider);
1882 PluginPinDialog::Control::~Control ()
1884 timer_connection.disconnect ();
1888 PluginPinDialog::Control::set_tooltip ()
1890 boost::shared_ptr<AutomationControl> c = _control.lock ();
1895 snprintf (tmp, sizeof (tmp), "%s: %.2f", _name.c_str (), c->internal_to_user (c->get_value ()));
1897 string sm = Gtkmm2ext::markup_escape_text (tmp);
1898 _slider_persistant_tooltip.set_tip (sm);
1902 PluginPinDialog::Control::slider_adjusted ()
1904 if (_ignore_ui_adjustment) {
1907 boost::shared_ptr<AutomationControl> c = _control.lock ();
1911 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1917 PluginPinDialog::Control::control_changed ()
1919 boost::shared_ptr<AutomationControl> c = _control.lock ();
1924 _ignore_ui_adjustment = true;
1926 // as long as rapid timers are used, only update the tooltip
1927 // if the value has changed.
1928 const double nval = c->internal_to_interface (c->get_value ());
1929 if (_adjustment.get_value () != nval) {
1930 _adjustment.set_value (nval);
1934 _ignore_ui_adjustment = false;