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/box.h>
23 #include <gtkmm/frame.h>
24 #include <gtkmm/label.h>
25 #include <gtkmm/separator.h>
26 #include <gtkmm/table.h>
28 #include "pbd/replace_all.h"
30 #include "gtkmm2ext/utils.h"
31 #include "gtkmm2ext/rgb_macros.h"
32 #include "gtkmm2ext/menu_elems.h"
34 #include "widgets/tooltips.h"
36 #include "ardour/amp.h"
37 #include "ardour/audioengine.h"
38 #include "ardour/pannable.h"
39 #include "ardour/plugin.h"
40 #include "ardour/port.h"
41 #include "ardour/profile.h"
42 #include "ardour/send.h"
43 #include "ardour/session.h"
44 #include "ardour/value_as_string.h"
46 #include "plugin_pin_dialog.h"
47 #include "gui_thread.h"
49 #include "ui_config.h"
53 using namespace ARDOUR;
57 using namespace Gtkmm2ext;
58 using namespace ArdourWidgets;
60 PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
61 : _set_config (_("Manual Config"), ArdourButton::led_default_elements)
62 , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements)
63 , _add_plugin (_("+"))
64 , _del_plugin (_("-"))
65 , _add_input_audio (_("+"))
66 , _del_input_audio (_("-"))
67 , _add_input_midi (_("+"))
68 , _del_input_midi (_("-"))
69 , _add_output_audio (_("+"))
70 , _del_output_audio (_("-"))
71 , _add_output_midi (_("+"))
72 , _del_output_midi (_("-"))
73 , _add_sc_audio (_("Audio"))
74 , _add_sc_midi (_("MIDI"))
86 , _position_valid (false)
87 , _ignore_updates (false)
88 , _sidechain_selector (0)
91 assert (pi->owner ()); // Route
93 _pi->PluginIoReConfigure.connect (
94 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
97 _pi->PluginMapChanged.connect (
98 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
101 _pi->PluginConfigChanged.connect (
102 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
105 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
106 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
107 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
109 _tgl_sidechain.set_name ("pinrouting sidechain");
110 _set_config.set_name ("pinrouting custom");
112 Menu_Helpers::MenuList& citems = reset_menu.items ();
113 reset_menu.set_name ("ArdourContextMenu");
115 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinWidget::reset_mapping)));
117 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
118 _add_plugin.set_tweaks (ArdourButton::Square);
119 _del_plugin.set_tweaks (ArdourButton::Square);
120 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
121 _pm_size_group->add_widget (_add_input_audio);
122 _pm_size_group->add_widget (_del_input_audio);
123 _pm_size_group->add_widget (_add_input_midi);
124 _pm_size_group->add_widget (_del_input_midi);
126 _pm_size_group->add_widget (_add_plugin);
127 _pm_size_group->add_widget (_del_plugin);
129 _pm_size_group->add_widget (_add_output_audio);
130 _pm_size_group->add_widget (_del_output_audio);
131 _pm_size_group->add_widget (_add_output_midi);
132 _pm_size_group->add_widget (_del_output_midi);
137 VBox* tl = manage (new VBox ());
138 tl->set_border_width (2);
141 VBox* tr = manage (new VBox ());
142 tr->set_border_width (2);
146 tl->pack_start (_set_config, false, false);
148 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
149 box = manage (new HBox ());
150 box->set_border_width (2);
151 box->pack_start (_add_input_audio, true, false);
152 box->pack_start (_del_input_audio, true, false);
153 f = manage (new Frame ());
154 f->set_label (_("Audio Input Pins"));
156 tl->pack_start (*f, false, false);
158 box = manage (new HBox ());
159 box->set_border_width (2);
160 box->pack_start (_add_input_midi, true, false);
161 box->pack_start (_del_input_midi, true, false);
162 f = manage (new Frame ());
163 f->set_label (_("MIDI Input Pins"));
165 tl->pack_start (*f, false, false);
167 box = manage (new HBox ());
168 box->set_border_width (2);
169 box->pack_start (_add_plugin, true, false);
170 box->pack_start (_del_plugin, true, false);
171 f = manage (new Frame ());
172 f->set_label (_("Instances"));
174 tl->pack_start (*f, false, false);
177 box = manage (new HBox ());
178 box->set_border_width (2);
179 box->pack_start (_add_output_audio, true, false);
180 box->pack_start (_del_output_audio, true, false);
181 f = manage (new Frame ());
182 f->set_label (_("Audio Out"));
184 tl->pack_start (*f, false, false);
186 box = manage (new HBox ());
187 box->set_border_width (2);
188 box->pack_start (_add_output_midi, true, false);
189 box->pack_start (_del_output_midi, true, false);
190 f = manage (new Frame ());
191 f->set_label (_("MIDI Out"));
193 tl->pack_start (*f, false, false);
195 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
196 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
197 _out_presets.disable_scrolling ();
198 ArdourWidgets::set_tooltip (_out_presets, _("Output Presets"));
199 tl->pack_start (_out_presets, false, false);
202 _sidechain_tbl = manage (new Gtk::Table ());
203 _sidechain_tbl->set_spacings (2);
205 tr->pack_start (_tgl_sidechain, false, false);
206 tr->pack_start (*_sidechain_tbl, true, true);
208 box = manage (new VBox ());
209 box->set_border_width (2);
210 box->set_spacing (2);
211 box->pack_start (_add_sc_audio, false, false);
212 box->pack_start (_add_sc_midi , false, false);
213 f = manage (new Frame ());
214 f->set_label (_("Add Sidechain Input"));
217 tr->pack_start (*f, false, false);
220 HBox* hbox = manage (new HBox ());
221 hbox->set_spacing (4);
222 hbox->pack_start (*tl, false, false);
223 hbox->pack_start (darea, true, true);
224 hbox->pack_start (*tr, false, false);
226 pack_start (*hbox, true, true);
227 set_border_width (4);
230 plugin_reconfigured ();
232 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
233 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_request));
234 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_allocate));
235 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_expose_event));
236 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_press_event));
237 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_release_event));
238 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_motion_notify_event));
240 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::toggle_sidechain));
242 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::reset_configuration));
243 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), true));
244 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), false));
246 _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::AUDIO));
247 _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::AUDIO));
248 _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::MIDI));
249 _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::MIDI));
251 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::AUDIO));
252 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::AUDIO));
253 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::MIDI));
254 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::MIDI));
256 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::AUDIO));
257 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::MIDI));
259 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
260 _io_connection, invalidator (*this), boost::bind (&PluginPinWidget::port_connected_or_disconnected, this, _1, _3), gui_context ()
264 PluginPinWidget::~PluginPinWidget ()
266 delete _sidechain_selector;
270 PluginPinWidget::set_session (ARDOUR::Session *s)
272 SessionHandlePtr::set_session (s);
273 plugin_reconfigured ();
277 PluginPinWidget::queue_idle_update ()
279 /* various actions here are directly executed, in the GUI thread,
280 * with the GUI-thread eventually taking the process and processor lock.
281 * "connect gui_context()" will call back immediately and this
282 * signal-handler will run with the locks held.
284 * This will lead to a crash with calling nth_send() which takes
285 * a processor read-lock while holding a write lock in the same thread.
287 * decouple update to GUI idle.
289 * BUT, do delete existing controls here (in case they're affected by
290 * the change and hit by the Timer before idle comes around)
292 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
293 _sidechain_tbl->remove ((*i)->box);
297 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinWidget::idle_update));
301 PluginPinWidget::idle_update ()
303 plugin_reconfigured ();
309 PluginPinWidget::plugin_reconfigured ()
311 ENSURE_GUI_THREAD (*this, &PluginPinWidget::plugin_reconfigured);
312 if (_ignore_updates) {
315 _n_plugins = _pi->get_count ();
316 _pi->configured_io (_in, _out);
317 _ins = _pi->internal_streams (); // with sidechain
318 _sinks = _pi->natural_input_streams ();
319 _sources = _pi->natural_output_streams ();
322 _tgl_sidechain.set_active (_pi->has_sidechain ());
323 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
324 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
326 if (_pi->custom_cfg ()) {
327 _set_config.set_active (true);
328 _add_plugin.set_sensitive (true);
329 _del_plugin.set_sensitive (_n_plugins > 1);
330 _add_output_audio.set_sensitive (true);
331 _add_output_midi.set_sensitive (true);
332 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
333 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
334 _add_input_audio.set_sensitive (true);
335 _add_input_midi.set_sensitive (true);
336 _del_input_audio.set_sensitive (_sinks.n_audio () > 0 && _sinks.n_total () > 1);
337 _del_input_midi.set_sensitive (_sinks.n_midi () > 0 && _sinks.n_total () > 1);
338 _out_presets.set_sensitive (false);
339 _out_presets.set_text (_("Manual"));
341 _set_config.set_active (false);
342 _add_plugin.set_sensitive (false);
343 _del_plugin.set_sensitive (false);
344 _add_input_audio.set_sensitive (false);
345 _add_input_midi.set_sensitive (false);
346 _del_input_audio.set_sensitive (false);
347 _del_input_midi.set_sensitive (false);
348 _add_output_audio.set_sensitive (false);
349 _add_output_midi.set_sensitive (false);
350 _del_output_audio.set_sensitive (false);
351 _del_output_midi.set_sensitive (false);
352 _out_presets.set_sensitive (true);
353 refill_output_presets ();
356 if (!_pi->has_sidechain () && _sidechain_selector) {
357 delete _sidechain_selector;
358 _sidechain_selector = 0;
361 refill_sidechain_table ();
363 /* update elements */
372 _n_inputs = _n_sidechains = 0;
374 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
375 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
376 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
377 bool sidechain = id >= _in.get (dt) ? true : false;
384 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
385 _elements.push_back (cw);
388 for (uint32_t i = 0; i < _out.n_total (); ++i) {
389 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
390 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
396 for (uint32_t n = 0; n < _n_plugins; ++n) {
397 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
398 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
399 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
400 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
401 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
402 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
403 _elements.push_back (cw);
405 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
406 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
407 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
408 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
409 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
411 _in_map[n] = _pi->input_map (n);
412 _out_map[n] = _pi->output_map (n);
414 _has_midi_bypass = _pi->has_midi_bypass ();
415 _thru_map = _pi->thru_map ();
419 /* calc minimum size */
420 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
421 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
422 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
423 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
424 min_width = std::max ((uint32_t)300, min_width);
426 min_width = 50 + 10 * ceilf (min_width / 10.f);
428 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
429 min_height = std::max ((uint32_t)200, min_height);
430 min_height = 4 * ceilf (min_height / 4.f);
432 if (min_width != _min_width || min_height != _min_height) {
433 _min_width = min_width;
434 _min_height = min_height;
435 darea.queue_resize ();
438 _position_valid = false;
443 PluginPinWidget::refill_sidechain_table ()
445 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
446 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
449 _sidechain_tbl->resize (1, 1);
450 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
454 if (!_pi->has_sidechain () && _sidechain_selector) {
457 boost::shared_ptr<IO> io = _pi->sidechain_input ();
463 PortSet& p (io->ports ());
464 bool can_remove = p.num_ports () > 1;
465 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
466 r += add_port_to_table (*i, r, can_remove);
468 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
469 r += add_port_to_table (*i, r, can_remove);
471 _sidechain_tbl->show_all ();
475 PluginPinWidget::refill_output_presets ()
477 using namespace Menu_Helpers;
478 _out_presets.clear_items ();
480 bool need_dropdown = _pi->has_output_presets ();
482 if (!need_dropdown) {
483 _out_presets.set_sensitive (false);
484 _out_presets.set_text (_("Automatic"));
488 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), 0)));
490 const uint32_t n_audio = _pi->preset_out ().n_audio ();
492 _out_presets.set_text (_("Automatic"));
495 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
496 if (ppc.find (0) != ppc.end ()) {
500 ppc.insert (n_audio);
510 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
521 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
524 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), *i)));
526 _out_presets.set_text (tmp);
532 PluginPinWidget::port_label (const std::string& portname, bool strip)
534 // compare to MixerStrip::update_io_button()
535 string lpn (PROGRAM_NAME);
536 boost::to_lower (lpn);
537 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
539 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
541 string::size_type slash = pn.find ("/");
542 if (slash != string::npos) {
543 pn = pn.substr (0, slash);
547 std::string label (portname);
548 if (label.find ("system:capture_") == 0) {
549 if (label.empty ()) {
550 label = portname.substr (15);
552 } else if (label.find ("system:midi_capture_") == 0) {
553 if (label.empty ()) {
554 // "system:midi_capture_123" -> "123"
555 label = "M " + portname.substr (20);
557 } else if (label.find (program_port_prefix) == 0) {
558 label = label.substr (program_port_prefix.size ());
560 string::size_type slash = label.find ("/");
561 if (slash != string::npos) {
562 label = label.substr (0, slash);
570 PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
573 std::string tip = Gtkmm2ext::markup_escape_text (p->name ());
574 std::vector<std::string> cns;
575 bool single_source = true;
576 p->get_connections (cns);
578 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
580 lbl = port_label (*i, true);
583 if (port_label (*i, true) != lbl) {
585 single_source = false;
590 if (cns.size () == 0) {
592 single_source = false;
593 } else if (cns.size () == 1) {
595 lbl = port_label (cns[0], false);
599 replace_all (lbl, "_", " ");
601 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
606 ArdourButton *pb = manage (new ArdourButton (lbl));
607 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
608 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
609 ArdourWidgets::set_tooltip (*pb, tip);
610 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
612 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr<Port> (p)), false);
613 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::sc_input_release), false);
615 pb = manage (new ArdourButton ("-"));
616 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
618 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::remove_port), boost::weak_ptr<Port> (p)));
620 pb->set_sensitive (false);
625 if (single_source && _session) {
626 /* check if it's an Ardour Send feeding.. */
627 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
628 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
630 boost::shared_ptr<Processor> proc;
631 /* nth_send () takes a processor read-lock */
632 while ((proc = (*i)->nth_send (nth))) {
633 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
634 if (!send || !send->output ()) {
638 if (!send->output ()->connected_to (p->name ())) {
642 /* if processor goes away, we're notified by the port disconnect,
643 * there should be no need to explicily connect to proc->DropReferences
645 set<Evoral::Parameter> p = proc->what_can_be_automated ();
646 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
647 Control* c = new Control (proc->automation_control (*i), _("Send"));
648 _controls.push_back (c);
650 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
660 PluginPinWidget::update_element_pos ()
663 _innerwidth = _width - 2. * _margin_x;
665 const double yc = rint (_height * .5);
666 const double bxh2 = rint (_margin_y * .45); // TODO grow?
667 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
668 const double bxw2 = rint (bxw * .5);
669 const double y_in = _margin_y;
670 const double y_out = _height - _margin_y;
675 const double dx = _pin_box_size * .5;
678 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
682 i->x = _innerwidth + _margin_x - dx;
683 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
684 i->h = _pin_box_size;
685 i->w = 1.5 * _pin_box_size;
688 uint32_t idx = i->e->id;
689 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
690 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
691 i->w = _pin_box_size;
692 i->h = 1.5 * _pin_box_size;
698 uint32_t idx = i->e->id;
699 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
700 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
702 i->w = _pin_box_size;
703 i->h = 1.5 * _pin_box_size;
708 uint32_t idx = i->e->id;
709 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
710 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
711 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
712 i->y = yc - bxh2 - dx;
713 i->w = _pin_box_size;
714 i->h = _pin_box_size;
719 uint32_t idx = i->e->id;
720 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
721 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
722 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
723 i->y = yc + bxh2 - dx;
724 i->w = _pin_box_size;
725 i->h = _pin_box_size;
733 PluginPinWidget::set_color (cairo_t* cr, bool midi)
735 // see also gtk2_ardour/processor_box.cc
736 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
737 static const uint32_t midi_port_color = 0x960909FF; //Red
740 cairo_set_source_rgb (cr,
741 UINT_RGBA_R_FLT (midi_port_color),
742 UINT_RGBA_G_FLT (midi_port_color),
743 UINT_RGBA_B_FLT (midi_port_color));
745 cairo_set_source_rgb (cr,
746 UINT_RGBA_R_FLT (audio_port_color),
747 UINT_RGBA_G_FLT (audio_port_color),
748 UINT_RGBA_B_FLT (audio_port_color));
753 PluginPinWidget::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
756 const double dy = w.h * .5;
757 const double dx = w.w - dy;
758 cairo_move_to (cr, w.x, w.y + dy);
759 cairo_rel_line_to (cr, dy, -dy);
760 cairo_rel_line_to (cr, dx, 0);
761 cairo_rel_line_to (cr, 0, w.h);
762 cairo_rel_line_to (cr, -dx, 0);
764 const double dir = (w.e->ct == Input) ? 1 : -1;
765 const double dx = w.w * .5;
766 const double dy = w.h - dx;
768 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
769 cairo_rel_line_to (cr, -dx, -dx * dir);
770 cairo_rel_line_to (cr, 0., -dy * dir);
771 cairo_rel_line_to (cr, 2. * dx, 0.);
772 cairo_rel_line_to (cr, 0., dy * dir);
774 cairo_close_path (cr);
776 cairo_set_line_width (cr, 1.0);
777 cairo_set_source_rgb (cr, 0, 0, 0);
778 cairo_stroke_preserve (cr);
780 set_color (cr, w.e->dt == DataType::MIDI);
783 assert (w.e->ct == Input);
784 cairo_fill_preserve (cr);
785 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
788 if (w.e == _selection || w.e == _actor) {
789 cairo_fill_preserve (cr);
790 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
791 } else if (w.prelight) {
792 cairo_fill_preserve (cr);
793 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
799 PluginPinWidget::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
801 const double dx = w.w * .5;
802 const double dy = w.h * .5;
804 cairo_move_to (cr, w.x + dx, w.y);
805 cairo_rel_line_to (cr, -dx, dy);
806 cairo_rel_line_to (cr, dx, dy);
807 cairo_rel_line_to (cr, dx, -dy);
808 cairo_close_path (cr);
810 cairo_set_line_width (cr, 1.0);
811 cairo_set_source_rgb (cr, 0, 0, 0);
812 cairo_stroke_preserve (cr);
814 set_color (cr, w.e->dt == DataType::MIDI);
817 assert (w.e->ct == Sink);
818 cairo_fill_preserve (cr);
819 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
822 if (w.e == _selection || w.e == _actor) {
823 cairo_fill_preserve (cr);
824 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
825 } else if (w.prelight) {
826 cairo_fill_preserve (cr);
827 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
831 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
834 Glib::RefPtr<Pango::Layout> layout;
835 layout = Pango::Layout::create (get_pango_context ());
836 layout->set_text (w.name);
837 layout->get_pixel_size (text_width, text_height);
839 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
840 cairo_set_source_rgba (cr, 0, 0, 0, .5);
843 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
844 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
845 pango_cairo_show_layout (cr, layout->gobj ());
850 PluginPinWidget::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
852 if (!midi) { i += n_midi; }
853 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
856 const PluginPinWidget::CtrlWidget&
857 PluginPinWidget::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
859 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
860 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
865 fatal << string_compose (_("programming error: %1"),
866 X_("Invalid Plugin I/O Port."))
868 abort (); /*NOTREACHED*/
869 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
870 return screw_old_compilers;
874 PluginPinWidget::edge_coordinates (const CtrlWidget& w, double &x, double &y)
902 PluginPinWidget::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
904 const double bz = 2 * _pin_box_size;
905 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
906 if (x0 > _width * .5) { bc *= -1; }
908 cairo_move_to (cr, x0, y0);
910 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
912 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
914 cairo_set_line_width (cr, 3.0);
915 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
916 cairo_set_source_rgb (cr, 1, 0, 0);
918 const double dashes[] = { 5, 7 };
919 cairo_set_dash (cr, dashes, 2, 0);
921 set_color (cr, midi);
924 cairo_set_dash (cr, 0, 0, 0);
929 PluginPinWidget::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
931 double x0, x1, y0, y1;
932 edge_coordinates (w0, x0, y0);
933 edge_coordinates (w1, x1, y1);
934 assert (w0.e->dt == w1.e->dt);
935 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
940 PluginPinWidget::darea_expose_event (GdkEventExpose* ev)
942 Gtk::Allocation a = darea.get_allocation ();
943 double const width = a.get_width ();
944 double const height = a.get_height ();
946 if (!_position_valid) {
949 update_element_pos ();
950 _position_valid = true;
953 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
954 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
957 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
958 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
959 cairo_rectangle (cr, 0, 0, width, height);
962 const double yc = rint (_height * .5);
965 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
966 cairo_set_line_width (cr, 1.0);
967 cairo_set_source_rgb (cr, .1, .1, .3);
968 cairo_stroke_preserve (cr);
969 cairo_set_source_rgb (cr, .3, .3, .3);
973 Glib::RefPtr<Pango::Layout> layout;
974 layout = Pango::Layout::create (get_pango_context ());
976 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
977 layout->set_width (_height * PANGO_SCALE);
982 layout->set_text (_route ()->name ());
983 layout->get_pixel_size (text_width, text_height);
985 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
986 cairo_rotate (cr, M_PI * -.5);
987 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
988 pango_cairo_show_layout (cr, layout->gobj ());
992 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
993 layout->set_text (_pi->name ());
994 layout->get_pixel_size (text_width, text_height);
995 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
996 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
997 pango_cairo_show_layout (cr, layout->gobj ());
1000 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
1001 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
1002 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
1003 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
1004 } else if (_pi->signal_latency () > 0) {
1005 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
1007 layout->set_text (_("no-inplace"));
1009 layout->get_pixel_size (text_width, text_height);
1010 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
1011 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1012 pango_cairo_show_layout (cr, layout->gobj ());
1016 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1017 layout->set_text (_("Strict I/O"));
1018 layout->get_pixel_size (text_width, text_height);
1019 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1020 const double sy0 = _height - 3 - text_height;
1022 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1023 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1026 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1027 cairo_move_to (cr, sx0, sy0);
1028 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1029 pango_cairo_show_layout (cr, layout->gobj ());
1032 /* draw midi-bypass (behind) */
1033 if (_has_midi_bypass) {
1034 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1035 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1036 draw_connection (cr, cw0, cw1, true);
1039 /* thru connections */
1040 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1041 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1042 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1043 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1044 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1045 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1046 draw_connection (cr, cw1, cw0, true);
1051 /* plugins & connection wires */
1052 for (uint32_t i = 0; i < _n_plugins; ++i) {
1053 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1056 cairo_set_source_rgb (cr, .5, .5, .5);
1057 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1060 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1061 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1062 layout->get_pixel_size (text_width, text_height);
1063 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1064 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1065 pango_cairo_show_layout (cr, layout->gobj ());
1067 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1068 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1070 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1071 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1072 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1073 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1074 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1075 draw_connection (cr, cw0, cw1);
1080 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1081 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1082 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1083 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1084 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1085 draw_connection (cr, cw0, cw1);
1091 /* pins and ports */
1092 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1096 draw_io_pin (cr, *i);
1100 draw_plugin_pin (cr, *i);
1106 CtrlWidget *drag_src = NULL;
1108 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1109 if (i->e == _selection ) {
1117 if (_selection->ct == Input || _selection->ct == Source) {
1118 edge_coordinates (*drag_src, x0, y0);
1119 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1120 _selection->dt == DataType::MIDI, _selection->sc);
1122 edge_coordinates (*drag_src, x0, y0);
1123 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1124 _selection->dt == DataType::MIDI, _selection->sc);
1133 PluginPinWidget::darea_size_request (Gtk::Requisition* req)
1135 req->width = _min_width;
1136 req->height = _min_height;
1140 PluginPinWidget::darea_size_allocate (Gtk::Allocation&)
1142 _position_valid = false;
1146 PluginPinWidget::drag_type_matches (const CtrlElem& e)
1148 if (!_dragging || !_selection) {
1151 if (_selection->dt != e->dt) {
1154 if (_selection->ct == Input && e->ct == Sink) { return true; }
1155 if (_selection->ct == Sink && e->ct == Input) { return true; }
1156 if (_selection->ct == Output && e->ct == Source) { return true; }
1157 if (_selection->ct == Source && e->ct == Output) { return true; }
1158 if (_selection->ct == Input && e->ct == Output) { return true; }
1159 if (_selection->ct == Output && e->ct == Input) { return true; }
1164 PluginPinWidget::start_drag (const CtrlElem& e, double x, double y)
1166 assert (_selection == e);
1168 if (e->ct == Sink) {
1170 const ChanMapping& map (_in_map[e->ip]);
1171 uint32_t idx = map.get (e->dt, e->id, &valid);
1173 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1178 else if (e->ct == Output) {
1179 for (uint32_t i = 0; i < _n_plugins; ++i) {
1181 const ChanMapping& map (_out_map[i]);
1182 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1184 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1192 const ChanMapping& map (_thru_map);
1193 uint32_t idx = map.get (e->dt, e->id, &valid);
1195 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1207 PluginPinWidget::darea_motion_notify_event (GdkEventMotion* ev)
1209 bool changed = false;
1211 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1212 if (ev->x >= i->x && ev->x <= i->x + i->w
1213 && ev->y >= i->y && ev->y <= i->y + i->h
1214 && drag_type_matches (i->e))
1216 if (!i->prelight) changed = true;
1220 if (i->prelight) changed = true;
1221 i->prelight = false;
1228 if (changed || _dragging) {
1229 darea.queue_draw ();
1235 PluginPinWidget::darea_button_press_event (GdkEventButton* ev)
1237 if (ev->type != GDK_BUTTON_PRESS) {
1241 switch (ev->button) {
1244 if (!_selection || (_selection && !_hover)) {
1245 _selection = _hover;
1248 start_drag (_selection, ev->x, ev->y);
1250 darea.queue_draw ();
1252 } else if (_selection && _hover && _selection != _hover) {
1253 if (_selection->dt != _hover->dt) { _actor.reset (); }
1254 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1255 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1256 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1257 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1258 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1259 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1261 _selection = _hover;
1262 start_drag (_selection, ev->x, ev->y);
1264 darea.queue_draw ();
1266 } else if (_hover) {
1267 _selection = _hover;
1269 start_drag (_selection, ev->x, ev->y);
1274 if (_selection != _hover) {
1275 _selection = _hover;
1276 darea.queue_draw ();
1288 PluginPinWidget::darea_button_release_event (GdkEventButton* ev)
1290 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1291 // select click. (or re-connect same)
1292 assert (_selection != _hover);
1297 darea.queue_draw ();
1301 if (_dragging && _hover && _hover != _selection) {
1305 if (_hover == _actor && _actor && ev->button == 1) {
1306 assert (_selection);
1307 assert (_selection->dt == _actor->dt);
1309 assert (_dragging && _selection != _drag_dst);
1310 handle_disconnect (_drag_dst, true);
1312 if (_selection->ct == Input && _actor->ct == Sink) {
1313 handle_input_action (_actor, _selection);
1315 else if (_selection->ct == Sink && _actor->ct == Input) {
1316 handle_input_action (_selection, _actor);
1318 else if (_selection->ct == Output && _actor->ct == Source) {
1319 handle_output_action (_actor, _selection);
1321 else if (_selection->ct == Source && _actor->ct == Output) {
1322 handle_output_action (_selection, _actor);
1324 else if (_selection->ct == Input && _actor->ct == Output) {
1325 handle_thru_action (_actor, _selection);
1327 else if (_selection->ct == Output && _actor->ct == Input) {
1328 handle_thru_action (_selection, _actor);
1330 _selection.reset ();
1331 } else if (_hover == _selection && _selection && ev->button == 3) {
1332 handle_disconnect (_selection);
1333 } else if (!_hover && ev->button == 3) {
1334 reset_menu.popup (1, ev->time);
1337 if (_dragging && _hover != _selection) {
1338 _selection.reset ();
1343 darea.queue_draw ();
1348 PluginPinWidget::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1350 const int pc = s->ip;
1352 ChanMapping in_map (_pi->input_map (pc));
1353 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1355 if (valid && idx == i->id) {
1358 in_map.unset (s->dt, s->id);
1359 _pi->set_input_map (pc, in_map);
1361 plugin_reconfigured ();
1366 in_map.set (s->dt, s->id, i->id);
1367 _pi->set_input_map (pc, in_map);
1371 in_map.unset (s->dt, s->id);
1372 in_map.set (s->dt, s->id, i->id);
1373 _pi->set_input_map (pc, in_map);
1378 PluginPinWidget::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1380 _ignore_updates = true;
1381 for (uint32_t n = 0; n < _n_plugins; ++n) {
1386 ChanMapping n_out_map (_pi->output_map (n));
1387 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1389 n_out_map.unset (dt, idx);
1390 _pi->set_output_map (n, n_out_map);
1393 _ignore_updates = false;
1397 PluginPinWidget::disconnect_other_thru (DataType dt, uint32_t id)
1399 _ignore_updates = true;
1401 ChanMapping n_thru_map (_pi->thru_map ());
1402 n_thru_map.get (dt, id, &valid);
1404 n_thru_map.unset (dt, id);
1405 _pi->set_thru_map (n_thru_map);
1407 _ignore_updates = false;
1411 PluginPinWidget::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1413 const uint32_t pc = s->ip;
1415 ChanMapping out_map (_pi->output_map (pc));
1416 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1418 if (valid && idx == o->id) {
1421 out_map.unset (s->dt, s->id);
1422 _pi->set_output_map (pc, out_map);
1424 plugin_reconfigured ();
1428 // disconnect source
1429 disconnect_other_outputs (pc, s->dt, o->id);
1430 disconnect_other_thru (s->dt, o->id);
1431 out_map = _pi->output_map (pc); // re-read map
1433 out_map.unset (s->dt, s->id);
1435 idx = out_map.get_src (s->dt, o->id, &valid);
1437 out_map.unset (s->dt, idx);
1440 out_map.set (s->dt, s->id, o->id);
1441 _pi->set_output_map (pc, out_map);
1446 PluginPinWidget::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1449 ChanMapping thru_map (_pi->thru_map ());
1450 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1452 if (valid && idx == i->id) {
1454 thru_map.unset (o->dt, o->id);
1457 // disconnect other outputs first
1458 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1459 disconnect_other_thru (o->dt, o->id);
1460 thru_map = _pi->thru_map (); // re-read map
1462 thru_map.set (o->dt, o->id, i->id);
1464 _pi->set_thru_map (thru_map);
1468 PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal)
1470 _ignore_updates = true;
1471 bool changed = false;
1477 ChanMapping n_thru_map (_pi->thru_map ());
1478 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1479 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1480 if (valid && idx == e->id) {
1481 n_thru_map.unset (e->dt, i);
1486 _pi->set_thru_map (n_thru_map);
1489 for (uint32_t n = 0; n < _n_plugins; ++n) {
1490 ChanMapping map (_pi->input_map (n));
1491 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1492 uint32_t idx = map.get (e->dt, i, &valid);
1493 if (valid && idx == e->id) {
1494 map.unset (e->dt, i);
1498 _pi->set_input_map (n, map);
1503 ChanMapping map (_pi->input_map (e->ip));
1504 map.get (e->dt, e->id, &valid);
1506 map.unset (e->dt, e->id);
1507 _pi->set_input_map (e->ip, map);
1514 ChanMapping map (_pi->output_map (e->ip));
1515 map.get (e->dt, e->id, &valid);
1517 map.unset (e->dt, e->id);
1518 _pi->set_output_map (e->ip, map);
1524 for (uint32_t n = 0; n < _n_plugins; ++n) {
1525 ChanMapping map (_pi->output_map (n));
1526 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1527 uint32_t idx = map.get (e->dt, i, &valid);
1528 if (valid && idx == e->id) {
1529 map.unset (e->dt, i);
1534 _pi->set_output_map (n, map);
1538 ChanMapping n_thru_map (_pi->thru_map ());
1539 n_thru_map.get (e->dt, e->id, &valid);
1541 n_thru_map.unset (e->dt, e->id);
1543 _pi->set_thru_map (n_thru_map);
1548 _ignore_updates = false;
1549 if (changed && !no_signal) {
1550 plugin_reconfigured ();
1556 PluginPinWidget::toggle_sidechain ()
1558 if (_session && _session->actively_recording ()) { return; }
1559 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1563 PluginPinWidget::connect_sidechain ()
1565 if (!_session) { return; }
1567 if (_sidechain_selector == 0) {
1568 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1571 if (_sidechain_selector->is_visible ()) {
1572 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1574 _sidechain_selector->present ();
1579 PluginPinWidget::reset_configuration ()
1581 if (_set_config.get_active ()) {
1582 _route ()->reset_plugin_insert (_pi);
1584 _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
1589 PluginPinWidget::reset_mapping ()
1595 PluginPinWidget::select_output_preset (uint32_t n_audio)
1597 if (_session && _session->actively_recording ()) { return; }
1598 ChanCount out (DataType::AUDIO, n_audio);
1599 _route ()->plugin_preset_output (_pi, out);
1603 PluginPinWidget::add_remove_plugin_clicked (bool add)
1605 if (_session && _session->actively_recording ()) { return; }
1606 ChanCount out = _out;
1607 ChanCount sinks = _sinks;
1608 assert (add || _n_plugins > 0);
1609 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks);
1613 PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1615 if (_session && _session->actively_recording ()) { return; }
1616 ChanCount out = _out;
1617 ChanCount sinks = _sinks;
1618 assert (add || out.get (dt) > 0);
1619 out.set (dt, out.get (dt) + (add ? 1 : -1));
1620 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1624 PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
1626 if (_session && _session->actively_recording ()) { return; }
1627 ChanCount out = _out;
1628 ChanCount sinks = _sinks;
1629 assert (add || sinks.get (dt) > 0);
1630 sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
1631 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1635 PluginPinWidget::add_sidechain_port (DataType dt)
1637 if (_session && _session->actively_recording ()) { return; }
1638 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1643 // this triggers a PluginIoReConfigure with process and processor write lock held
1644 // from /this/ thread.
1645 io->add_port ("", this, dt);
1649 PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1651 if (_session && _session->actively_recording ()) { return; }
1652 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1653 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1657 io->remove_port (p, this);
1661 PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1663 if (_session && _session->actively_recording ()) { return; }
1664 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1665 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1669 p->disconnect_all ();
1673 PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1675 if (_session && _session->actively_recording ()) { return; }
1676 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1677 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1678 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1679 if (!io || !p0 || !p1) {
1682 _ignore_updates = true;
1683 p0->disconnect_all ();
1684 _ignore_updates = false;
1685 p0->connect (p1->name ());
1689 PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1691 if (_session && _session->actively_recording ()) { return; }
1692 boost::shared_ptr<Port> p = wp.lock ();
1693 boost::shared_ptr<Route> r = wr.lock ();
1694 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1695 if (!p || !r || !io || !_session) {
1699 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1700 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1701 const ChanCount& outs (r->amp ()->input_streams ());
1703 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1704 send->output()->ensure_io (outs, false, this);
1705 } catch (AudioEngine::PortRegistrationFailure& err) {
1706 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1710 std::string sendname = send->name ();
1711 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1712 if (last_letter != string::npos) {
1713 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1715 sendname.substr (last_letter + 1)));
1718 _ignore_updates = true;
1719 p->disconnect_all ();
1721 DataType dt = p->type ();
1722 PortSet& ps (send->output ()->ports ());
1723 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1724 p->connect (&(**i));
1727 send->set_remove_on_disconnect (true);
1728 r->add_processor (send, PreFader);
1729 _ignore_updates = false;
1730 queue_idle_update ();
1734 PluginPinWidget::sc_input_release (GdkEventButton *ev)
1736 if (_session && _session->actively_recording ()) { return false; }
1737 if (ev->button == 3) {
1738 connect_sidechain ();
1744 PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1746 using namespace Menu_Helpers;
1747 if (!_session || _session->actively_recording ()) { return false; }
1748 if (!_session->engine ().connected ()) { return false; }
1750 if (ev->button == 1) {
1751 MenuList& citems = input_menu.items ();
1752 input_menu.set_name ("ArdourContextMenu");
1755 boost::shared_ptr<Port> p = wp.lock ();
1756 if (p && p->connected ()) {
1757 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::disconnect_port), wp)));
1758 citems.push_back (SeparatorElem ());
1762 // TODO add system inputs, too ?!
1763 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1764 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1765 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1767 //maybe_add_bundle_to_input_menu (*i, current);
1771 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1772 RouteList copy = *routes;
1773 copy.sort (Stripable::Sorter(true));
1775 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1776 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1780 citems.push_back (SeparatorElem ());
1782 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinWidget::connect_sidechain)));
1783 input_menu.popup (1, ev->time);
1789 PluginPinWidget::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1792 using namespace Menu_Helpers;
1793 if (r->output () == _route ()->output ()) {
1797 if (_route ()->feeds_according_to_graph (r)) {
1801 MenuList& citems = input_menu.items ();
1803 /*check if there's already a send.. */
1804 bool already_present = false;
1806 boost::shared_ptr<Processor> proc;
1807 /* Note: nth_send () takes a processor read-lock */
1808 while ((proc = r->nth_send (nth))) {
1809 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1810 if (!send || !send->output ()) {
1814 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1815 // only if (send->remove_on_disconnect ()) ??
1816 already_present = true;
1821 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1822 const ChanCount& rc (r->amp ()->input_streams ());
1823 if (!already_present && rc.get (dt) > 0) {
1824 citems.push_back (MenuElemNoMnemonic (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr<Route> (r))));
1831 PluginPinWidget::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1833 boost::shared_ptr<Port> p0 = w0.lock ();
1834 boost::shared_ptr<Port> p1 = w1.lock ();
1836 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1837 if (!io) { return; }
1839 if (p0 && io->has_port (p0)) {
1840 queue_idle_update ();
1842 else if (p1 && io->has_port (p1)) {
1843 queue_idle_update ();
1847 /* lifted from ProcessorEntry::Control */
1848 PluginPinWidget::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1850 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1851 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1852 , _slider_persistant_tooltip (&_slider)
1853 , _ignore_ui_adjustment (false)
1856 _slider.set_controllable (c);
1857 box.set_padding (0, 0, 4, 4);
1859 _slider.set_name ("ProcessorControlSlider");
1860 _slider.set_text (_name);
1865 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1866 double const lo = c->internal_to_interface (desc.lower);
1867 double const up = c->internal_to_interface (desc.upper);
1868 double const normal = c->internal_to_interface (desc.normal);
1869 double const smallstep = c->internal_to_interface (desc.lower + desc.smallstep);
1870 double const largestep = c->internal_to_interface (desc.lower + desc.largestep);
1872 _adjustment.set_lower (lo);
1873 _adjustment.set_upper (up);
1874 _adjustment.set_step_increment (smallstep);
1875 _adjustment.set_page_increment (largestep);
1876 _slider.set_default_value (normal);
1878 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1879 // dup. currently timers are used :(
1880 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1882 // yuck, do we really need to do this?
1883 // according to c404374 this is only needed for send automation
1884 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1889 /* We're providing our own PersistentTooltip */
1890 set_no_tooltip_whatsoever (_slider);
1893 PluginPinWidget::Control::~Control ()
1895 timer_connection.disconnect ();
1899 PluginPinWidget::Control::set_tooltip ()
1901 boost::shared_ptr<AutomationControl> c = _control.lock ();
1905 std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ());
1906 string sm = Gtkmm2ext::markup_escape_text (tt);
1907 _slider_persistant_tooltip.set_tip (sm);
1911 PluginPinWidget::Control::slider_adjusted ()
1913 if (_ignore_ui_adjustment) {
1916 boost::shared_ptr<AutomationControl> c = _control.lock ();
1920 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1926 PluginPinWidget::Control::control_changed ()
1928 boost::shared_ptr<AutomationControl> c = _control.lock ();
1933 _ignore_ui_adjustment = true;
1935 // as long as rapid timers are used, only update the tooltip
1936 // if the value has changed.
1937 const double nval = c->internal_to_interface (c->get_value ());
1938 if (_adjustment.get_value () != nval) {
1939 _adjustment.set_value (nval);
1943 _ignore_ui_adjustment = false;
1948 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
1949 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
1951 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
1956 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
1957 : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
1959 , _height_mapped (false)
1961 vbox = manage (new VBox ());
1962 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
1963 scroller = manage (new ScrolledWindow);
1964 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1965 scroller->set_shadow_type (Gtk::SHADOW_NONE);
1968 scroller->add (*vbox);
1972 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
1974 _route->processors_changed.connect (
1975 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context()
1978 _route->DropReferences.connect (
1979 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context()
1983 PluginPinDialog::set_session (ARDOUR::Session *s)
1985 SessionHandlePtr::set_session (s);
1986 for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) {
1987 (*i)->set_session (s);
1992 PluginPinDialog::map_height (Gtk::Allocation&)
1994 if (!_height_mapped) {
1995 scroller->set_size_request (-1, std::min (600, 2 + vbox->get_height()));
1996 _height_mapped = true;
2001 PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
2004 _height_mapped = false;
2005 scroller->remove ();
2006 vbox = manage (new VBox ());
2007 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
2008 scroller->add (*vbox);
2009 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2014 PluginPinDialog::route_going_away ()
2022 PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
2024 boost::shared_ptr<Processor> proc = p.lock ();
2025 if (!proc || !proc->display_to_user ()) {
2028 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
2030 if (pi && pi->is_channelstrip ()) {
2035 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
2036 vbox->pack_start (*ppw.back());
2038 HBox* hbox = manage (new HBox ());
2039 hbox->pack_start (*manage (new HSeparator ()));
2040 hbox->pack_start (*manage (new Label (proc->display_name ())));
2041 hbox->pack_start (*manage (new HSeparator ()));
2042 vbox->pack_start (*hbox, false, false);