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/label.h>
26 #include "pbd/replace_all.h"
28 #include "gtkmm2ext/utils.h"
29 #include "gtkmm2ext/rgb_macros.h"
31 #include "ardour/amp.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/pannable.h"
34 #include "ardour/plugin.h"
35 #include "ardour/port.h"
36 #include "ardour/profile.h"
37 #include "ardour/send.h"
38 #include "ardour/session.h"
39 #include "ardour/value_as_string.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 PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
56 : _set_config (_("Manual Config"), ArdourButton::led_default_elements)
57 , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements)
58 , _add_plugin (_("+"))
59 , _del_plugin (_("-"))
60 , _add_input_audio (_("+"))
61 , _del_input_audio (_("-"))
62 , _add_input_midi (_("+"))
63 , _del_input_midi (_("-"))
64 , _add_output_audio (_("+"))
65 , _del_output_audio (_("-"))
66 , _add_output_midi (_("+"))
67 , _del_output_midi (_("-"))
68 , _add_sc_audio (_("Audio"))
69 , _add_sc_midi (_("MIDI"))
81 , _position_valid (false)
82 , _ignore_updates (false)
83 , _sidechain_selector (0)
86 assert (pi->owner ()); // Route
88 _pi->PluginIoReConfigure.connect (
89 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
92 _pi->PluginMapChanged.connect (
93 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
96 _pi->PluginConfigChanged.connect (
97 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
100 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
101 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
102 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
104 _tgl_sidechain.set_name ("pinrouting sidechain");
105 _set_config.set_name ("pinrouting custom");
107 Menu_Helpers::MenuList& citems = reset_menu.items ();
108 reset_menu.set_name ("ArdourContextMenu");
110 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinWidget::reset_mapping)));
112 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
113 _add_plugin.set_tweaks (ArdourButton::Square);
114 _del_plugin.set_tweaks (ArdourButton::Square);
115 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
116 _pm_size_group->add_widget (_add_input_audio);
117 _pm_size_group->add_widget (_del_input_audio);
118 _pm_size_group->add_widget (_add_input_midi);
119 _pm_size_group->add_widget (_del_input_midi);
121 _pm_size_group->add_widget (_add_plugin);
122 _pm_size_group->add_widget (_del_plugin);
124 _pm_size_group->add_widget (_add_output_audio);
125 _pm_size_group->add_widget (_del_output_audio);
126 _pm_size_group->add_widget (_add_output_midi);
127 _pm_size_group->add_widget (_del_output_midi);
132 VBox* tl = manage (new VBox ());
133 tl->set_border_width (2);
136 VBox* tr = manage (new VBox ());
137 tr->set_border_width (2);
141 tl->pack_start (_set_config, false, false);
143 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
144 box = manage (new HBox ());
145 box->set_border_width (2);
146 box->pack_start (_add_input_audio, true, false);
147 box->pack_start (_del_input_audio, true, false);
148 f = manage (new Frame ());
149 f->set_label (_("Audio Input Pins"));
151 tl->pack_start (*f, false, false);
153 box = manage (new HBox ());
154 box->set_border_width (2);
155 box->pack_start (_add_input_midi, true, false);
156 box->pack_start (_del_input_midi, true, false);
157 f = manage (new Frame ());
158 f->set_label (_("MIDI Input Pins"));
160 tl->pack_start (*f, false, false);
162 box = manage (new HBox ());
163 box->set_border_width (2);
164 box->pack_start (_add_plugin, true, false);
165 box->pack_start (_del_plugin, true, false);
166 f = manage (new Frame ());
167 f->set_label (_("Instances"));
169 tl->pack_start (*f, false, false);
172 box = manage (new HBox ());
173 box->set_border_width (2);
174 box->pack_start (_add_output_audio, true, false);
175 box->pack_start (_del_output_audio, true, false);
176 f = manage (new Frame ());
177 f->set_label (_("Audio Out"));
179 tl->pack_start (*f, false, false);
181 box = manage (new HBox ());
182 box->set_border_width (2);
183 box->pack_start (_add_output_midi, true, false);
184 box->pack_start (_del_output_midi, true, false);
185 f = manage (new Frame ());
186 f->set_label (_("MIDI Out"));
188 tl->pack_start (*f, false, false);
190 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
191 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
192 _out_presets.disable_scrolling ();
193 ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
194 tl->pack_start (_out_presets, false, false);
197 _sidechain_tbl = manage (new Gtk::Table ());
198 _sidechain_tbl->set_spacings (2);
200 tr->pack_start (_tgl_sidechain, false, false);
201 tr->pack_start (*_sidechain_tbl, true, true);
203 box = manage (new VBox ());
204 box->set_border_width (2);
205 box->set_spacing (2);
206 box->pack_start (_add_sc_audio, false, false);
207 box->pack_start (_add_sc_midi , false, false);
208 f = manage (new Frame ());
209 f->set_label (_("Add Sidechain Input"));
212 tr->pack_start (*f, false, false);
215 HBox* hbox = manage (new HBox ());
216 hbox->set_spacing (4);
217 hbox->pack_start (*tl, false, false);
218 hbox->pack_start (darea, true, true);
219 hbox->pack_start (*tr, false, false);
221 pack_start (*hbox, true, true);
222 set_border_width (4);
225 plugin_reconfigured ();
227 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
228 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_request));
229 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_allocate));
230 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_expose_event));
231 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_press_event));
232 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_release_event));
233 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_motion_notify_event));
235 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::toggle_sidechain));
237 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::reset_configuration));
238 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), true));
239 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), false));
241 _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::AUDIO));
242 _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::AUDIO));
243 _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::MIDI));
244 _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::MIDI));
246 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::AUDIO));
247 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::AUDIO));
248 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::MIDI));
249 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::MIDI));
251 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::AUDIO));
252 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::MIDI));
254 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
255 _io_connection, invalidator (*this), boost::bind (&PluginPinWidget::port_connected_or_disconnected, this, _1, _3), gui_context ()
259 PluginPinWidget::~PluginPinWidget ()
261 delete _sidechain_selector;
265 PluginPinWidget::set_session (ARDOUR::Session *s)
267 SessionHandlePtr::set_session (s);
268 plugin_reconfigured ();
272 PluginPinWidget::queue_idle_update ()
274 /* various actions here are directly executed, in the GUI thread,
275 * with the GUI-thread eventually taking the process and processor lock.
276 * "connect gui_context()" will call back immediately and this
277 * signal-handler will run with the locks held.
279 * This will lead to a crash with calling nth_send() which takes
280 * a processor read-lock while holding a write lock in the same thread.
282 * decouple update to GUI idle.
284 * BUT, do delete existing controls here (in case they're affected by
285 * the change and hit by the Timer before idle comes around)
287 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
288 _sidechain_tbl->remove ((*i)->box);
292 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinWidget::idle_update));
296 PluginPinWidget::idle_update ()
298 plugin_reconfigured ();
304 PluginPinWidget::plugin_reconfigured ()
306 ENSURE_GUI_THREAD (*this, &PluginPinWidget::plugin_reconfigured);
307 if (_ignore_updates) {
310 _n_plugins = _pi->get_count ();
311 _pi->configured_io (_in, _out);
312 _ins = _pi->internal_streams (); // with sidechain
313 _sinks = _pi->natural_input_streams ();
314 _sources = _pi->natural_output_streams ();
317 _tgl_sidechain.set_active (_pi->has_sidechain ());
318 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
319 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
321 if (_pi->custom_cfg ()) {
322 _set_config.set_active (true);
323 _add_plugin.set_sensitive (true);
324 _del_plugin.set_sensitive (_n_plugins > 1);
325 _add_output_audio.set_sensitive (true);
326 _add_output_midi.set_sensitive (true);
327 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
328 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
329 _add_input_audio.set_sensitive (true);
330 _add_input_midi.set_sensitive (true);
331 _del_input_audio.set_sensitive (_sinks.n_audio () > 0 && _sinks.n_total () > 1);
332 _del_input_midi.set_sensitive (_sinks.n_midi () > 0 && _sinks.n_total () > 1);
333 _out_presets.set_sensitive (false);
334 _out_presets.set_text (_("Manual"));
336 _set_config.set_active (false);
337 _add_plugin.set_sensitive (false);
338 _del_plugin.set_sensitive (false);
339 _add_input_audio.set_sensitive (false);
340 _add_input_midi.set_sensitive (false);
341 _del_input_audio.set_sensitive (false);
342 _del_input_midi.set_sensitive (false);
343 _add_output_audio.set_sensitive (false);
344 _add_output_midi.set_sensitive (false);
345 _del_output_audio.set_sensitive (false);
346 _del_output_midi.set_sensitive (false);
347 _out_presets.set_sensitive (true);
348 refill_output_presets ();
351 if (!_pi->has_sidechain () && _sidechain_selector) {
352 delete _sidechain_selector;
353 _sidechain_selector = 0;
356 refill_sidechain_table ();
358 /* update elements */
367 _n_inputs = _n_sidechains = 0;
369 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
370 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
371 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
372 bool sidechain = id >= _in.get (dt) ? true : false;
379 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
380 _elements.push_back (cw);
383 for (uint32_t i = 0; i < _out.n_total (); ++i) {
384 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
385 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
391 for (uint32_t n = 0; n < _n_plugins; ++n) {
392 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
393 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
394 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
395 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
396 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
397 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
398 _elements.push_back (cw);
400 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
401 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
402 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
403 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
404 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
406 _in_map[n] = _pi->input_map (n);
407 _out_map[n] = _pi->output_map (n);
409 _has_midi_bypass = _pi->has_midi_bypass ();
410 _thru_map = _pi->thru_map ();
414 /* calc minimum size */
415 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
416 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
417 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
418 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
419 min_width = std::max ((uint32_t)300, min_width);
421 min_width = 50 + 10 * ceilf (min_width / 10.f);
423 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
424 min_height = std::max ((uint32_t)200, min_height);
425 min_height = 4 * ceilf (min_height / 4.f);
427 if (min_width != _min_width || min_height != _min_height) {
428 _min_width = min_width;
429 _min_height = min_height;
430 darea.queue_resize ();
433 _position_valid = false;
438 PluginPinWidget::refill_sidechain_table ()
440 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
441 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
444 _sidechain_tbl->resize (1, 1);
445 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
449 if (!_pi->has_sidechain () && _sidechain_selector) {
452 boost::shared_ptr<IO> io = _pi->sidechain_input ();
458 PortSet& p (io->ports ());
459 bool can_remove = p.num_ports () > 1;
460 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
461 r += add_port_to_table (*i, r, can_remove);
463 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
464 r += add_port_to_table (*i, r, can_remove);
466 _sidechain_tbl->show_all ();
470 PluginPinWidget::refill_output_presets ()
472 using namespace Menu_Helpers;
473 _out_presets.clear_items ();
475 bool need_dropdown = _pi->has_output_presets ();
477 if (!need_dropdown) {
478 _out_presets.set_sensitive (false);
479 _out_presets.set_text (_("Automatic"));
483 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), 0)));
485 const uint32_t n_audio = _pi->preset_out ().n_audio ();
487 _out_presets.set_text (_("Automatic"));
490 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
491 if (ppc.find (0) != ppc.end ()) {
495 ppc.insert (n_audio);
505 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
516 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
519 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), *i)));
521 _out_presets.set_text (tmp);
527 PluginPinWidget::port_label (const std::string& portname, bool strip)
529 // compare to MixerStrip::update_io_button()
530 string lpn (PROGRAM_NAME);
531 boost::to_lower (lpn);
532 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
534 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
536 string::size_type slash = pn.find ("/");
537 if (slash != string::npos) {
538 pn = pn.substr (0, slash);
542 std::string label (portname);
543 if (label.find ("system:capture_") == 0) {
544 if (label.empty ()) {
545 label = portname.substr (15);
547 } else if (label.find ("system:midi_capture_") == 0) {
548 if (label.empty ()) {
549 // "system:midi_capture_123" -> "123"
550 label = "M " + portname.substr (20);
552 } else if (label.find (program_port_prefix) == 0) {
553 label = label.substr (program_port_prefix.size ());
555 string::size_type slash = label.find ("/");
556 if (slash != string::npos) {
557 label = label.substr (0, slash);
565 PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
568 std::string tip = p->name ();
569 std::vector<std::string> cns;
570 bool single_source = true;
571 p->get_connections (cns);
573 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
575 lbl = port_label (*i, true);
578 if (port_label (*i, true) != lbl) {
580 single_source = false;
585 if (cns.size () == 0) {
587 single_source = false;
588 } else if (cns.size () == 1) {
590 lbl = port_label (cns[0], false);
594 replace_all (lbl, "_", " ");
596 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
601 ArdourButton *pb = manage (new ArdourButton (lbl));
602 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
603 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
604 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
605 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
607 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr<Port> (p)), false);
608 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::sc_input_release), false);
610 pb = manage (new ArdourButton ("-"));
611 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
613 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::remove_port), boost::weak_ptr<Port> (p)));
615 pb->set_sensitive (false);
620 if (single_source && _session) {
621 /* check if it's an Ardour Send feeding.. */
622 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
623 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
625 boost::shared_ptr<Processor> proc;
626 /* nth_send () takes a processor read-lock */
627 while ((proc = (*i)->nth_send (nth))) {
628 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
629 if (!send || !send->output ()) {
633 if (!send->output ()->connected_to (p->name ())) {
637 /* if processor goes away, we're notified by the port disconnect,
638 * there should be no need to explicily connect to proc->DropReferences
640 set<Evoral::Parameter> p = proc->what_can_be_automated ();
641 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
642 Control* c = new Control (proc->automation_control (*i), _("Send"));
643 _controls.push_back (c);
645 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
655 PluginPinWidget::update_element_pos ()
658 _innerwidth = _width - 2. * _margin_x;
660 const double yc = rint (_height * .5);
661 const double bxh2 = rint (_margin_y * .45); // TODO grow?
662 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
663 const double bxw2 = rint (bxw * .5);
664 const double y_in = _margin_y;
665 const double y_out = _height - _margin_y;
670 const double dx = _pin_box_size * .5;
673 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
677 i->x = _innerwidth + _margin_x - dx;
678 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
679 i->h = _pin_box_size;
680 i->w = 1.5 * _pin_box_size;
683 uint32_t idx = i->e->id;
684 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
685 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
686 i->w = _pin_box_size;
687 i->h = 1.5 * _pin_box_size;
693 uint32_t idx = i->e->id;
694 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
695 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
697 i->w = _pin_box_size;
698 i->h = 1.5 * _pin_box_size;
703 uint32_t idx = i->e->id;
704 if (i->e->dt == DataType::AUDIO) { idx += _sinks.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. + _sinks.n_total ())) - .5 - dx;
707 i->y = yc - bxh2 - dx;
708 i->w = _pin_box_size;
709 i->h = _pin_box_size;
714 uint32_t idx = i->e->id;
715 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
716 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
717 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
718 i->y = yc + bxh2 - dx;
719 i->w = _pin_box_size;
720 i->h = _pin_box_size;
728 PluginPinWidget::set_color (cairo_t* cr, bool midi)
730 // see also gtk2_ardour/processor_box.cc
731 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
732 static const uint32_t midi_port_color = 0x960909FF; //Red
735 cairo_set_source_rgb (cr,
736 UINT_RGBA_R_FLT (midi_port_color),
737 UINT_RGBA_G_FLT (midi_port_color),
738 UINT_RGBA_B_FLT (midi_port_color));
740 cairo_set_source_rgb (cr,
741 UINT_RGBA_R_FLT (audio_port_color),
742 UINT_RGBA_G_FLT (audio_port_color),
743 UINT_RGBA_B_FLT (audio_port_color));
748 PluginPinWidget::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
751 const double dy = w.h * .5;
752 const double dx = w.w - dy;
753 cairo_move_to (cr, w.x, w.y + dy);
754 cairo_rel_line_to (cr, dy, -dy);
755 cairo_rel_line_to (cr, dx, 0);
756 cairo_rel_line_to (cr, 0, w.h);
757 cairo_rel_line_to (cr, -dx, 0);
759 const double dir = (w.e->ct == Input) ? 1 : -1;
760 const double dx = w.w * .5;
761 const double dy = w.h - dx;
763 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
764 cairo_rel_line_to (cr, -dx, -dx * dir);
765 cairo_rel_line_to (cr, 0., -dy * dir);
766 cairo_rel_line_to (cr, 2. * dx, 0.);
767 cairo_rel_line_to (cr, 0., dy * dir);
769 cairo_close_path (cr);
771 cairo_set_line_width (cr, 1.0);
772 cairo_set_source_rgb (cr, 0, 0, 0);
773 cairo_stroke_preserve (cr);
775 set_color (cr, w.e->dt == DataType::MIDI);
778 assert (w.e->ct == Input);
779 cairo_fill_preserve (cr);
780 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
783 if (w.e == _selection || w.e == _actor) {
784 cairo_fill_preserve (cr);
785 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
786 } else if (w.prelight) {
787 cairo_fill_preserve (cr);
788 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
794 PluginPinWidget::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
796 const double dx = w.w * .5;
797 const double dy = w.h * .5;
799 cairo_move_to (cr, w.x + dx, w.y);
800 cairo_rel_line_to (cr, -dx, dy);
801 cairo_rel_line_to (cr, dx, dy);
802 cairo_rel_line_to (cr, dx, -dy);
803 cairo_close_path (cr);
805 cairo_set_line_width (cr, 1.0);
806 cairo_set_source_rgb (cr, 0, 0, 0);
807 cairo_stroke_preserve (cr);
809 set_color (cr, w.e->dt == DataType::MIDI);
812 assert (w.e->ct == Sink);
813 cairo_fill_preserve (cr);
814 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
817 if (w.e == _selection || w.e == _actor) {
818 cairo_fill_preserve (cr);
819 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
820 } else if (w.prelight) {
821 cairo_fill_preserve (cr);
822 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
826 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
829 Glib::RefPtr<Pango::Layout> layout;
830 layout = Pango::Layout::create (get_pango_context ());
831 layout->set_text (w.name);
832 layout->get_pixel_size (text_width, text_height);
834 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
835 cairo_set_source_rgba (cr, 0, 0, 0, .5);
838 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
839 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
840 pango_cairo_show_layout (cr, layout->gobj ());
845 PluginPinWidget::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
847 if (!midi) { i += n_midi; }
848 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
851 const PluginPinWidget::CtrlWidget&
852 PluginPinWidget::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
854 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
855 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
860 fatal << string_compose (_("programming error: %1"),
861 X_("Invalid Plugin I/O Port."))
863 abort (); /*NOTREACHED*/
864 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
865 return screw_old_compilers;
869 PluginPinWidget::edge_coordinates (const CtrlWidget& w, double &x, double &y)
897 PluginPinWidget::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
899 const double bz = 2 * _pin_box_size;
900 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
901 if (x0 > _width * .5) { bc *= -1; }
903 cairo_move_to (cr, x0, y0);
905 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
907 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
909 cairo_set_line_width (cr, 3.0);
910 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
911 cairo_set_source_rgb (cr, 1, 0, 0);
913 const double dashes[] = { 5, 7 };
914 cairo_set_dash (cr, dashes, 2, 0);
916 set_color (cr, midi);
919 cairo_set_dash (cr, 0, 0, 0);
924 PluginPinWidget::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
926 double x0, x1, y0, y1;
927 edge_coordinates (w0, x0, y0);
928 edge_coordinates (w1, x1, y1);
929 assert (w0.e->dt == w1.e->dt);
930 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
935 PluginPinWidget::darea_expose_event (GdkEventExpose* ev)
937 Gtk::Allocation a = darea.get_allocation ();
938 double const width = a.get_width ();
939 double const height = a.get_height ();
941 if (!_position_valid) {
944 update_element_pos ();
945 _position_valid = true;
948 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
949 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
952 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
953 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
954 cairo_rectangle (cr, 0, 0, width, height);
957 const double yc = rint (_height * .5);
960 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
961 cairo_set_line_width (cr, 1.0);
962 cairo_set_source_rgb (cr, .1, .1, .3);
963 cairo_stroke_preserve (cr);
964 cairo_set_source_rgb (cr, .3, .3, .3);
968 Glib::RefPtr<Pango::Layout> layout;
969 layout = Pango::Layout::create (get_pango_context ());
971 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
972 layout->set_width (_height * PANGO_SCALE);
977 layout->set_text (_route ()->name ());
978 layout->get_pixel_size (text_width, text_height);
980 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
981 cairo_rotate (cr, M_PI * -.5);
982 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
983 pango_cairo_show_layout (cr, layout->gobj ());
987 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
988 layout->set_text (_pi->name ());
989 layout->get_pixel_size (text_width, text_height);
990 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
991 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
992 pango_cairo_show_layout (cr, layout->gobj ());
995 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
996 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
997 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
998 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
999 } else if (_pi->signal_latency () > 0) {
1000 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
1002 layout->set_text (_("no-inplace"));
1004 layout->get_pixel_size (text_width, text_height);
1005 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
1006 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1007 pango_cairo_show_layout (cr, layout->gobj ());
1011 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1012 layout->set_text (_("Strict I/O"));
1013 layout->get_pixel_size (text_width, text_height);
1014 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1015 const double sy0 = _height - 3 - text_height;
1017 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1018 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1021 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1022 cairo_move_to (cr, sx0, sy0);
1023 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1024 pango_cairo_show_layout (cr, layout->gobj ());
1027 /* draw midi-bypass (behind) */
1028 if (_has_midi_bypass) {
1029 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1030 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1031 draw_connection (cr, cw0, cw1, true);
1034 /* thru connections */
1035 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1036 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1037 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1038 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1039 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1040 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1041 draw_connection (cr, cw1, cw0, true);
1046 /* plugins & connection wires */
1047 for (uint32_t i = 0; i < _n_plugins; ++i) {
1048 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1051 cairo_set_source_rgb (cr, .5, .5, .5);
1052 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1055 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1056 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1057 layout->get_pixel_size (text_width, text_height);
1058 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1059 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1060 pango_cairo_show_layout (cr, layout->gobj ());
1062 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1063 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1065 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1066 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1067 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1068 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1069 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1070 draw_connection (cr, cw0, cw1);
1075 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1076 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1077 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1078 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1079 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1080 draw_connection (cr, cw0, cw1);
1086 /* pins and ports */
1087 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1091 draw_io_pin (cr, *i);
1095 draw_plugin_pin (cr, *i);
1101 CtrlWidget *drag_src = NULL;
1103 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1104 if (i->e == _selection ) {
1112 if (_selection->ct == Input || _selection->ct == Source) {
1113 edge_coordinates (*drag_src, x0, y0);
1114 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1115 _selection->dt == DataType::MIDI, _selection->sc);
1117 edge_coordinates (*drag_src, x0, y0);
1118 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1119 _selection->dt == DataType::MIDI, _selection->sc);
1128 PluginPinWidget::darea_size_request (Gtk::Requisition* req)
1130 req->width = _min_width;
1131 req->height = _min_height;
1135 PluginPinWidget::darea_size_allocate (Gtk::Allocation&)
1137 _position_valid = false;
1141 PluginPinWidget::drag_type_matches (const CtrlElem& e)
1143 if (!_dragging || !_selection) {
1146 if (_selection->dt != e->dt) {
1149 if (_selection->ct == Input && e->ct == Sink) { return true; }
1150 if (_selection->ct == Sink && e->ct == Input) { return true; }
1151 if (_selection->ct == Output && e->ct == Source) { return true; }
1152 if (_selection->ct == Source && e->ct == Output) { return true; }
1153 if (_selection->ct == Input && e->ct == Output) { return true; }
1154 if (_selection->ct == Output && e->ct == Input) { return true; }
1159 PluginPinWidget::start_drag (const CtrlElem& e, double x, double y)
1161 assert (_selection == e);
1163 if (e->ct == Sink) {
1165 const ChanMapping& map (_in_map[e->ip]);
1166 uint32_t idx = map.get (e->dt, e->id, &valid);
1168 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1173 else if (e->ct == Output) {
1174 for (uint32_t i = 0; i < _n_plugins; ++i) {
1176 const ChanMapping& map (_out_map[i]);
1177 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1179 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1187 const ChanMapping& map (_thru_map);
1188 uint32_t idx = map.get (e->dt, e->id, &valid);
1190 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1202 PluginPinWidget::darea_motion_notify_event (GdkEventMotion* ev)
1204 bool changed = false;
1206 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1207 if (ev->x >= i->x && ev->x <= i->x + i->w
1208 && ev->y >= i->y && ev->y <= i->y + i->h
1209 && drag_type_matches (i->e))
1211 if (!i->prelight) changed = true;
1215 if (i->prelight) changed = true;
1216 i->prelight = false;
1223 if (changed || _dragging) {
1224 darea.queue_draw ();
1230 PluginPinWidget::darea_button_press_event (GdkEventButton* ev)
1232 if (ev->type != GDK_BUTTON_PRESS) {
1236 switch (ev->button) {
1239 if (!_selection || (_selection && !_hover)) {
1240 _selection = _hover;
1243 start_drag (_selection, ev->x, ev->y);
1245 darea.queue_draw ();
1247 } else if (_selection && _hover && _selection != _hover) {
1248 if (_selection->dt != _hover->dt) { _actor.reset (); }
1249 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1250 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1251 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1252 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1253 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1254 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1256 _selection = _hover;
1257 start_drag (_selection, ev->x, ev->y);
1259 darea.queue_draw ();
1261 } else if (_hover) {
1262 _selection = _hover;
1264 start_drag (_selection, ev->x, ev->y);
1269 if (_selection != _hover) {
1270 _selection = _hover;
1271 darea.queue_draw ();
1283 PluginPinWidget::darea_button_release_event (GdkEventButton* ev)
1285 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1286 // select click. (or re-connect same)
1287 assert (_selection != _hover);
1292 darea.queue_draw ();
1296 if (_dragging && _hover && _hover != _selection) {
1300 if (_hover == _actor && _actor && ev->button == 1) {
1301 assert (_selection);
1302 assert (_selection->dt == _actor->dt);
1304 assert (_dragging && _selection != _drag_dst);
1305 handle_disconnect (_drag_dst, true);
1307 if (_selection->ct == Input && _actor->ct == Sink) {
1308 handle_input_action (_actor, _selection);
1310 else if (_selection->ct == Sink && _actor->ct == Input) {
1311 handle_input_action (_selection, _actor);
1313 else if (_selection->ct == Output && _actor->ct == Source) {
1314 handle_output_action (_actor, _selection);
1316 else if (_selection->ct == Source && _actor->ct == Output) {
1317 handle_output_action (_selection, _actor);
1319 else if (_selection->ct == Input && _actor->ct == Output) {
1320 handle_thru_action (_actor, _selection);
1322 else if (_selection->ct == Output && _actor->ct == Input) {
1323 handle_thru_action (_selection, _actor);
1325 _selection.reset ();
1326 } else if (_hover == _selection && _selection && ev->button == 3) {
1327 handle_disconnect (_selection);
1328 } else if (!_hover && ev->button == 3) {
1329 reset_menu.popup (1, ev->time);
1332 if (_dragging && _hover != _selection) {
1333 _selection.reset ();
1338 darea.queue_draw ();
1343 PluginPinWidget::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1345 const int pc = s->ip;
1347 ChanMapping in_map (_pi->input_map (pc));
1348 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1350 if (valid && idx == i->id) {
1353 in_map.unset (s->dt, s->id);
1354 _pi->set_input_map (pc, in_map);
1356 plugin_reconfigured ();
1361 in_map.set (s->dt, s->id, i->id);
1362 _pi->set_input_map (pc, in_map);
1366 in_map.unset (s->dt, s->id);
1367 in_map.set (s->dt, s->id, i->id);
1368 _pi->set_input_map (pc, in_map);
1373 PluginPinWidget::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1375 _ignore_updates = true;
1376 for (uint32_t n = 0; n < _n_plugins; ++n) {
1381 ChanMapping n_out_map (_pi->output_map (n));
1382 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1384 n_out_map.unset (dt, idx);
1385 _pi->set_output_map (n, n_out_map);
1388 _ignore_updates = false;
1392 PluginPinWidget::disconnect_other_thru (DataType dt, uint32_t id)
1394 _ignore_updates = true;
1396 ChanMapping n_thru_map (_pi->thru_map ());
1397 n_thru_map.get (dt, id, &valid);
1399 n_thru_map.unset (dt, id);
1400 _pi->set_thru_map (n_thru_map);
1402 _ignore_updates = false;
1406 PluginPinWidget::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1408 const uint32_t pc = s->ip;
1410 ChanMapping out_map (_pi->output_map (pc));
1411 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1413 if (valid && idx == o->id) {
1416 out_map.unset (s->dt, s->id);
1417 _pi->set_output_map (pc, out_map);
1419 plugin_reconfigured ();
1423 // disconnect source
1424 disconnect_other_outputs (pc, s->dt, o->id);
1425 disconnect_other_thru (s->dt, o->id);
1426 out_map = _pi->output_map (pc); // re-read map
1428 out_map.unset (s->dt, s->id);
1430 idx = out_map.get_src (s->dt, o->id, &valid);
1432 out_map.unset (s->dt, idx);
1435 out_map.set (s->dt, s->id, o->id);
1436 _pi->set_output_map (pc, out_map);
1441 PluginPinWidget::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1444 ChanMapping thru_map (_pi->thru_map ());
1445 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1447 if (valid && idx == i->id) {
1449 thru_map.unset (o->dt, o->id);
1452 // disconnect other outputs first
1453 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1454 disconnect_other_thru (o->dt, o->id);
1455 thru_map = _pi->thru_map (); // re-read map
1457 thru_map.set (o->dt, o->id, i->id);
1459 _pi->set_thru_map (thru_map);
1463 PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal)
1465 _ignore_updates = true;
1466 bool changed = false;
1472 ChanMapping n_thru_map (_pi->thru_map ());
1473 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1474 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1475 if (valid && idx == e->id) {
1476 n_thru_map.unset (e->dt, i);
1481 _pi->set_thru_map (n_thru_map);
1484 for (uint32_t n = 0; n < _n_plugins; ++n) {
1485 ChanMapping map (_pi->input_map (n));
1486 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1487 uint32_t idx = map.get (e->dt, i, &valid);
1488 if (valid && idx == e->id) {
1489 map.unset (e->dt, i);
1493 _pi->set_input_map (n, map);
1498 ChanMapping map (_pi->input_map (e->ip));
1499 map.get (e->dt, e->id, &valid);
1501 map.unset (e->dt, e->id);
1502 _pi->set_input_map (e->ip, map);
1509 ChanMapping map (_pi->output_map (e->ip));
1510 map.get (e->dt, e->id, &valid);
1512 map.unset (e->dt, e->id);
1513 _pi->set_output_map (e->ip, map);
1519 for (uint32_t n = 0; n < _n_plugins; ++n) {
1520 ChanMapping map (_pi->output_map (n));
1521 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1522 uint32_t idx = map.get (e->dt, i, &valid);
1523 if (valid && idx == e->id) {
1524 map.unset (e->dt, i);
1529 _pi->set_output_map (n, map);
1533 ChanMapping n_thru_map (_pi->thru_map ());
1534 n_thru_map.get (e->dt, e->id, &valid);
1536 n_thru_map.unset (e->dt, e->id);
1538 _pi->set_thru_map (n_thru_map);
1543 _ignore_updates = false;
1544 if (changed && !no_signal) {
1545 plugin_reconfigured ();
1551 PluginPinWidget::toggle_sidechain ()
1553 if (_session && _session->actively_recording ()) { return; }
1554 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1558 PluginPinWidget::connect_sidechain ()
1560 if (!_session) { return; }
1562 if (_sidechain_selector == 0) {
1563 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1566 if (_sidechain_selector->is_visible ()) {
1567 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1569 _sidechain_selector->present ();
1574 PluginPinWidget::reset_configuration ()
1576 if (_set_config.get_active ()) {
1577 _route ()->reset_plugin_insert (_pi);
1579 _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
1584 PluginPinWidget::reset_mapping ()
1590 PluginPinWidget::select_output_preset (uint32_t n_audio)
1592 if (_session && _session->actively_recording ()) { return; }
1593 ChanCount out (DataType::AUDIO, n_audio);
1594 _route ()->plugin_preset_output (_pi, out);
1598 PluginPinWidget::add_remove_plugin_clicked (bool add)
1600 if (_session && _session->actively_recording ()) { return; }
1601 ChanCount out = _out;
1602 ChanCount sinks = _sinks;
1603 assert (add || _n_plugins > 0);
1604 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks);
1608 PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1610 if (_session && _session->actively_recording ()) { return; }
1611 ChanCount out = _out;
1612 ChanCount sinks = _sinks;
1613 assert (add || out.get (dt) > 0);
1614 out.set (dt, out.get (dt) + (add ? 1 : -1));
1615 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1619 PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
1621 if (_session && _session->actively_recording ()) { return; }
1622 ChanCount out = _out;
1623 ChanCount sinks = _sinks;
1624 assert (add || sinks.get (dt) > 0);
1625 sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
1626 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1630 PluginPinWidget::add_sidechain_port (DataType dt)
1632 if (_session && _session->actively_recording ()) { return; }
1633 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1638 // this triggers a PluginIoReConfigure with process and processor write lock held
1639 // from /this/ thread.
1640 io->add_port ("", this, dt);
1644 PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1646 if (_session && _session->actively_recording ()) { return; }
1647 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1648 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1652 io->remove_port (p, this);
1656 PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1658 if (_session && _session->actively_recording ()) { return; }
1659 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1660 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1664 p->disconnect_all ();
1668 PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1670 if (_session && _session->actively_recording ()) { return; }
1671 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1672 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1673 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1674 if (!io || !p0 || !p1) {
1677 _ignore_updates = true;
1678 p0->disconnect_all ();
1679 _ignore_updates = false;
1680 p0->connect (p1->name ());
1684 PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1686 if (_session && _session->actively_recording ()) { return; }
1687 boost::shared_ptr<Port> p = wp.lock ();
1688 boost::shared_ptr<Route> r = wr.lock ();
1689 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1690 if (!p || !r || !io || !_session) {
1694 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1695 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1696 const ChanCount& outs (r->amp ()->input_streams ());
1698 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1699 send->output()->ensure_io (outs, false, this);
1700 } catch (AudioEngine::PortRegistrationFailure& err) {
1701 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1705 std::string sendname = send->name ();
1706 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1707 if (last_letter != string::npos) {
1708 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1710 sendname.substr (last_letter + 1)));
1713 _ignore_updates = true;
1714 p->disconnect_all ();
1716 DataType dt = p->type ();
1717 PortSet& ps (send->output ()->ports ());
1718 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1719 p->connect (&(**i));
1722 send->set_remove_on_disconnect (true);
1723 r->add_processor (send, PreFader);
1724 _ignore_updates = false;
1725 queue_idle_update ();
1729 PluginPinWidget::sc_input_release (GdkEventButton *ev)
1731 if (_session && _session->actively_recording ()) { return false; }
1732 if (ev->button == 3) {
1733 connect_sidechain ();
1738 struct RouteCompareByName {
1739 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1740 return a->name ().compare (b->name ()) < 0;
1745 PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1747 using namespace Menu_Helpers;
1748 if (!_session || _session->actively_recording ()) { return false; }
1749 if (!_session->engine ().connected ()) { return false; }
1751 if (ev->button == 1) {
1752 MenuList& citems = input_menu.items ();
1753 input_menu.set_name ("ArdourContextMenu");
1756 boost::shared_ptr<Port> p = wp.lock ();
1757 if (p && p->connected ()) {
1758 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::disconnect_port), wp)));
1759 citems.push_back (SeparatorElem ());
1763 // TODO add system inputs, too ?!
1764 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1765 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1766 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1768 //maybe_add_bundle_to_input_menu (*i, current);
1772 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1773 RouteList copy = *routes;
1774 copy.sort (RouteCompareByName ());
1776 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1777 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1781 citems.push_back (SeparatorElem ());
1783 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinWidget::connect_sidechain)));
1784 input_menu.popup (1, ev->time);
1790 PluginPinWidget::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1793 using namespace Menu_Helpers;
1794 if (r->output () == _route ()->output ()) {
1798 if (_route ()->feeds_according_to_graph (r)) {
1802 MenuList& citems = input_menu.items ();
1804 /*check if there's already a send.. */
1805 bool already_present = false;
1807 boost::shared_ptr<Processor> proc;
1808 /* Note: nth_send () takes a processor read-lock */
1809 while ((proc = r->nth_send (nth))) {
1810 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1811 if (!send || !send->output ()) {
1815 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1816 // only if (send->remove_on_disconnect ()) ??
1817 already_present = true;
1822 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1823 const ChanCount& rc (r->amp ()->input_streams ());
1824 if (!already_present && rc.get (dt) > 0) {
1825 citems.push_back (MenuElem (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr<Route> (r))));
1832 PluginPinWidget::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1834 boost::shared_ptr<Port> p0 = w0.lock ();
1835 boost::shared_ptr<Port> p1 = w1.lock ();
1837 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1838 if (!io) { return; }
1840 if (p0 && io->has_port (p0)) {
1841 queue_idle_update ();
1843 else if (p1 && io->has_port (p1)) {
1844 queue_idle_update ();
1848 /* lifted from ProcessorEntry::Control */
1849 PluginPinWidget::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1851 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1852 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1853 , _slider_persistant_tooltip (&_slider)
1854 , _ignore_ui_adjustment (false)
1857 _slider.set_controllable (c);
1858 box.set_padding (0, 0, 4, 4);
1860 _slider.set_name ("ProcessorControlSlider");
1861 _slider.set_text (_name);
1866 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1867 double const lo = c->internal_to_interface (desc.lower);
1868 double const up = c->internal_to_interface (desc.upper);
1869 double const normal = c->internal_to_interface (desc.normal);
1870 double smallstep = desc.smallstep;
1871 double largestep = desc.largestep;
1873 if (smallstep == 0.0) {
1874 smallstep = up / 1000.;
1876 smallstep = c->internal_to_interface (desc.lower + smallstep);
1879 if (largestep == 0.0) {
1880 largestep = up / 40.;
1882 largestep = c->internal_to_interface (desc.lower + largestep);
1885 _adjustment.set_lower (lo);
1886 _adjustment.set_upper (up);
1887 _adjustment.set_step_increment (smallstep);
1888 _adjustment.set_page_increment (largestep);
1889 _slider.set_default_value (normal);
1891 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1892 // dup. currently timers are used :(
1893 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1895 // yuck, do we really need to do this?
1896 // according to c404374 this is only needed for send automation
1897 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1902 /* We're providing our own PersistentTooltip */
1903 set_no_tooltip_whatsoever (_slider);
1906 PluginPinWidget::Control::~Control ()
1908 timer_connection.disconnect ();
1912 PluginPinWidget::Control::set_tooltip ()
1914 boost::shared_ptr<AutomationControl> c = _control.lock ();
1918 std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ());
1919 string sm = Gtkmm2ext::markup_escape_text (tt);
1920 _slider_persistant_tooltip.set_tip (sm);
1924 PluginPinWidget::Control::slider_adjusted ()
1926 if (_ignore_ui_adjustment) {
1929 boost::shared_ptr<AutomationControl> c = _control.lock ();
1933 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1939 PluginPinWidget::Control::control_changed ()
1941 boost::shared_ptr<AutomationControl> c = _control.lock ();
1946 _ignore_ui_adjustment = true;
1948 // as long as rapid timers are used, only update the tooltip
1949 // if the value has changed.
1950 const double nval = c->internal_to_interface (c->get_value ());
1951 if (_adjustment.get_value () != nval) {
1952 _adjustment.set_value (nval);
1956 _ignore_ui_adjustment = false;
1961 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
1962 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
1964 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
1969 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
1970 : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
1972 , _height_mapped (false)
1974 vbox = manage (new VBox ());
1975 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
1976 scroller = manage (new ScrolledWindow);
1977 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1978 scroller->set_shadow_type (Gtk::SHADOW_NONE);
1981 scroller->add (*vbox);
1985 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
1987 _route->processors_changed.connect (
1988 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context()
1991 _route->DropReferences.connect (
1992 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context()
1996 PluginPinDialog::set_session (ARDOUR::Session *s)
1998 SessionHandlePtr::set_session (s);
1999 for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) {
2000 (*i)->set_session (s);
2005 PluginPinDialog::map_height (Gtk::Allocation&)
2007 if (!_height_mapped) {
2008 scroller->set_size_request (-1, std::min (600, 2 + vbox->get_height()));
2009 _height_mapped = true;
2014 PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
2017 _height_mapped = false;
2018 scroller->remove ();
2019 vbox = manage (new VBox ());
2020 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
2021 scroller->add (*vbox);
2022 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2027 PluginPinDialog::route_going_away ()
2035 PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
2037 boost::shared_ptr<Processor> proc = p.lock ();
2038 if (!proc || !proc->display_to_user ()) {
2041 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
2043 if (pi && pi->is_channelstrip ()) {
2048 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
2049 vbox->pack_start (*ppw.back());
2051 HBox* hbox = manage (new HBox ());
2052 hbox->pack_start (*manage (new HSeparator ()));
2053 hbox->pack_start (*manage (new Label (proc->display_name ())));
2054 hbox->pack_start (*manage (new HSeparator ()));
2055 vbox->pack_start (*hbox, false, false);