2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2011 Paul Davis
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <boost/algorithm/string.hpp>
22 #include <gtkmm/table.h>
23 #include <gtkmm/frame.h>
24 #include <gtkmm/label.h>
26 #include "pbd/replace_all.h"
28 #include "gtkmm2ext/utils.h"
29 #include "gtkmm2ext/rgb_macros.h"
31 #include "ardour/amp.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/pannable.h"
34 #include "ardour/plugin.h"
35 #include "ardour/port.h"
36 #include "ardour/profile.h"
37 #include "ardour/send.h"
38 #include "ardour/session.h"
40 #include "plugin_pin_dialog.h"
41 #include "gui_thread.h"
44 #include "ui_config.h"
48 using namespace ARDOUR;
52 using namespace Gtkmm2ext;
54 PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
55 : _set_config (_("Manual Config"), ArdourButton::led_default_elements)
56 , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements)
57 , _add_plugin (_("+"))
58 , _del_plugin (_("-"))
59 , _add_input_audio (_("+"))
60 , _del_input_audio (_("-"))
61 , _add_input_midi (_("+"))
62 , _del_input_midi (_("-"))
63 , _add_output_audio (_("+"))
64 , _del_output_audio (_("-"))
65 , _add_output_midi (_("+"))
66 , _del_output_midi (_("-"))
67 , _add_sc_audio (_("Audio"))
68 , _add_sc_midi (_("MIDI"))
80 , _position_valid (false)
81 , _ignore_updates (false)
82 , _sidechain_selector (0)
85 assert (pi->owner ()); // Route
87 _pi->PluginIoReConfigure.connect (
88 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
91 _pi->PluginMapChanged.connect (
92 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
95 _pi->PluginConfigChanged.connect (
96 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
99 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
100 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
101 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
103 _tgl_sidechain.set_name ("pinrouting sidechain");
104 _set_config.set_name ("pinrouting custom");
106 Menu_Helpers::MenuList& citems = reset_menu.items ();
107 reset_menu.set_name ("ArdourContextMenu");
109 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinWidget::reset_mapping)));
111 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
112 _add_plugin.set_tweaks (ArdourButton::Square);
113 _del_plugin.set_tweaks (ArdourButton::Square);
114 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
115 _pm_size_group->add_widget (_add_input_audio);
116 _pm_size_group->add_widget (_del_input_audio);
117 _pm_size_group->add_widget (_add_input_midi);
118 _pm_size_group->add_widget (_del_input_midi);
120 _pm_size_group->add_widget (_add_plugin);
121 _pm_size_group->add_widget (_del_plugin);
123 _pm_size_group->add_widget (_add_output_audio);
124 _pm_size_group->add_widget (_del_output_audio);
125 _pm_size_group->add_widget (_add_output_midi);
126 _pm_size_group->add_widget (_del_output_midi);
131 VBox* tl = manage (new VBox ());
132 tl->set_border_width (2);
135 VBox* tr = manage (new VBox ());
136 tr->set_border_width (2);
140 tl->pack_start (_set_config, false, false);
142 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
143 box = manage (new HBox ());
144 box->set_border_width (2);
145 box->pack_start (_add_input_audio, true, false);
146 box->pack_start (_del_input_audio, true, false);
147 f = manage (new Frame ());
148 f->set_label (_("Audio Input Pins"));
150 tl->pack_start (*f, false, false);
152 box = manage (new HBox ());
153 box->set_border_width (2);
154 box->pack_start (_add_input_midi, true, false);
155 box->pack_start (_del_input_midi, true, false);
156 f = manage (new Frame ());
157 f->set_label (_("MIDI Input Pins"));
159 tl->pack_start (*f, false, false);
161 box = manage (new HBox ());
162 box->set_border_width (2);
163 box->pack_start (_add_plugin, true, false);
164 box->pack_start (_del_plugin, true, false);
165 f = manage (new Frame ());
166 f->set_label (_("Instances"));
168 tl->pack_start (*f, false, false);
171 box = manage (new HBox ());
172 box->set_border_width (2);
173 box->pack_start (_add_output_audio, true, false);
174 box->pack_start (_del_output_audio, true, false);
175 f = manage (new Frame ());
176 f->set_label (_("Audio Out"));
178 tl->pack_start (*f, false, false);
180 box = manage (new HBox ());
181 box->set_border_width (2);
182 box->pack_start (_add_output_midi, true, false);
183 box->pack_start (_del_output_midi, true, false);
184 f = manage (new Frame ());
185 f->set_label (_("MIDI Out"));
187 tl->pack_start (*f, false, false);
189 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
190 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
191 _out_presets.disable_scrolling ();
192 ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
193 tl->pack_start (_out_presets, false, false);
196 _sidechain_tbl = manage (new Gtk::Table ());
197 _sidechain_tbl->set_spacings (2);
199 tr->pack_start (_tgl_sidechain, false, false);
200 tr->pack_start (*_sidechain_tbl, true, true);
202 box = manage (new VBox ());
203 box->set_border_width (2);
204 box->set_spacing (2);
205 box->pack_start (_add_sc_audio, false, false);
206 box->pack_start (_add_sc_midi , false, false);
207 f = manage (new Frame ());
208 f->set_label (_("Add Sidechain Input"));
211 tr->pack_start (*f, false, false);
214 HBox* hbox = manage (new HBox ());
215 hbox->set_spacing (4);
216 hbox->pack_start (*tl, false, false);
217 hbox->pack_start (darea, true, true);
218 hbox->pack_start (*tr, false, false);
220 pack_start (*hbox, true, true);
221 set_border_width (4);
224 plugin_reconfigured ();
226 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
227 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_request));
228 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_allocate));
229 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_expose_event));
230 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_press_event));
231 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_release_event));
232 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_motion_notify_event));
234 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::toggle_sidechain));
236 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::reset_configuration));
237 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), true));
238 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), false));
240 _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::AUDIO));
241 _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::AUDIO));
242 _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::MIDI));
243 _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::MIDI));
245 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::AUDIO));
246 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::AUDIO));
247 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::MIDI));
248 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::MIDI));
250 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::AUDIO));
251 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::MIDI));
253 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
254 _io_connection, invalidator (*this), boost::bind (&PluginPinWidget::port_connected_or_disconnected, this, _1, _3), gui_context ()
258 PluginPinWidget::~PluginPinWidget ()
260 delete _sidechain_selector;
264 PluginPinWidget::set_session (ARDOUR::Session *s)
266 SessionHandlePtr::set_session (s);
267 plugin_reconfigured ();
271 PluginPinWidget::queue_idle_update ()
273 /* various actions here are directly executed, in the GUI thread,
274 * with the GUI-thread eventually taking the process and processor lock.
275 * "connect gui_context()" will call back immediately and this
276 * signal-handler will run with the locks held.
278 * This will lead to a crash with calling nth_send() which takes
279 * a processor read-lock while holding a write lock in the same thread.
281 * decouple update to GUI idle.
283 * BUT, do delete existing controls here (in case they're affected by
284 * the change and hit by the Timer before idle comes around)
286 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
287 _sidechain_tbl->remove ((*i)->box);
291 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinWidget::idle_update));
295 PluginPinWidget::idle_update ()
297 plugin_reconfigured ();
303 PluginPinWidget::plugin_reconfigured ()
305 ENSURE_GUI_THREAD (*this, &PluginPinWidget::plugin_reconfigured);
306 if (_ignore_updates) {
309 _n_plugins = _pi->get_count ();
310 _pi->configured_io (_in, _out);
311 _ins = _pi->internal_streams (); // with sidechain
312 _sinks = _pi->natural_input_streams ();
313 _sources = _pi->natural_output_streams ();
316 _tgl_sidechain.set_active (_pi->has_sidechain ());
317 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
318 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
320 if (_pi->custom_cfg ()) {
321 _set_config.set_active (true);
322 _add_plugin.set_sensitive (true);
323 _del_plugin.set_sensitive (_n_plugins > 1);
324 _add_output_audio.set_sensitive (true);
325 _add_output_midi.set_sensitive (true);
326 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
327 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
328 _add_input_audio.set_sensitive (true);
329 _add_input_midi.set_sensitive (true);
330 _del_input_audio.set_sensitive (_sinks.n_audio () > 0 && _sinks.n_total () > 1);
331 _del_input_midi.set_sensitive (_sinks.n_midi () > 0 && _sinks.n_total () > 1);
332 _out_presets.set_sensitive (false);
333 _out_presets.set_text (_("Manual"));
335 _set_config.set_active (false);
336 _add_plugin.set_sensitive (false);
337 _del_plugin.set_sensitive (false);
338 _add_input_audio.set_sensitive (false);
339 _add_input_midi.set_sensitive (false);
340 _del_input_audio.set_sensitive (false);
341 _del_input_midi.set_sensitive (false);
342 _add_output_audio.set_sensitive (false);
343 _add_output_midi.set_sensitive (false);
344 _del_output_audio.set_sensitive (false);
345 _del_output_midi.set_sensitive (false);
346 _out_presets.set_sensitive (true);
347 refill_output_presets ();
350 if (!_pi->has_sidechain () && _sidechain_selector) {
351 delete _sidechain_selector;
352 _sidechain_selector = 0;
355 refill_sidechain_table ();
357 /* update elements */
366 _n_inputs = _n_sidechains = 0;
368 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
369 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
370 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
371 bool sidechain = id >= _in.get (dt) ? true : false;
378 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
379 _elements.push_back (cw);
382 for (uint32_t i = 0; i < _out.n_total (); ++i) {
383 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
384 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
390 for (uint32_t n = 0; n < _n_plugins; ++n) {
391 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
392 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
393 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
394 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
395 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
396 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
397 _elements.push_back (cw);
399 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
400 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
401 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
402 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
403 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
405 _in_map[n] = _pi->input_map (n);
406 _out_map[n] = _pi->output_map (n);
408 _has_midi_bypass = _pi->has_midi_bypass ();
409 _thru_map = _pi->thru_map ();
413 /* calc minimum size */
414 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
415 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
416 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
417 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
418 min_width = std::max ((uint32_t)300, min_width);
420 min_width = 50 + 10 * ceilf (min_width / 10.f);
422 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
423 min_height = std::max ((uint32_t)200, min_height);
424 min_height = 4 * ceilf (min_height / 4.f);
426 if (min_width != _min_width || min_height != _min_height) {
427 _min_width = min_width;
428 _min_height = min_height;
429 darea.queue_resize ();
432 _position_valid = false;
437 PluginPinWidget::refill_sidechain_table ()
439 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
440 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
443 _sidechain_tbl->resize (1, 1);
444 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
448 if (!_pi->has_sidechain () && _sidechain_selector) {
451 boost::shared_ptr<IO> io = _pi->sidechain_input ();
457 PortSet& p (io->ports ());
458 bool can_remove = p.num_ports () > 1;
459 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
460 r += add_port_to_table (*i, r, can_remove);
462 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
463 r += add_port_to_table (*i, r, can_remove);
465 _sidechain_tbl->show_all ();
469 PluginPinWidget::refill_output_presets ()
471 using namespace Menu_Helpers;
472 _out_presets.clear_items ();
474 bool need_dropdown = _pi->has_output_presets ();
476 if (!need_dropdown) {
477 _out_presets.set_sensitive (false);
478 _out_presets.set_text (_("Automatic"));
482 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), 0)));
484 const uint32_t n_audio = _pi->preset_out ().n_audio ();
486 _out_presets.set_text (_("Automatic"));
489 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
490 if (ppc.find (0) != ppc.end ()) {
494 ppc.insert (n_audio);
504 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
515 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
518 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), *i)));
520 _out_presets.set_text (tmp);
526 PluginPinWidget::port_label (const std::string& portname, bool strip)
528 // compare to MixerStrip::update_io_button()
529 string lpn (PROGRAM_NAME);
530 boost::to_lower (lpn);
531 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
533 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
535 string::size_type slash = pn.find ("/");
536 if (slash != string::npos) {
537 pn = pn.substr (0, slash);
541 std::string label (portname);
542 if (label.find ("system:capture_") == 0) {
543 if (label.empty ()) {
544 label = portname.substr (15);
546 } else if (label.find ("system:midi_capture_") == 0) {
547 if (label.empty ()) {
548 // "system:midi_capture_123" -> "123"
549 label = "M " + portname.substr (20);
551 } else if (label.find (program_port_prefix) == 0) {
552 label = label.substr (program_port_prefix.size ());
554 string::size_type slash = label.find ("/");
555 if (slash != string::npos) {
556 label = label.substr (0, slash);
564 PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
567 std::string tip = p->name ();
568 std::vector<std::string> cns;
569 bool single_source = true;
570 p->get_connections (cns);
572 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
574 lbl = port_label (*i, true);
577 if (port_label (*i, true) != lbl) {
579 single_source = false;
584 if (cns.size () == 0) {
586 single_source = false;
587 } else if (cns.size () == 1) {
589 lbl = port_label (cns[0], false);
593 replace_all (lbl, "_", " ");
595 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
600 ArdourButton *pb = manage (new ArdourButton (lbl));
601 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
602 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
603 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
604 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
606 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr<Port> (p)), false);
607 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::sc_input_release), false);
609 pb = manage (new ArdourButton ("-"));
610 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
612 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::remove_port), boost::weak_ptr<Port> (p)));
614 pb->set_sensitive (false);
619 if (single_source && _session) {
620 /* check if it's an Ardour Send feeding.. */
621 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
622 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
624 boost::shared_ptr<Processor> proc;
625 /* nth_send () takes a processor read-lock */
626 while ((proc = (*i)->nth_send (nth))) {
627 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
628 if (!send || !send->output ()) {
632 if (!send->output ()->connected_to (p->name ())) {
636 /* if processor goes away, we're notified by the port disconnect,
637 * there should be no need to explicily connect to proc->DropReferences
639 set<Evoral::Parameter> p = proc->what_can_be_automated ();
640 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
641 Control* c = new Control (proc->automation_control (*i), _("Send"));
642 _controls.push_back (c);
644 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
654 PluginPinWidget::update_element_pos ()
657 _innerwidth = _width - 2. * _margin_x;
659 const double yc = rint (_height * .5);
660 const double bxh2 = rint (_margin_y * .45); // TODO grow?
661 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
662 const double bxw2 = rint (bxw * .5);
663 const double y_in = _margin_y;
664 const double y_out = _height - _margin_y;
669 const double dx = _pin_box_size * .5;
672 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
676 i->x = _innerwidth + _margin_x - dx;
677 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
678 i->h = _pin_box_size;
679 i->w = 1.5 * _pin_box_size;
682 uint32_t idx = i->e->id;
683 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
684 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
685 i->w = _pin_box_size;
686 i->h = 1.5 * _pin_box_size;
692 uint32_t idx = i->e->id;
693 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
694 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
696 i->w = _pin_box_size;
697 i->h = 1.5 * _pin_box_size;
702 uint32_t idx = i->e->id;
703 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
704 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
705 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
706 i->y = yc - bxh2 - dx;
707 i->w = _pin_box_size;
708 i->h = _pin_box_size;
713 uint32_t idx = i->e->id;
714 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
715 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
716 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
717 i->y = yc + bxh2 - dx;
718 i->w = _pin_box_size;
719 i->h = _pin_box_size;
727 PluginPinWidget::set_color (cairo_t* cr, bool midi)
729 // see also gtk2_ardour/processor_box.cc
730 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
731 static const uint32_t midi_port_color = 0x960909FF; //Red
734 cairo_set_source_rgb (cr,
735 UINT_RGBA_R_FLT (midi_port_color),
736 UINT_RGBA_G_FLT (midi_port_color),
737 UINT_RGBA_B_FLT (midi_port_color));
739 cairo_set_source_rgb (cr,
740 UINT_RGBA_R_FLT (audio_port_color),
741 UINT_RGBA_G_FLT (audio_port_color),
742 UINT_RGBA_B_FLT (audio_port_color));
747 PluginPinWidget::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
750 const double dy = w.h * .5;
751 const double dx = w.w - dy;
752 cairo_move_to (cr, w.x, w.y + dy);
753 cairo_rel_line_to (cr, dy, -dy);
754 cairo_rel_line_to (cr, dx, 0);
755 cairo_rel_line_to (cr, 0, w.h);
756 cairo_rel_line_to (cr, -dx, 0);
758 const double dir = (w.e->ct == Input) ? 1 : -1;
759 const double dx = w.w * .5;
760 const double dy = w.h - dx;
762 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
763 cairo_rel_line_to (cr, -dx, -dx * dir);
764 cairo_rel_line_to (cr, 0., -dy * dir);
765 cairo_rel_line_to (cr, 2. * dx, 0.);
766 cairo_rel_line_to (cr, 0., dy * dir);
768 cairo_close_path (cr);
770 cairo_set_line_width (cr, 1.0);
771 cairo_set_source_rgb (cr, 0, 0, 0);
772 cairo_stroke_preserve (cr);
774 set_color (cr, w.e->dt == DataType::MIDI);
777 assert (w.e->ct == Input);
778 cairo_fill_preserve (cr);
779 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
782 if (w.e == _selection || w.e == _actor) {
783 cairo_fill_preserve (cr);
784 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
785 } else if (w.prelight) {
786 cairo_fill_preserve (cr);
787 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
793 PluginPinWidget::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
795 const double dx = w.w * .5;
796 const double dy = w.h * .5;
798 cairo_move_to (cr, w.x + dx, w.y);
799 cairo_rel_line_to (cr, -dx, dy);
800 cairo_rel_line_to (cr, dx, dy);
801 cairo_rel_line_to (cr, dx, -dy);
802 cairo_close_path (cr);
804 cairo_set_line_width (cr, 1.0);
805 cairo_set_source_rgb (cr, 0, 0, 0);
806 cairo_stroke_preserve (cr);
808 set_color (cr, w.e->dt == DataType::MIDI);
811 assert (w.e->ct == Sink);
812 cairo_fill_preserve (cr);
813 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
816 if (w.e == _selection || w.e == _actor) {
817 cairo_fill_preserve (cr);
818 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
819 } else if (w.prelight) {
820 cairo_fill_preserve (cr);
821 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
825 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
828 Glib::RefPtr<Pango::Layout> layout;
829 layout = Pango::Layout::create (get_pango_context ());
830 layout->set_text (w.name);
831 layout->get_pixel_size (text_width, text_height);
833 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
834 cairo_set_source_rgba (cr, 0, 0, 0, .5);
837 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
838 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
839 pango_cairo_show_layout (cr, layout->gobj ());
844 PluginPinWidget::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
846 if (!midi) { i += n_midi; }
847 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
850 const PluginPinWidget::CtrlWidget&
851 PluginPinWidget::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
853 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
854 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
859 fatal << string_compose (_("programming error: %1"),
860 X_("Invalid Plugin I/O Port."))
862 abort (); /*NOTREACHED*/
863 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
864 return screw_old_compilers;
868 PluginPinWidget::edge_coordinates (const CtrlWidget& w, double &x, double &y)
896 PluginPinWidget::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
898 const double bz = 2 * _pin_box_size;
899 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
900 if (x0 > _width * .5) { bc *= -1; }
902 cairo_move_to (cr, x0, y0);
904 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
906 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
908 cairo_set_line_width (cr, 3.0);
909 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
910 cairo_set_source_rgb (cr, 1, 0, 0);
912 const double dashes[] = { 5, 7 };
913 cairo_set_dash (cr, dashes, 2, 0);
915 set_color (cr, midi);
918 cairo_set_dash (cr, 0, 0, 0);
923 PluginPinWidget::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
925 double x0, x1, y0, y1;
926 edge_coordinates (w0, x0, y0);
927 edge_coordinates (w1, x1, y1);
928 assert (w0.e->dt == w1.e->dt);
929 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
934 PluginPinWidget::darea_expose_event (GdkEventExpose* ev)
936 Gtk::Allocation a = darea.get_allocation ();
937 double const width = a.get_width ();
938 double const height = a.get_height ();
940 if (!_position_valid) {
943 update_element_pos ();
944 _position_valid = true;
947 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
948 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
951 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
952 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
953 cairo_rectangle (cr, 0, 0, width, height);
956 const double yc = rint (_height * .5);
959 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
960 cairo_set_line_width (cr, 1.0);
961 cairo_set_source_rgb (cr, .1, .1, .3);
962 cairo_stroke_preserve (cr);
963 cairo_set_source_rgb (cr, .3, .3, .3);
967 Glib::RefPtr<Pango::Layout> layout;
968 layout = Pango::Layout::create (get_pango_context ());
970 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
971 layout->set_width (_height * PANGO_SCALE);
976 layout->set_text (_route ()->name ());
977 layout->get_pixel_size (text_width, text_height);
979 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
980 cairo_rotate (cr, M_PI * -.5);
981 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
982 pango_cairo_show_layout (cr, layout->gobj ());
986 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
987 layout->set_text (_pi->name ());
988 layout->get_pixel_size (text_width, text_height);
989 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
990 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
991 pango_cairo_show_layout (cr, layout->gobj ());
994 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
995 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
996 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
997 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
998 } else if (_pi->signal_latency () > 0) {
999 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
1001 layout->set_text (_("no-inplace"));
1003 layout->get_pixel_size (text_width, text_height);
1004 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
1005 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1006 pango_cairo_show_layout (cr, layout->gobj ());
1010 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1011 layout->set_text (_("Strict I/O"));
1012 layout->get_pixel_size (text_width, text_height);
1013 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1014 const double sy0 = _height - 3 - text_height;
1016 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1017 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1020 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1021 cairo_move_to (cr, sx0, sy0);
1022 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1023 pango_cairo_show_layout (cr, layout->gobj ());
1026 /* draw midi-bypass (behind) */
1027 if (_has_midi_bypass) {
1028 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1029 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1030 draw_connection (cr, cw0, cw1, true);
1033 /* thru connections */
1034 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1035 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1036 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1037 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1038 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1039 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1040 draw_connection (cr, cw1, cw0, true);
1045 /* plugins & connection wires */
1046 for (uint32_t i = 0; i < _n_plugins; ++i) {
1047 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1050 cairo_set_source_rgb (cr, .5, .5, .5);
1051 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1054 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1055 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1056 layout->get_pixel_size (text_width, text_height);
1057 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1058 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1059 pango_cairo_show_layout (cr, layout->gobj ());
1061 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1062 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1064 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1065 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1066 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1067 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1068 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1069 draw_connection (cr, cw0, cw1);
1074 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1075 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1076 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1077 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1078 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1079 draw_connection (cr, cw0, cw1);
1085 /* pins and ports */
1086 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1090 draw_io_pin (cr, *i);
1094 draw_plugin_pin (cr, *i);
1100 CtrlWidget *drag_src = NULL;
1102 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1103 if (i->e == _selection ) {
1111 if (_selection->ct == Input || _selection->ct == Source) {
1112 edge_coordinates (*drag_src, x0, y0);
1113 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1114 _selection->dt == DataType::MIDI, _selection->sc);
1116 edge_coordinates (*drag_src, x0, y0);
1117 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1118 _selection->dt == DataType::MIDI, _selection->sc);
1127 PluginPinWidget::darea_size_request (Gtk::Requisition* req)
1129 req->width = _min_width;
1130 req->height = _min_height;
1134 PluginPinWidget::darea_size_allocate (Gtk::Allocation&)
1136 _position_valid = false;
1140 PluginPinWidget::drag_type_matches (const CtrlElem& e)
1142 if (!_dragging || !_selection) {
1145 if (_selection->dt != e->dt) {
1148 if (_selection->ct == Input && e->ct == Sink) { return true; }
1149 if (_selection->ct == Sink && e->ct == Input) { return true; }
1150 if (_selection->ct == Output && e->ct == Source) { return true; }
1151 if (_selection->ct == Source && e->ct == Output) { return true; }
1152 if (_selection->ct == Input && e->ct == Output) { return true; }
1153 if (_selection->ct == Output && e->ct == Input) { return true; }
1158 PluginPinWidget::start_drag (const CtrlElem& e, double x, double y)
1160 assert (_selection == e);
1162 if (e->ct == Sink) {
1164 const ChanMapping& map (_in_map[e->ip]);
1165 uint32_t idx = map.get (e->dt, e->id, &valid);
1167 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1172 else if (e->ct == Output) {
1173 for (uint32_t i = 0; i < _n_plugins; ++i) {
1175 const ChanMapping& map (_out_map[i]);
1176 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1178 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1186 const ChanMapping& map (_thru_map);
1187 uint32_t idx = map.get (e->dt, e->id, &valid);
1189 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1201 PluginPinWidget::darea_motion_notify_event (GdkEventMotion* ev)
1203 bool changed = false;
1205 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1206 if (ev->x >= i->x && ev->x <= i->x + i->w
1207 && ev->y >= i->y && ev->y <= i->y + i->h
1208 && drag_type_matches (i->e))
1210 if (!i->prelight) changed = true;
1214 if (i->prelight) changed = true;
1215 i->prelight = false;
1222 if (changed || _dragging) {
1223 darea.queue_draw ();
1229 PluginPinWidget::darea_button_press_event (GdkEventButton* ev)
1231 if (ev->type != GDK_BUTTON_PRESS) {
1235 switch (ev->button) {
1238 if (!_selection || (_selection && !_hover)) {
1239 _selection = _hover;
1242 start_drag (_selection, ev->x, ev->y);
1244 darea.queue_draw ();
1246 } else if (_selection && _hover && _selection != _hover) {
1247 if (_selection->dt != _hover->dt) { _actor.reset (); }
1248 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1249 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1250 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1251 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1252 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1253 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1255 _selection = _hover;
1256 start_drag (_selection, ev->x, ev->y);
1258 darea.queue_draw ();
1260 } else if (_hover) {
1261 _selection = _hover;
1263 start_drag (_selection, ev->x, ev->y);
1268 if (_selection != _hover) {
1269 _selection = _hover;
1270 darea.queue_draw ();
1282 PluginPinWidget::darea_button_release_event (GdkEventButton* ev)
1284 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1285 // select click. (or re-connect same)
1286 assert (_selection != _hover);
1291 darea.queue_draw ();
1295 if (_dragging && _hover && _hover != _selection) {
1299 if (_hover == _actor && _actor && ev->button == 1) {
1300 assert (_selection);
1301 assert (_selection->dt == _actor->dt);
1303 assert (_dragging && _selection != _drag_dst);
1304 handle_disconnect (_drag_dst, true);
1306 if (_selection->ct == Input && _actor->ct == Sink) {
1307 handle_input_action (_actor, _selection);
1309 else if (_selection->ct == Sink && _actor->ct == Input) {
1310 handle_input_action (_selection, _actor);
1312 else if (_selection->ct == Output && _actor->ct == Source) {
1313 handle_output_action (_actor, _selection);
1315 else if (_selection->ct == Source && _actor->ct == Output) {
1316 handle_output_action (_selection, _actor);
1318 else if (_selection->ct == Input && _actor->ct == Output) {
1319 handle_thru_action (_actor, _selection);
1321 else if (_selection->ct == Output && _actor->ct == Input) {
1322 handle_thru_action (_selection, _actor);
1324 _selection.reset ();
1325 } else if (_hover == _selection && _selection && ev->button == 3) {
1326 handle_disconnect (_selection);
1327 } else if (!_hover && ev->button == 3) {
1328 reset_menu.popup (1, ev->time);
1331 if (_dragging && _hover != _selection) {
1332 _selection.reset ();
1337 darea.queue_draw ();
1342 PluginPinWidget::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1344 const int pc = s->ip;
1346 ChanMapping in_map (_pi->input_map (pc));
1347 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1349 if (valid && idx == i->id) {
1352 in_map.unset (s->dt, s->id);
1353 _pi->set_input_map (pc, in_map);
1355 plugin_reconfigured ();
1360 in_map.set (s->dt, s->id, i->id);
1361 _pi->set_input_map (pc, in_map);
1365 in_map.unset (s->dt, s->id);
1366 in_map.set (s->dt, s->id, i->id);
1367 _pi->set_input_map (pc, in_map);
1372 PluginPinWidget::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1374 _ignore_updates = true;
1375 for (uint32_t n = 0; n < _n_plugins; ++n) {
1380 ChanMapping n_out_map (_pi->output_map (n));
1381 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1383 n_out_map.unset (dt, idx);
1384 _pi->set_output_map (n, n_out_map);
1387 _ignore_updates = false;
1391 PluginPinWidget::disconnect_other_thru (DataType dt, uint32_t id)
1393 _ignore_updates = true;
1395 ChanMapping n_thru_map (_pi->thru_map ());
1396 n_thru_map.get (dt, id, &valid);
1398 n_thru_map.unset (dt, id);
1399 _pi->set_thru_map (n_thru_map);
1401 _ignore_updates = false;
1405 PluginPinWidget::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1407 const uint32_t pc = s->ip;
1409 ChanMapping out_map (_pi->output_map (pc));
1410 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1412 if (valid && idx == o->id) {
1415 out_map.unset (s->dt, s->id);
1416 _pi->set_output_map (pc, out_map);
1418 plugin_reconfigured ();
1422 // disconnect source
1423 disconnect_other_outputs (pc, s->dt, o->id);
1424 disconnect_other_thru (s->dt, o->id);
1425 out_map = _pi->output_map (pc); // re-read map
1427 out_map.unset (s->dt, s->id);
1429 idx = out_map.get_src (s->dt, o->id, &valid);
1431 out_map.unset (s->dt, idx);
1434 out_map.set (s->dt, s->id, o->id);
1435 _pi->set_output_map (pc, out_map);
1440 PluginPinWidget::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1443 ChanMapping thru_map (_pi->thru_map ());
1444 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1446 if (valid && idx == i->id) {
1448 thru_map.unset (o->dt, o->id);
1451 // disconnect other outputs first
1452 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1453 disconnect_other_thru (o->dt, o->id);
1454 thru_map = _pi->thru_map (); // re-read map
1456 thru_map.set (o->dt, o->id, i->id);
1458 _pi->set_thru_map (thru_map);
1462 PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal)
1464 _ignore_updates = true;
1465 bool changed = false;
1471 ChanMapping n_thru_map (_pi->thru_map ());
1472 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1473 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1474 if (valid && idx == e->id) {
1475 n_thru_map.unset (e->dt, i);
1480 _pi->set_thru_map (n_thru_map);
1483 for (uint32_t n = 0; n < _n_plugins; ++n) {
1484 ChanMapping map (_pi->input_map (n));
1485 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1486 uint32_t idx = map.get (e->dt, i, &valid);
1487 if (valid && idx == e->id) {
1488 map.unset (e->dt, i);
1492 _pi->set_input_map (n, map);
1497 ChanMapping map (_pi->input_map (e->ip));
1498 map.get (e->dt, e->id, &valid);
1500 map.unset (e->dt, e->id);
1501 _pi->set_input_map (e->ip, map);
1508 ChanMapping map (_pi->output_map (e->ip));
1509 map.get (e->dt, e->id, &valid);
1511 map.unset (e->dt, e->id);
1512 _pi->set_output_map (e->ip, map);
1518 for (uint32_t n = 0; n < _n_plugins; ++n) {
1519 ChanMapping map (_pi->output_map (n));
1520 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1521 uint32_t idx = map.get (e->dt, i, &valid);
1522 if (valid && idx == e->id) {
1523 map.unset (e->dt, i);
1528 _pi->set_output_map (n, map);
1532 ChanMapping n_thru_map (_pi->thru_map ());
1533 n_thru_map.get (e->dt, e->id, &valid);
1535 n_thru_map.unset (e->dt, e->id);
1537 _pi->set_thru_map (n_thru_map);
1542 _ignore_updates = false;
1543 if (changed && !no_signal) {
1544 plugin_reconfigured ();
1550 PluginPinWidget::toggle_sidechain ()
1552 if (_session && _session->actively_recording ()) { return; }
1553 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1557 PluginPinWidget::connect_sidechain ()
1559 if (!_session) { return; }
1561 if (_sidechain_selector == 0) {
1562 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1565 if (_sidechain_selector->is_visible ()) {
1566 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1568 _sidechain_selector->present ();
1573 PluginPinWidget::reset_configuration ()
1575 if (_set_config.get_active ()) {
1576 _route ()->reset_plugin_insert (_pi);
1578 _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
1583 PluginPinWidget::reset_mapping ()
1589 PluginPinWidget::select_output_preset (uint32_t n_audio)
1591 if (_session && _session->actively_recording ()) { return; }
1592 ChanCount out (DataType::AUDIO, n_audio);
1593 _route ()->plugin_preset_output (_pi, out);
1597 PluginPinWidget::add_remove_plugin_clicked (bool add)
1599 if (_session && _session->actively_recording ()) { return; }
1600 ChanCount out = _out;
1601 ChanCount sinks = _sinks;
1602 assert (add || _n_plugins > 0);
1603 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks);
1607 PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1609 if (_session && _session->actively_recording ()) { return; }
1610 ChanCount out = _out;
1611 ChanCount sinks = _sinks;
1612 assert (add || out.get (dt) > 0);
1613 out.set (dt, out.get (dt) + (add ? 1 : -1));
1614 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1618 PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
1620 if (_session && _session->actively_recording ()) { return; }
1621 ChanCount out = _out;
1622 ChanCount sinks = _sinks;
1623 assert (add || sinks.get (dt) > 0);
1624 sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
1625 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1629 PluginPinWidget::add_sidechain_port (DataType dt)
1631 if (_session && _session->actively_recording ()) { return; }
1632 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1637 // this triggers a PluginIoReConfigure with process and processor write lock held
1638 // from /this/ thread.
1639 io->add_port ("", this, dt);
1643 PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1645 if (_session && _session->actively_recording ()) { return; }
1646 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1647 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1651 io->remove_port (p, this);
1655 PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1657 if (_session && _session->actively_recording ()) { return; }
1658 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1659 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1663 p->disconnect_all ();
1667 PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1669 if (_session && _session->actively_recording ()) { return; }
1670 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1671 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1672 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1673 if (!io || !p0 || !p1) {
1676 _ignore_updates = true;
1677 p0->disconnect_all ();
1678 _ignore_updates = false;
1679 p0->connect (p1->name ());
1683 PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1685 if (_session && _session->actively_recording ()) { return; }
1686 boost::shared_ptr<Port> p = wp.lock ();
1687 boost::shared_ptr<Route> r = wr.lock ();
1688 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1689 if (!p || !r || !io || !_session) {
1693 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1694 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1695 const ChanCount& outs (r->amp ()->input_streams ());
1697 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1698 send->output()->ensure_io (outs, false, this);
1699 } catch (AudioEngine::PortRegistrationFailure& err) {
1700 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1704 std::string sendname = send->name ();
1705 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1706 if (last_letter != string::npos) {
1707 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1709 sendname.substr (last_letter + 1)));
1712 _ignore_updates = true;
1713 p->disconnect_all ();
1715 DataType dt = p->type ();
1716 PortSet& ps (send->output ()->ports ());
1717 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1718 p->connect (&(**i));
1721 send->set_remove_on_disconnect (true);
1722 r->add_processor (send, PreFader);
1723 _ignore_updates = false;
1724 queue_idle_update ();
1728 PluginPinWidget::sc_input_release (GdkEventButton *ev)
1730 if (_session && _session->actively_recording ()) { return false; }
1731 if (ev->button == 3) {
1732 connect_sidechain ();
1737 struct RouteCompareByName {
1738 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1739 return a->name ().compare (b->name ()) < 0;
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 (RouteCompareByName ());
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 (MenuElem (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 smallstep = desc.smallstep;
1870 double largestep = desc.largestep;
1872 if (smallstep == 0.0) {
1873 smallstep = up / 1000.;
1875 smallstep = c->internal_to_interface (desc.lower + smallstep);
1878 if (largestep == 0.0) {
1879 largestep = up / 40.;
1881 largestep = c->internal_to_interface (desc.lower + largestep);
1884 _adjustment.set_lower (lo);
1885 _adjustment.set_upper (up);
1886 _adjustment.set_step_increment (smallstep);
1887 _adjustment.set_page_increment (largestep);
1888 _slider.set_default_value (normal);
1890 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1891 // dup. currently timers are used :(
1892 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1894 // yuck, do we really need to do this?
1895 // according to c404374 this is only needed for send automation
1896 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1901 /* We're providing our own PersistentTooltip */
1902 set_no_tooltip_whatsoever (_slider);
1905 PluginPinWidget::Control::~Control ()
1907 timer_connection.disconnect ();
1911 PluginPinWidget::Control::set_tooltip ()
1913 boost::shared_ptr<AutomationControl> c = _control.lock ();
1918 snprintf (tmp, sizeof (tmp), "%s: %.2f", _name.c_str (), c->internal_to_user (c->get_value ()));
1920 string sm = Gtkmm2ext::markup_escape_text (tmp);
1921 _slider_persistant_tooltip.set_tip (sm);
1925 PluginPinWidget::Control::slider_adjusted ()
1927 if (_ignore_ui_adjustment) {
1930 boost::shared_ptr<AutomationControl> c = _control.lock ();
1934 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1940 PluginPinWidget::Control::control_changed ()
1942 boost::shared_ptr<AutomationControl> c = _control.lock ();
1947 _ignore_ui_adjustment = true;
1949 // as long as rapid timers are used, only update the tooltip
1950 // if the value has changed.
1951 const double nval = c->internal_to_interface (c->get_value ());
1952 if (_adjustment.get_value () != nval) {
1953 _adjustment.set_value (nval);
1957 _ignore_ui_adjustment = false;
1962 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
1963 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
1965 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
1970 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
1971 : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
1974 vbox = manage (new VBox ());
1978 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
1980 _route->processors_changed.connect (
1981 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context()
1984 _route->DropReferences.connect (
1985 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context()
1989 PluginPinDialog::set_session (ARDOUR::Session *s)
1991 SessionHandlePtr::set_session (s);
1992 for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) {
1993 (*i)->set_session (s);
1998 PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
2002 vbox = manage (new VBox ());
2005 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2009 PluginPinDialog::route_going_away ()
2017 PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
2019 boost::shared_ptr<Processor> proc = p.lock ();
2020 if (!proc || !proc->display_to_user ()) {
2023 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
2025 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
2026 vbox->pack_start (*ppw.back());
2028 HBox* hbox = manage (new HBox ());
2029 hbox->pack_start (*manage (new HSeparator ()));
2030 hbox->pack_start (*manage (new Label (proc->display_name ())));
2031 hbox->pack_start (*manage (new HSeparator ()));
2032 vbox->pack_start (*hbox);