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"
30 #include "gtkmm2ext/menu_elems.h"
32 #include "ardour/amp.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/pannable.h"
35 #include "ardour/plugin.h"
36 #include "ardour/port.h"
37 #include "ardour/profile.h"
38 #include "ardour/send.h"
39 #include "ardour/session.h"
40 #include "ardour/value_as_string.h"
42 #include "plugin_pin_dialog.h"
43 #include "gui_thread.h"
46 #include "ui_config.h"
50 using namespace ARDOUR;
54 using namespace Gtkmm2ext;
56 PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
57 : _set_config (_("Manual Config"), ArdourButton::led_default_elements)
58 , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements)
59 , _add_plugin (_("+"))
60 , _del_plugin (_("-"))
61 , _add_input_audio (_("+"))
62 , _del_input_audio (_("-"))
63 , _add_input_midi (_("+"))
64 , _del_input_midi (_("-"))
65 , _add_output_audio (_("+"))
66 , _del_output_audio (_("-"))
67 , _add_output_midi (_("+"))
68 , _del_output_midi (_("-"))
69 , _add_sc_audio (_("Audio"))
70 , _add_sc_midi (_("MIDI"))
82 , _position_valid (false)
83 , _ignore_updates (false)
84 , _sidechain_selector (0)
87 assert (pi->owner ()); // Route
89 _pi->PluginIoReConfigure.connect (
90 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
93 _pi->PluginMapChanged.connect (
94 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
97 _pi->PluginConfigChanged.connect (
98 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
101 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
102 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
103 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
105 _tgl_sidechain.set_name ("pinrouting sidechain");
106 _set_config.set_name ("pinrouting custom");
108 Menu_Helpers::MenuList& citems = reset_menu.items ();
109 reset_menu.set_name ("ArdourContextMenu");
111 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinWidget::reset_mapping)));
113 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
114 _add_plugin.set_tweaks (ArdourButton::Square);
115 _del_plugin.set_tweaks (ArdourButton::Square);
116 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
117 _pm_size_group->add_widget (_add_input_audio);
118 _pm_size_group->add_widget (_del_input_audio);
119 _pm_size_group->add_widget (_add_input_midi);
120 _pm_size_group->add_widget (_del_input_midi);
122 _pm_size_group->add_widget (_add_plugin);
123 _pm_size_group->add_widget (_del_plugin);
125 _pm_size_group->add_widget (_add_output_audio);
126 _pm_size_group->add_widget (_del_output_audio);
127 _pm_size_group->add_widget (_add_output_midi);
128 _pm_size_group->add_widget (_del_output_midi);
133 VBox* tl = manage (new VBox ());
134 tl->set_border_width (2);
137 VBox* tr = manage (new VBox ());
138 tr->set_border_width (2);
142 tl->pack_start (_set_config, false, false);
144 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
145 box = manage (new HBox ());
146 box->set_border_width (2);
147 box->pack_start (_add_input_audio, true, false);
148 box->pack_start (_del_input_audio, true, false);
149 f = manage (new Frame ());
150 f->set_label (_("Audio Input Pins"));
152 tl->pack_start (*f, false, false);
154 box = manage (new HBox ());
155 box->set_border_width (2);
156 box->pack_start (_add_input_midi, true, false);
157 box->pack_start (_del_input_midi, true, false);
158 f = manage (new Frame ());
159 f->set_label (_("MIDI Input Pins"));
161 tl->pack_start (*f, false, false);
163 box = manage (new HBox ());
164 box->set_border_width (2);
165 box->pack_start (_add_plugin, true, false);
166 box->pack_start (_del_plugin, true, false);
167 f = manage (new Frame ());
168 f->set_label (_("Instances"));
170 tl->pack_start (*f, false, false);
173 box = manage (new HBox ());
174 box->set_border_width (2);
175 box->pack_start (_add_output_audio, true, false);
176 box->pack_start (_del_output_audio, true, false);
177 f = manage (new Frame ());
178 f->set_label (_("Audio Out"));
180 tl->pack_start (*f, false, false);
182 box = manage (new HBox ());
183 box->set_border_width (2);
184 box->pack_start (_add_output_midi, true, false);
185 box->pack_start (_del_output_midi, true, false);
186 f = manage (new Frame ());
187 f->set_label (_("MIDI Out"));
189 tl->pack_start (*f, false, false);
191 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
192 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
193 _out_presets.disable_scrolling ();
194 ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
195 tl->pack_start (_out_presets, false, false);
198 _sidechain_tbl = manage (new Gtk::Table ());
199 _sidechain_tbl->set_spacings (2);
201 tr->pack_start (_tgl_sidechain, false, false);
202 tr->pack_start (*_sidechain_tbl, true, true);
204 box = manage (new VBox ());
205 box->set_border_width (2);
206 box->set_spacing (2);
207 box->pack_start (_add_sc_audio, false, false);
208 box->pack_start (_add_sc_midi , false, false);
209 f = manage (new Frame ());
210 f->set_label (_("Add Sidechain Input"));
213 tr->pack_start (*f, false, false);
216 HBox* hbox = manage (new HBox ());
217 hbox->set_spacing (4);
218 hbox->pack_start (*tl, false, false);
219 hbox->pack_start (darea, true, true);
220 hbox->pack_start (*tr, false, false);
222 pack_start (*hbox, true, true);
223 set_border_width (4);
226 plugin_reconfigured ();
228 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
229 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_request));
230 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_allocate));
231 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_expose_event));
232 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_press_event));
233 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_release_event));
234 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_motion_notify_event));
236 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::toggle_sidechain));
238 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::reset_configuration));
239 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), true));
240 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), false));
242 _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::AUDIO));
243 _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::AUDIO));
244 _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::MIDI));
245 _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::MIDI));
247 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::AUDIO));
248 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::AUDIO));
249 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::MIDI));
250 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::MIDI));
252 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::AUDIO));
253 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::MIDI));
255 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
256 _io_connection, invalidator (*this), boost::bind (&PluginPinWidget::port_connected_or_disconnected, this, _1, _3), gui_context ()
260 PluginPinWidget::~PluginPinWidget ()
262 delete _sidechain_selector;
266 PluginPinWidget::set_session (ARDOUR::Session *s)
268 SessionHandlePtr::set_session (s);
269 plugin_reconfigured ();
273 PluginPinWidget::queue_idle_update ()
275 /* various actions here are directly executed, in the GUI thread,
276 * with the GUI-thread eventually taking the process and processor lock.
277 * "connect gui_context()" will call back immediately and this
278 * signal-handler will run with the locks held.
280 * This will lead to a crash with calling nth_send() which takes
281 * a processor read-lock while holding a write lock in the same thread.
283 * decouple update to GUI idle.
285 * BUT, do delete existing controls here (in case they're affected by
286 * the change and hit by the Timer before idle comes around)
288 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
289 _sidechain_tbl->remove ((*i)->box);
293 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinWidget::idle_update));
297 PluginPinWidget::idle_update ()
299 plugin_reconfigured ();
305 PluginPinWidget::plugin_reconfigured ()
307 ENSURE_GUI_THREAD (*this, &PluginPinWidget::plugin_reconfigured);
308 if (_ignore_updates) {
311 _n_plugins = _pi->get_count ();
312 _pi->configured_io (_in, _out);
313 _ins = _pi->internal_streams (); // with sidechain
314 _sinks = _pi->natural_input_streams ();
315 _sources = _pi->natural_output_streams ();
318 _tgl_sidechain.set_active (_pi->has_sidechain ());
319 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
320 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
322 if (_pi->custom_cfg ()) {
323 _set_config.set_active (true);
324 _add_plugin.set_sensitive (true);
325 _del_plugin.set_sensitive (_n_plugins > 1);
326 _add_output_audio.set_sensitive (true);
327 _add_output_midi.set_sensitive (true);
328 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
329 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
330 _add_input_audio.set_sensitive (true);
331 _add_input_midi.set_sensitive (true);
332 _del_input_audio.set_sensitive (_sinks.n_audio () > 0 && _sinks.n_total () > 1);
333 _del_input_midi.set_sensitive (_sinks.n_midi () > 0 && _sinks.n_total () > 1);
334 _out_presets.set_sensitive (false);
335 _out_presets.set_text (_("Manual"));
337 _set_config.set_active (false);
338 _add_plugin.set_sensitive (false);
339 _del_plugin.set_sensitive (false);
340 _add_input_audio.set_sensitive (false);
341 _add_input_midi.set_sensitive (false);
342 _del_input_audio.set_sensitive (false);
343 _del_input_midi.set_sensitive (false);
344 _add_output_audio.set_sensitive (false);
345 _add_output_midi.set_sensitive (false);
346 _del_output_audio.set_sensitive (false);
347 _del_output_midi.set_sensitive (false);
348 _out_presets.set_sensitive (true);
349 refill_output_presets ();
352 if (!_pi->has_sidechain () && _sidechain_selector) {
353 delete _sidechain_selector;
354 _sidechain_selector = 0;
357 refill_sidechain_table ();
359 /* update elements */
368 _n_inputs = _n_sidechains = 0;
370 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
371 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
372 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
373 bool sidechain = id >= _in.get (dt) ? true : false;
380 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
381 _elements.push_back (cw);
384 for (uint32_t i = 0; i < _out.n_total (); ++i) {
385 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
386 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
392 for (uint32_t n = 0; n < _n_plugins; ++n) {
393 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
394 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
395 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
396 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
397 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
398 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
399 _elements.push_back (cw);
401 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
402 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
403 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
404 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
405 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
407 _in_map[n] = _pi->input_map (n);
408 _out_map[n] = _pi->output_map (n);
410 _has_midi_bypass = _pi->has_midi_bypass ();
411 _thru_map = _pi->thru_map ();
415 /* calc minimum size */
416 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
417 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
418 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
419 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
420 min_width = std::max ((uint32_t)300, min_width);
422 min_width = 50 + 10 * ceilf (min_width / 10.f);
424 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
425 min_height = std::max ((uint32_t)200, min_height);
426 min_height = 4 * ceilf (min_height / 4.f);
428 if (min_width != _min_width || min_height != _min_height) {
429 _min_width = min_width;
430 _min_height = min_height;
431 darea.queue_resize ();
434 _position_valid = false;
439 PluginPinWidget::refill_sidechain_table ()
441 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
442 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
445 _sidechain_tbl->resize (1, 1);
446 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
450 if (!_pi->has_sidechain () && _sidechain_selector) {
453 boost::shared_ptr<IO> io = _pi->sidechain_input ();
459 PortSet& p (io->ports ());
460 bool can_remove = p.num_ports () > 1;
461 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
462 r += add_port_to_table (*i, r, can_remove);
464 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
465 r += add_port_to_table (*i, r, can_remove);
467 _sidechain_tbl->show_all ();
471 PluginPinWidget::refill_output_presets ()
473 using namespace Menu_Helpers;
474 _out_presets.clear_items ();
476 bool need_dropdown = _pi->has_output_presets ();
478 if (!need_dropdown) {
479 _out_presets.set_sensitive (false);
480 _out_presets.set_text (_("Automatic"));
484 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), 0)));
486 const uint32_t n_audio = _pi->preset_out ().n_audio ();
488 _out_presets.set_text (_("Automatic"));
491 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
492 if (ppc.find (0) != ppc.end ()) {
496 ppc.insert (n_audio);
506 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
517 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
520 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), *i)));
522 _out_presets.set_text (tmp);
528 PluginPinWidget::port_label (const std::string& portname, bool strip)
530 // compare to MixerStrip::update_io_button()
531 string lpn (PROGRAM_NAME);
532 boost::to_lower (lpn);
533 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
535 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
537 string::size_type slash = pn.find ("/");
538 if (slash != string::npos) {
539 pn = pn.substr (0, slash);
543 std::string label (portname);
544 if (label.find ("system:capture_") == 0) {
545 if (label.empty ()) {
546 label = portname.substr (15);
548 } else if (label.find ("system:midi_capture_") == 0) {
549 if (label.empty ()) {
550 // "system:midi_capture_123" -> "123"
551 label = "M " + portname.substr (20);
553 } else if (label.find (program_port_prefix) == 0) {
554 label = label.substr (program_port_prefix.size ());
556 string::size_type slash = label.find ("/");
557 if (slash != string::npos) {
558 label = label.substr (0, slash);
566 PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
569 std::string tip = p->name ();
570 std::vector<std::string> cns;
571 bool single_source = true;
572 p->get_connections (cns);
574 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
576 lbl = port_label (*i, true);
579 if (port_label (*i, true) != lbl) {
581 single_source = false;
586 if (cns.size () == 0) {
588 single_source = false;
589 } else if (cns.size () == 1) {
591 lbl = port_label (cns[0], false);
595 replace_all (lbl, "_", " ");
597 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
602 ArdourButton *pb = manage (new ArdourButton (lbl));
603 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
604 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
605 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
606 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
608 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr<Port> (p)), false);
609 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::sc_input_release), false);
611 pb = manage (new ArdourButton ("-"));
612 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
614 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::remove_port), boost::weak_ptr<Port> (p)));
616 pb->set_sensitive (false);
621 if (single_source && _session) {
622 /* check if it's an Ardour Send feeding.. */
623 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
624 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
626 boost::shared_ptr<Processor> proc;
627 /* nth_send () takes a processor read-lock */
628 while ((proc = (*i)->nth_send (nth))) {
629 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
630 if (!send || !send->output ()) {
634 if (!send->output ()->connected_to (p->name ())) {
638 /* if processor goes away, we're notified by the port disconnect,
639 * there should be no need to explicily connect to proc->DropReferences
641 set<Evoral::Parameter> p = proc->what_can_be_automated ();
642 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
643 Control* c = new Control (proc->automation_control (*i), _("Send"));
644 _controls.push_back (c);
646 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
656 PluginPinWidget::update_element_pos ()
659 _innerwidth = _width - 2. * _margin_x;
661 const double yc = rint (_height * .5);
662 const double bxh2 = rint (_margin_y * .45); // TODO grow?
663 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
664 const double bxw2 = rint (bxw * .5);
665 const double y_in = _margin_y;
666 const double y_out = _height - _margin_y;
671 const double dx = _pin_box_size * .5;
674 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
678 i->x = _innerwidth + _margin_x - dx;
679 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
680 i->h = _pin_box_size;
681 i->w = 1.5 * _pin_box_size;
684 uint32_t idx = i->e->id;
685 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
686 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
687 i->w = _pin_box_size;
688 i->h = 1.5 * _pin_box_size;
694 uint32_t idx = i->e->id;
695 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
696 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
698 i->w = _pin_box_size;
699 i->h = 1.5 * _pin_box_size;
704 uint32_t idx = i->e->id;
705 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
706 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
707 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
708 i->y = yc - bxh2 - dx;
709 i->w = _pin_box_size;
710 i->h = _pin_box_size;
715 uint32_t idx = i->e->id;
716 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
717 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
718 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
719 i->y = yc + bxh2 - dx;
720 i->w = _pin_box_size;
721 i->h = _pin_box_size;
729 PluginPinWidget::set_color (cairo_t* cr, bool midi)
731 // see also gtk2_ardour/processor_box.cc
732 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
733 static const uint32_t midi_port_color = 0x960909FF; //Red
736 cairo_set_source_rgb (cr,
737 UINT_RGBA_R_FLT (midi_port_color),
738 UINT_RGBA_G_FLT (midi_port_color),
739 UINT_RGBA_B_FLT (midi_port_color));
741 cairo_set_source_rgb (cr,
742 UINT_RGBA_R_FLT (audio_port_color),
743 UINT_RGBA_G_FLT (audio_port_color),
744 UINT_RGBA_B_FLT (audio_port_color));
749 PluginPinWidget::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
752 const double dy = w.h * .5;
753 const double dx = w.w - dy;
754 cairo_move_to (cr, w.x, w.y + dy);
755 cairo_rel_line_to (cr, dy, -dy);
756 cairo_rel_line_to (cr, dx, 0);
757 cairo_rel_line_to (cr, 0, w.h);
758 cairo_rel_line_to (cr, -dx, 0);
760 const double dir = (w.e->ct == Input) ? 1 : -1;
761 const double dx = w.w * .5;
762 const double dy = w.h - dx;
764 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
765 cairo_rel_line_to (cr, -dx, -dx * dir);
766 cairo_rel_line_to (cr, 0., -dy * dir);
767 cairo_rel_line_to (cr, 2. * dx, 0.);
768 cairo_rel_line_to (cr, 0., dy * dir);
770 cairo_close_path (cr);
772 cairo_set_line_width (cr, 1.0);
773 cairo_set_source_rgb (cr, 0, 0, 0);
774 cairo_stroke_preserve (cr);
776 set_color (cr, w.e->dt == DataType::MIDI);
779 assert (w.e->ct == Input);
780 cairo_fill_preserve (cr);
781 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
784 if (w.e == _selection || w.e == _actor) {
785 cairo_fill_preserve (cr);
786 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
787 } else if (w.prelight) {
788 cairo_fill_preserve (cr);
789 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
795 PluginPinWidget::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
797 const double dx = w.w * .5;
798 const double dy = w.h * .5;
800 cairo_move_to (cr, w.x + dx, w.y);
801 cairo_rel_line_to (cr, -dx, dy);
802 cairo_rel_line_to (cr, dx, dy);
803 cairo_rel_line_to (cr, dx, -dy);
804 cairo_close_path (cr);
806 cairo_set_line_width (cr, 1.0);
807 cairo_set_source_rgb (cr, 0, 0, 0);
808 cairo_stroke_preserve (cr);
810 set_color (cr, w.e->dt == DataType::MIDI);
813 assert (w.e->ct == Sink);
814 cairo_fill_preserve (cr);
815 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
818 if (w.e == _selection || w.e == _actor) {
819 cairo_fill_preserve (cr);
820 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
821 } else if (w.prelight) {
822 cairo_fill_preserve (cr);
823 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
827 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
830 Glib::RefPtr<Pango::Layout> layout;
831 layout = Pango::Layout::create (get_pango_context ());
832 layout->set_text (w.name);
833 layout->get_pixel_size (text_width, text_height);
835 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
836 cairo_set_source_rgba (cr, 0, 0, 0, .5);
839 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
840 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
841 pango_cairo_show_layout (cr, layout->gobj ());
846 PluginPinWidget::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
848 if (!midi) { i += n_midi; }
849 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
852 const PluginPinWidget::CtrlWidget&
853 PluginPinWidget::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
855 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
856 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
861 fatal << string_compose (_("programming error: %1"),
862 X_("Invalid Plugin I/O Port."))
864 abort (); /*NOTREACHED*/
865 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
866 return screw_old_compilers;
870 PluginPinWidget::edge_coordinates (const CtrlWidget& w, double &x, double &y)
898 PluginPinWidget::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
900 const double bz = 2 * _pin_box_size;
901 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
902 if (x0 > _width * .5) { bc *= -1; }
904 cairo_move_to (cr, x0, y0);
906 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
908 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
910 cairo_set_line_width (cr, 3.0);
911 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
912 cairo_set_source_rgb (cr, 1, 0, 0);
914 const double dashes[] = { 5, 7 };
915 cairo_set_dash (cr, dashes, 2, 0);
917 set_color (cr, midi);
920 cairo_set_dash (cr, 0, 0, 0);
925 PluginPinWidget::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
927 double x0, x1, y0, y1;
928 edge_coordinates (w0, x0, y0);
929 edge_coordinates (w1, x1, y1);
930 assert (w0.e->dt == w1.e->dt);
931 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
936 PluginPinWidget::darea_expose_event (GdkEventExpose* ev)
938 Gtk::Allocation a = darea.get_allocation ();
939 double const width = a.get_width ();
940 double const height = a.get_height ();
942 if (!_position_valid) {
945 update_element_pos ();
946 _position_valid = true;
949 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
950 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
953 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
954 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
955 cairo_rectangle (cr, 0, 0, width, height);
958 const double yc = rint (_height * .5);
961 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
962 cairo_set_line_width (cr, 1.0);
963 cairo_set_source_rgb (cr, .1, .1, .3);
964 cairo_stroke_preserve (cr);
965 cairo_set_source_rgb (cr, .3, .3, .3);
969 Glib::RefPtr<Pango::Layout> layout;
970 layout = Pango::Layout::create (get_pango_context ());
972 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
973 layout->set_width (_height * PANGO_SCALE);
978 layout->set_text (_route ()->name ());
979 layout->get_pixel_size (text_width, text_height);
981 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
982 cairo_rotate (cr, M_PI * -.5);
983 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
984 pango_cairo_show_layout (cr, layout->gobj ());
988 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
989 layout->set_text (_pi->name ());
990 layout->get_pixel_size (text_width, text_height);
991 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
992 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
993 pango_cairo_show_layout (cr, layout->gobj ());
996 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
997 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
998 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
999 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
1000 } else if (_pi->signal_latency () > 0) {
1001 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
1003 layout->set_text (_("no-inplace"));
1005 layout->get_pixel_size (text_width, text_height);
1006 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
1007 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1008 pango_cairo_show_layout (cr, layout->gobj ());
1012 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1013 layout->set_text (_("Strict I/O"));
1014 layout->get_pixel_size (text_width, text_height);
1015 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1016 const double sy0 = _height - 3 - text_height;
1018 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1019 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1022 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1023 cairo_move_to (cr, sx0, sy0);
1024 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1025 pango_cairo_show_layout (cr, layout->gobj ());
1028 /* draw midi-bypass (behind) */
1029 if (_has_midi_bypass) {
1030 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1031 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1032 draw_connection (cr, cw0, cw1, true);
1035 /* thru connections */
1036 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1037 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1038 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1039 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1040 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1041 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1042 draw_connection (cr, cw1, cw0, true);
1047 /* plugins & connection wires */
1048 for (uint32_t i = 0; i < _n_plugins; ++i) {
1049 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1052 cairo_set_source_rgb (cr, .5, .5, .5);
1053 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1056 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1057 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1058 layout->get_pixel_size (text_width, text_height);
1059 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1060 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1061 pango_cairo_show_layout (cr, layout->gobj ());
1063 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1064 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1066 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1067 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1068 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1069 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1070 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1071 draw_connection (cr, cw0, cw1);
1076 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1077 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1078 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1079 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1080 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1081 draw_connection (cr, cw0, cw1);
1087 /* pins and ports */
1088 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1092 draw_io_pin (cr, *i);
1096 draw_plugin_pin (cr, *i);
1102 CtrlWidget *drag_src = NULL;
1104 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1105 if (i->e == _selection ) {
1113 if (_selection->ct == Input || _selection->ct == Source) {
1114 edge_coordinates (*drag_src, x0, y0);
1115 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1116 _selection->dt == DataType::MIDI, _selection->sc);
1118 edge_coordinates (*drag_src, x0, y0);
1119 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1120 _selection->dt == DataType::MIDI, _selection->sc);
1129 PluginPinWidget::darea_size_request (Gtk::Requisition* req)
1131 req->width = _min_width;
1132 req->height = _min_height;
1136 PluginPinWidget::darea_size_allocate (Gtk::Allocation&)
1138 _position_valid = false;
1142 PluginPinWidget::drag_type_matches (const CtrlElem& e)
1144 if (!_dragging || !_selection) {
1147 if (_selection->dt != e->dt) {
1150 if (_selection->ct == Input && e->ct == Sink) { return true; }
1151 if (_selection->ct == Sink && e->ct == Input) { return true; }
1152 if (_selection->ct == Output && e->ct == Source) { return true; }
1153 if (_selection->ct == Source && e->ct == Output) { return true; }
1154 if (_selection->ct == Input && e->ct == Output) { return true; }
1155 if (_selection->ct == Output && e->ct == Input) { return true; }
1160 PluginPinWidget::start_drag (const CtrlElem& e, double x, double y)
1162 assert (_selection == e);
1164 if (e->ct == Sink) {
1166 const ChanMapping& map (_in_map[e->ip]);
1167 uint32_t idx = map.get (e->dt, e->id, &valid);
1169 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1174 else if (e->ct == Output) {
1175 for (uint32_t i = 0; i < _n_plugins; ++i) {
1177 const ChanMapping& map (_out_map[i]);
1178 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1180 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1188 const ChanMapping& map (_thru_map);
1189 uint32_t idx = map.get (e->dt, e->id, &valid);
1191 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1203 PluginPinWidget::darea_motion_notify_event (GdkEventMotion* ev)
1205 bool changed = false;
1207 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1208 if (ev->x >= i->x && ev->x <= i->x + i->w
1209 && ev->y >= i->y && ev->y <= i->y + i->h
1210 && drag_type_matches (i->e))
1212 if (!i->prelight) changed = true;
1216 if (i->prelight) changed = true;
1217 i->prelight = false;
1224 if (changed || _dragging) {
1225 darea.queue_draw ();
1231 PluginPinWidget::darea_button_press_event (GdkEventButton* ev)
1233 if (ev->type != GDK_BUTTON_PRESS) {
1237 switch (ev->button) {
1240 if (!_selection || (_selection && !_hover)) {
1241 _selection = _hover;
1244 start_drag (_selection, ev->x, ev->y);
1246 darea.queue_draw ();
1248 } else if (_selection && _hover && _selection != _hover) {
1249 if (_selection->dt != _hover->dt) { _actor.reset (); }
1250 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1251 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1252 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1253 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1254 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1255 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1257 _selection = _hover;
1258 start_drag (_selection, ev->x, ev->y);
1260 darea.queue_draw ();
1262 } else if (_hover) {
1263 _selection = _hover;
1265 start_drag (_selection, ev->x, ev->y);
1270 if (_selection != _hover) {
1271 _selection = _hover;
1272 darea.queue_draw ();
1284 PluginPinWidget::darea_button_release_event (GdkEventButton* ev)
1286 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1287 // select click. (or re-connect same)
1288 assert (_selection != _hover);
1293 darea.queue_draw ();
1297 if (_dragging && _hover && _hover != _selection) {
1301 if (_hover == _actor && _actor && ev->button == 1) {
1302 assert (_selection);
1303 assert (_selection->dt == _actor->dt);
1305 assert (_dragging && _selection != _drag_dst);
1306 handle_disconnect (_drag_dst, true);
1308 if (_selection->ct == Input && _actor->ct == Sink) {
1309 handle_input_action (_actor, _selection);
1311 else if (_selection->ct == Sink && _actor->ct == Input) {
1312 handle_input_action (_selection, _actor);
1314 else if (_selection->ct == Output && _actor->ct == Source) {
1315 handle_output_action (_actor, _selection);
1317 else if (_selection->ct == Source && _actor->ct == Output) {
1318 handle_output_action (_selection, _actor);
1320 else if (_selection->ct == Input && _actor->ct == Output) {
1321 handle_thru_action (_actor, _selection);
1323 else if (_selection->ct == Output && _actor->ct == Input) {
1324 handle_thru_action (_selection, _actor);
1326 _selection.reset ();
1327 } else if (_hover == _selection && _selection && ev->button == 3) {
1328 handle_disconnect (_selection);
1329 } else if (!_hover && ev->button == 3) {
1330 reset_menu.popup (1, ev->time);
1333 if (_dragging && _hover != _selection) {
1334 _selection.reset ();
1339 darea.queue_draw ();
1344 PluginPinWidget::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1346 const int pc = s->ip;
1348 ChanMapping in_map (_pi->input_map (pc));
1349 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1351 if (valid && idx == i->id) {
1354 in_map.unset (s->dt, s->id);
1355 _pi->set_input_map (pc, in_map);
1357 plugin_reconfigured ();
1362 in_map.set (s->dt, s->id, i->id);
1363 _pi->set_input_map (pc, in_map);
1367 in_map.unset (s->dt, s->id);
1368 in_map.set (s->dt, s->id, i->id);
1369 _pi->set_input_map (pc, in_map);
1374 PluginPinWidget::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1376 _ignore_updates = true;
1377 for (uint32_t n = 0; n < _n_plugins; ++n) {
1382 ChanMapping n_out_map (_pi->output_map (n));
1383 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1385 n_out_map.unset (dt, idx);
1386 _pi->set_output_map (n, n_out_map);
1389 _ignore_updates = false;
1393 PluginPinWidget::disconnect_other_thru (DataType dt, uint32_t id)
1395 _ignore_updates = true;
1397 ChanMapping n_thru_map (_pi->thru_map ());
1398 n_thru_map.get (dt, id, &valid);
1400 n_thru_map.unset (dt, id);
1401 _pi->set_thru_map (n_thru_map);
1403 _ignore_updates = false;
1407 PluginPinWidget::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1409 const uint32_t pc = s->ip;
1411 ChanMapping out_map (_pi->output_map (pc));
1412 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1414 if (valid && idx == o->id) {
1417 out_map.unset (s->dt, s->id);
1418 _pi->set_output_map (pc, out_map);
1420 plugin_reconfigured ();
1424 // disconnect source
1425 disconnect_other_outputs (pc, s->dt, o->id);
1426 disconnect_other_thru (s->dt, o->id);
1427 out_map = _pi->output_map (pc); // re-read map
1429 out_map.unset (s->dt, s->id);
1431 idx = out_map.get_src (s->dt, o->id, &valid);
1433 out_map.unset (s->dt, idx);
1436 out_map.set (s->dt, s->id, o->id);
1437 _pi->set_output_map (pc, out_map);
1442 PluginPinWidget::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1445 ChanMapping thru_map (_pi->thru_map ());
1446 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1448 if (valid && idx == i->id) {
1450 thru_map.unset (o->dt, o->id);
1453 // disconnect other outputs first
1454 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1455 disconnect_other_thru (o->dt, o->id);
1456 thru_map = _pi->thru_map (); // re-read map
1458 thru_map.set (o->dt, o->id, i->id);
1460 _pi->set_thru_map (thru_map);
1464 PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal)
1466 _ignore_updates = true;
1467 bool changed = false;
1473 ChanMapping n_thru_map (_pi->thru_map ());
1474 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1475 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1476 if (valid && idx == e->id) {
1477 n_thru_map.unset (e->dt, i);
1482 _pi->set_thru_map (n_thru_map);
1485 for (uint32_t n = 0; n < _n_plugins; ++n) {
1486 ChanMapping map (_pi->input_map (n));
1487 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1488 uint32_t idx = map.get (e->dt, i, &valid);
1489 if (valid && idx == e->id) {
1490 map.unset (e->dt, i);
1494 _pi->set_input_map (n, map);
1499 ChanMapping map (_pi->input_map (e->ip));
1500 map.get (e->dt, e->id, &valid);
1502 map.unset (e->dt, e->id);
1503 _pi->set_input_map (e->ip, map);
1510 ChanMapping map (_pi->output_map (e->ip));
1511 map.get (e->dt, e->id, &valid);
1513 map.unset (e->dt, e->id);
1514 _pi->set_output_map (e->ip, map);
1520 for (uint32_t n = 0; n < _n_plugins; ++n) {
1521 ChanMapping map (_pi->output_map (n));
1522 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1523 uint32_t idx = map.get (e->dt, i, &valid);
1524 if (valid && idx == e->id) {
1525 map.unset (e->dt, i);
1530 _pi->set_output_map (n, map);
1534 ChanMapping n_thru_map (_pi->thru_map ());
1535 n_thru_map.get (e->dt, e->id, &valid);
1537 n_thru_map.unset (e->dt, e->id);
1539 _pi->set_thru_map (n_thru_map);
1544 _ignore_updates = false;
1545 if (changed && !no_signal) {
1546 plugin_reconfigured ();
1552 PluginPinWidget::toggle_sidechain ()
1554 if (_session && _session->actively_recording ()) { return; }
1555 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1559 PluginPinWidget::connect_sidechain ()
1561 if (!_session) { return; }
1563 if (_sidechain_selector == 0) {
1564 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1567 if (_sidechain_selector->is_visible ()) {
1568 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1570 _sidechain_selector->present ();
1575 PluginPinWidget::reset_configuration ()
1577 if (_set_config.get_active ()) {
1578 _route ()->reset_plugin_insert (_pi);
1580 _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
1585 PluginPinWidget::reset_mapping ()
1591 PluginPinWidget::select_output_preset (uint32_t n_audio)
1593 if (_session && _session->actively_recording ()) { return; }
1594 ChanCount out (DataType::AUDIO, n_audio);
1595 _route ()->plugin_preset_output (_pi, out);
1599 PluginPinWidget::add_remove_plugin_clicked (bool add)
1601 if (_session && _session->actively_recording ()) { return; }
1602 ChanCount out = _out;
1603 ChanCount sinks = _sinks;
1604 assert (add || _n_plugins > 0);
1605 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks);
1609 PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1611 if (_session && _session->actively_recording ()) { return; }
1612 ChanCount out = _out;
1613 ChanCount sinks = _sinks;
1614 assert (add || out.get (dt) > 0);
1615 out.set (dt, out.get (dt) + (add ? 1 : -1));
1616 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1620 PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
1622 if (_session && _session->actively_recording ()) { return; }
1623 ChanCount out = _out;
1624 ChanCount sinks = _sinks;
1625 assert (add || sinks.get (dt) > 0);
1626 sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
1627 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1631 PluginPinWidget::add_sidechain_port (DataType dt)
1633 if (_session && _session->actively_recording ()) { return; }
1634 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1639 // this triggers a PluginIoReConfigure with process and processor write lock held
1640 // from /this/ thread.
1641 io->add_port ("", this, dt);
1645 PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1647 if (_session && _session->actively_recording ()) { return; }
1648 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1649 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1653 io->remove_port (p, this);
1657 PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1659 if (_session && _session->actively_recording ()) { return; }
1660 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1661 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1665 p->disconnect_all ();
1669 PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1671 if (_session && _session->actively_recording ()) { return; }
1672 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1673 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1674 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1675 if (!io || !p0 || !p1) {
1678 _ignore_updates = true;
1679 p0->disconnect_all ();
1680 _ignore_updates = false;
1681 p0->connect (p1->name ());
1685 PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1687 if (_session && _session->actively_recording ()) { return; }
1688 boost::shared_ptr<Port> p = wp.lock ();
1689 boost::shared_ptr<Route> r = wr.lock ();
1690 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1691 if (!p || !r || !io || !_session) {
1695 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1696 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1697 const ChanCount& outs (r->amp ()->input_streams ());
1699 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1700 send->output()->ensure_io (outs, false, this);
1701 } catch (AudioEngine::PortRegistrationFailure& err) {
1702 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1706 std::string sendname = send->name ();
1707 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1708 if (last_letter != string::npos) {
1709 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1711 sendname.substr (last_letter + 1)));
1714 _ignore_updates = true;
1715 p->disconnect_all ();
1717 DataType dt = p->type ();
1718 PortSet& ps (send->output ()->ports ());
1719 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1720 p->connect (&(**i));
1723 send->set_remove_on_disconnect (true);
1724 r->add_processor (send, PreFader);
1725 _ignore_updates = false;
1726 queue_idle_update ();
1730 PluginPinWidget::sc_input_release (GdkEventButton *ev)
1732 if (_session && _session->actively_recording ()) { return false; }
1733 if (ev->button == 3) {
1734 connect_sidechain ();
1739 struct RouteCompareByName {
1740 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1741 return a->name ().compare (b->name ()) < 0;
1746 PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1748 using namespace Menu_Helpers;
1749 if (!_session || _session->actively_recording ()) { return false; }
1750 if (!_session->engine ().connected ()) { return false; }
1752 if (ev->button == 1) {
1753 MenuList& citems = input_menu.items ();
1754 input_menu.set_name ("ArdourContextMenu");
1757 boost::shared_ptr<Port> p = wp.lock ();
1758 if (p && p->connected ()) {
1759 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::disconnect_port), wp)));
1760 citems.push_back (SeparatorElem ());
1764 // TODO add system inputs, too ?!
1765 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1766 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1767 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1769 //maybe_add_bundle_to_input_menu (*i, current);
1773 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1774 RouteList copy = *routes;
1775 copy.sort (RouteCompareByName ());
1777 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1778 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1782 citems.push_back (SeparatorElem ());
1784 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinWidget::connect_sidechain)));
1785 input_menu.popup (1, ev->time);
1791 PluginPinWidget::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1794 using namespace Menu_Helpers;
1795 if (r->output () == _route ()->output ()) {
1799 if (_route ()->feeds_according_to_graph (r)) {
1803 MenuList& citems = input_menu.items ();
1805 /*check if there's already a send.. */
1806 bool already_present = false;
1808 boost::shared_ptr<Processor> proc;
1809 /* Note: nth_send () takes a processor read-lock */
1810 while ((proc = r->nth_send (nth))) {
1811 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1812 if (!send || !send->output ()) {
1816 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1817 // only if (send->remove_on_disconnect ()) ??
1818 already_present = true;
1823 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1824 const ChanCount& rc (r->amp ()->input_streams ());
1825 if (!already_present && rc.get (dt) > 0) {
1826 citems.push_back (MenuElemNoMnemonic (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr<Route> (r))));
1833 PluginPinWidget::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1835 boost::shared_ptr<Port> p0 = w0.lock ();
1836 boost::shared_ptr<Port> p1 = w1.lock ();
1838 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1839 if (!io) { return; }
1841 if (p0 && io->has_port (p0)) {
1842 queue_idle_update ();
1844 else if (p1 && io->has_port (p1)) {
1845 queue_idle_update ();
1849 /* lifted from ProcessorEntry::Control */
1850 PluginPinWidget::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1852 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1853 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1854 , _slider_persistant_tooltip (&_slider)
1855 , _ignore_ui_adjustment (false)
1858 _slider.set_controllable (c);
1859 box.set_padding (0, 0, 4, 4);
1861 _slider.set_name ("ProcessorControlSlider");
1862 _slider.set_text (_name);
1867 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1868 double const lo = c->internal_to_interface (desc.lower);
1869 double const up = c->internal_to_interface (desc.upper);
1870 double const normal = c->internal_to_interface (desc.normal);
1871 double const smallstep = c->internal_to_interface (desc.lower + desc.smallstep);
1872 double const largestep = c->internal_to_interface (desc.lower + desc.largestep);
1874 _adjustment.set_lower (lo);
1875 _adjustment.set_upper (up);
1876 _adjustment.set_step_increment (smallstep);
1877 _adjustment.set_page_increment (largestep);
1878 _slider.set_default_value (normal);
1880 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1881 // dup. currently timers are used :(
1882 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1884 // yuck, do we really need to do this?
1885 // according to c404374 this is only needed for send automation
1886 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1891 /* We're providing our own PersistentTooltip */
1892 set_no_tooltip_whatsoever (_slider);
1895 PluginPinWidget::Control::~Control ()
1897 timer_connection.disconnect ();
1901 PluginPinWidget::Control::set_tooltip ()
1903 boost::shared_ptr<AutomationControl> c = _control.lock ();
1907 std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ());
1908 string sm = Gtkmm2ext::markup_escape_text (tt);
1909 _slider_persistant_tooltip.set_tip (sm);
1913 PluginPinWidget::Control::slider_adjusted ()
1915 if (_ignore_ui_adjustment) {
1918 boost::shared_ptr<AutomationControl> c = _control.lock ();
1922 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1928 PluginPinWidget::Control::control_changed ()
1930 boost::shared_ptr<AutomationControl> c = _control.lock ();
1935 _ignore_ui_adjustment = true;
1937 // as long as rapid timers are used, only update the tooltip
1938 // if the value has changed.
1939 const double nval = c->internal_to_interface (c->get_value ());
1940 if (_adjustment.get_value () != nval) {
1941 _adjustment.set_value (nval);
1945 _ignore_ui_adjustment = false;
1950 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
1951 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
1953 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
1958 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
1959 : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
1961 , _height_mapped (false)
1963 vbox = manage (new VBox ());
1964 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
1965 scroller = manage (new ScrolledWindow);
1966 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1967 scroller->set_shadow_type (Gtk::SHADOW_NONE);
1970 scroller->add (*vbox);
1974 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
1976 _route->processors_changed.connect (
1977 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context()
1980 _route->DropReferences.connect (
1981 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context()
1985 PluginPinDialog::set_session (ARDOUR::Session *s)
1987 SessionHandlePtr::set_session (s);
1988 for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) {
1989 (*i)->set_session (s);
1994 PluginPinDialog::map_height (Gtk::Allocation&)
1996 if (!_height_mapped) {
1997 scroller->set_size_request (-1, std::min (600, 2 + vbox->get_height()));
1998 _height_mapped = true;
2003 PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
2006 _height_mapped = false;
2007 scroller->remove ();
2008 vbox = manage (new VBox ());
2009 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
2010 scroller->add (*vbox);
2011 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2016 PluginPinDialog::route_going_away ()
2024 PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
2026 boost::shared_ptr<Processor> proc = p.lock ();
2027 if (!proc || !proc->display_to_user ()) {
2030 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
2032 if (pi && pi->is_channelstrip ()) {
2037 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
2038 vbox->pack_start (*ppw.back());
2040 HBox* hbox = manage (new HBox ());
2041 hbox->pack_start (*manage (new HSeparator ()));
2042 hbox->pack_start (*manage (new Label (proc->display_name ())));
2043 hbox->pack_start (*manage (new HSeparator ()));
2044 vbox->pack_start (*hbox, false, false);