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 "widgets/tooltips.h"
34 #include "ardour/amp.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/pannable.h"
37 #include "ardour/plugin.h"
38 #include "ardour/port.h"
39 #include "ardour/profile.h"
40 #include "ardour/send.h"
41 #include "ardour/session.h"
42 #include "ardour/value_as_string.h"
44 #include "plugin_pin_dialog.h"
45 #include "gui_thread.h"
47 #include "ui_config.h"
51 using namespace ARDOUR;
55 using namespace Gtkmm2ext;
56 using namespace ArdourWidgets;
58 PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
59 : _set_config (_("Manual Config"), ArdourButton::led_default_elements)
60 , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements)
61 , _add_plugin (_("+"))
62 , _del_plugin (_("-"))
63 , _add_input_audio (_("+"))
64 , _del_input_audio (_("-"))
65 , _add_input_midi (_("+"))
66 , _del_input_midi (_("-"))
67 , _add_output_audio (_("+"))
68 , _del_output_audio (_("-"))
69 , _add_output_midi (_("+"))
70 , _del_output_midi (_("-"))
71 , _add_sc_audio (_("Audio"))
72 , _add_sc_midi (_("MIDI"))
84 , _position_valid (false)
85 , _ignore_updates (false)
86 , _sidechain_selector (0)
89 assert (pi->owner ()); // Route
91 _pi->PluginIoReConfigure.connect (
92 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
95 _pi->PluginMapChanged.connect (
96 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
99 _pi->PluginConfigChanged.connect (
100 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
103 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
104 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
105 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
107 _tgl_sidechain.set_name ("pinrouting sidechain");
108 _set_config.set_name ("pinrouting custom");
110 Menu_Helpers::MenuList& citems = reset_menu.items ();
111 reset_menu.set_name ("ArdourContextMenu");
113 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinWidget::reset_mapping)));
115 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
116 _add_plugin.set_tweaks (ArdourButton::Square);
117 _del_plugin.set_tweaks (ArdourButton::Square);
118 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
119 _pm_size_group->add_widget (_add_input_audio);
120 _pm_size_group->add_widget (_del_input_audio);
121 _pm_size_group->add_widget (_add_input_midi);
122 _pm_size_group->add_widget (_del_input_midi);
124 _pm_size_group->add_widget (_add_plugin);
125 _pm_size_group->add_widget (_del_plugin);
127 _pm_size_group->add_widget (_add_output_audio);
128 _pm_size_group->add_widget (_del_output_audio);
129 _pm_size_group->add_widget (_add_output_midi);
130 _pm_size_group->add_widget (_del_output_midi);
135 VBox* tl = manage (new VBox ());
136 tl->set_border_width (2);
139 VBox* tr = manage (new VBox ());
140 tr->set_border_width (2);
144 tl->pack_start (_set_config, false, false);
146 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
147 box = manage (new HBox ());
148 box->set_border_width (2);
149 box->pack_start (_add_input_audio, true, false);
150 box->pack_start (_del_input_audio, true, false);
151 f = manage (new Frame ());
152 f->set_label (_("Audio Input Pins"));
154 tl->pack_start (*f, false, false);
156 box = manage (new HBox ());
157 box->set_border_width (2);
158 box->pack_start (_add_input_midi, true, false);
159 box->pack_start (_del_input_midi, true, false);
160 f = manage (new Frame ());
161 f->set_label (_("MIDI Input Pins"));
163 tl->pack_start (*f, false, false);
165 box = manage (new HBox ());
166 box->set_border_width (2);
167 box->pack_start (_add_plugin, true, false);
168 box->pack_start (_del_plugin, true, false);
169 f = manage (new Frame ());
170 f->set_label (_("Instances"));
172 tl->pack_start (*f, false, false);
175 box = manage (new HBox ());
176 box->set_border_width (2);
177 box->pack_start (_add_output_audio, true, false);
178 box->pack_start (_del_output_audio, true, false);
179 f = manage (new Frame ());
180 f->set_label (_("Audio Out"));
182 tl->pack_start (*f, false, false);
184 box = manage (new HBox ());
185 box->set_border_width (2);
186 box->pack_start (_add_output_midi, true, false);
187 box->pack_start (_del_output_midi, true, false);
188 f = manage (new Frame ());
189 f->set_label (_("MIDI Out"));
191 tl->pack_start (*f, false, false);
193 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
194 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
195 _out_presets.disable_scrolling ();
196 ArdourWidgets::set_tooltip (_out_presets, _("Output Presets"));
197 tl->pack_start (_out_presets, false, false);
200 _sidechain_tbl = manage (new Gtk::Table ());
201 _sidechain_tbl->set_spacings (2);
203 tr->pack_start (_tgl_sidechain, false, false);
204 tr->pack_start (*_sidechain_tbl, true, true);
206 box = manage (new VBox ());
207 box->set_border_width (2);
208 box->set_spacing (2);
209 box->pack_start (_add_sc_audio, false, false);
210 box->pack_start (_add_sc_midi , false, false);
211 f = manage (new Frame ());
212 f->set_label (_("Add Sidechain Input"));
215 tr->pack_start (*f, false, false);
218 HBox* hbox = manage (new HBox ());
219 hbox->set_spacing (4);
220 hbox->pack_start (*tl, false, false);
221 hbox->pack_start (darea, true, true);
222 hbox->pack_start (*tr, false, false);
224 pack_start (*hbox, true, true);
225 set_border_width (4);
228 plugin_reconfigured ();
230 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
231 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_request));
232 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_allocate));
233 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_expose_event));
234 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_press_event));
235 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_release_event));
236 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_motion_notify_event));
238 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::toggle_sidechain));
240 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::reset_configuration));
241 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), true));
242 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), false));
244 _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::AUDIO));
245 _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::AUDIO));
246 _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::MIDI));
247 _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::MIDI));
249 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::AUDIO));
250 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::AUDIO));
251 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::MIDI));
252 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::MIDI));
254 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::AUDIO));
255 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::MIDI));
257 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
258 _io_connection, invalidator (*this), boost::bind (&PluginPinWidget::port_connected_or_disconnected, this, _1, _3), gui_context ()
262 PluginPinWidget::~PluginPinWidget ()
264 delete _sidechain_selector;
268 PluginPinWidget::set_session (ARDOUR::Session *s)
270 SessionHandlePtr::set_session (s);
271 plugin_reconfigured ();
275 PluginPinWidget::queue_idle_update ()
277 /* various actions here are directly executed, in the GUI thread,
278 * with the GUI-thread eventually taking the process and processor lock.
279 * "connect gui_context()" will call back immediately and this
280 * signal-handler will run with the locks held.
282 * This will lead to a crash with calling nth_send() which takes
283 * a processor read-lock while holding a write lock in the same thread.
285 * decouple update to GUI idle.
287 * BUT, do delete existing controls here (in case they're affected by
288 * the change and hit by the Timer before idle comes around)
290 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
291 _sidechain_tbl->remove ((*i)->box);
295 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinWidget::idle_update));
299 PluginPinWidget::idle_update ()
301 plugin_reconfigured ();
307 PluginPinWidget::plugin_reconfigured ()
309 ENSURE_GUI_THREAD (*this, &PluginPinWidget::plugin_reconfigured);
310 if (_ignore_updates) {
313 _n_plugins = _pi->get_count ();
314 _pi->configured_io (_in, _out);
315 _ins = _pi->internal_streams (); // with sidechain
316 _sinks = _pi->natural_input_streams ();
317 _sources = _pi->natural_output_streams ();
320 _tgl_sidechain.set_active (_pi->has_sidechain ());
321 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
322 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
324 if (_pi->custom_cfg ()) {
325 _set_config.set_active (true);
326 _add_plugin.set_sensitive (true);
327 _del_plugin.set_sensitive (_n_plugins > 1);
328 _add_output_audio.set_sensitive (true);
329 _add_output_midi.set_sensitive (true);
330 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
331 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
332 _add_input_audio.set_sensitive (true);
333 _add_input_midi.set_sensitive (true);
334 _del_input_audio.set_sensitive (_sinks.n_audio () > 0 && _sinks.n_total () > 1);
335 _del_input_midi.set_sensitive (_sinks.n_midi () > 0 && _sinks.n_total () > 1);
336 _out_presets.set_sensitive (false);
337 _out_presets.set_text (_("Manual"));
339 _set_config.set_active (false);
340 _add_plugin.set_sensitive (false);
341 _del_plugin.set_sensitive (false);
342 _add_input_audio.set_sensitive (false);
343 _add_input_midi.set_sensitive (false);
344 _del_input_audio.set_sensitive (false);
345 _del_input_midi.set_sensitive (false);
346 _add_output_audio.set_sensitive (false);
347 _add_output_midi.set_sensitive (false);
348 _del_output_audio.set_sensitive (false);
349 _del_output_midi.set_sensitive (false);
350 _out_presets.set_sensitive (true);
351 refill_output_presets ();
354 if (!_pi->has_sidechain () && _sidechain_selector) {
355 delete _sidechain_selector;
356 _sidechain_selector = 0;
359 refill_sidechain_table ();
361 /* update elements */
370 _n_inputs = _n_sidechains = 0;
372 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
373 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
374 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
375 bool sidechain = id >= _in.get (dt) ? true : false;
382 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
383 _elements.push_back (cw);
386 for (uint32_t i = 0; i < _out.n_total (); ++i) {
387 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
388 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
394 for (uint32_t n = 0; n < _n_plugins; ++n) {
395 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
396 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
397 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
398 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
399 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
400 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
401 _elements.push_back (cw);
403 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
404 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
405 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
406 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
407 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
409 _in_map[n] = _pi->input_map (n);
410 _out_map[n] = _pi->output_map (n);
412 _has_midi_bypass = _pi->has_midi_bypass ();
413 _thru_map = _pi->thru_map ();
417 /* calc minimum size */
418 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
419 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
420 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
421 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
422 min_width = std::max ((uint32_t)300, min_width);
424 min_width = 50 + 10 * ceilf (min_width / 10.f);
426 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
427 min_height = std::max ((uint32_t)200, min_height);
428 min_height = 4 * ceilf (min_height / 4.f);
430 if (min_width != _min_width || min_height != _min_height) {
431 _min_width = min_width;
432 _min_height = min_height;
433 darea.queue_resize ();
436 _position_valid = false;
441 PluginPinWidget::refill_sidechain_table ()
443 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
444 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
447 _sidechain_tbl->resize (1, 1);
448 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
452 if (!_pi->has_sidechain () && _sidechain_selector) {
455 boost::shared_ptr<IO> io = _pi->sidechain_input ();
461 PortSet& p (io->ports ());
462 bool can_remove = p.num_ports () > 1;
463 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
464 r += add_port_to_table (*i, r, can_remove);
466 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
467 r += add_port_to_table (*i, r, can_remove);
469 _sidechain_tbl->show_all ();
473 PluginPinWidget::refill_output_presets ()
475 using namespace Menu_Helpers;
476 _out_presets.clear_items ();
478 bool need_dropdown = _pi->has_output_presets ();
480 if (!need_dropdown) {
481 _out_presets.set_sensitive (false);
482 _out_presets.set_text (_("Automatic"));
486 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), 0)));
488 const uint32_t n_audio = _pi->preset_out ().n_audio ();
490 _out_presets.set_text (_("Automatic"));
493 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
494 if (ppc.find (0) != ppc.end ()) {
498 ppc.insert (n_audio);
508 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
519 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
522 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), *i)));
524 _out_presets.set_text (tmp);
530 PluginPinWidget::port_label (const std::string& portname, bool strip)
532 // compare to MixerStrip::update_io_button()
533 string lpn (PROGRAM_NAME);
534 boost::to_lower (lpn);
535 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
537 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
539 string::size_type slash = pn.find ("/");
540 if (slash != string::npos) {
541 pn = pn.substr (0, slash);
545 std::string label (portname);
546 if (label.find ("system:capture_") == 0) {
547 if (label.empty ()) {
548 label = portname.substr (15);
550 } else if (label.find ("system:midi_capture_") == 0) {
551 if (label.empty ()) {
552 // "system:midi_capture_123" -> "123"
553 label = "M " + portname.substr (20);
555 } else if (label.find (program_port_prefix) == 0) {
556 label = label.substr (program_port_prefix.size ());
558 string::size_type slash = label.find ("/");
559 if (slash != string::npos) {
560 label = label.substr (0, slash);
568 PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
571 std::string tip = p->name ();
572 std::vector<std::string> cns;
573 bool single_source = true;
574 p->get_connections (cns);
576 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
578 lbl = port_label (*i, true);
581 if (port_label (*i, true) != lbl) {
583 single_source = false;
588 if (cns.size () == 0) {
590 single_source = false;
591 } else if (cns.size () == 1) {
593 lbl = port_label (cns[0], false);
597 replace_all (lbl, "_", " ");
599 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
604 ArdourButton *pb = manage (new ArdourButton (lbl));
605 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
606 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
607 ArdourWidgets::set_tooltip (*pb, tip);
608 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
610 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr<Port> (p)), false);
611 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::sc_input_release), false);
613 pb = manage (new ArdourButton ("-"));
614 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
616 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::remove_port), boost::weak_ptr<Port> (p)));
618 pb->set_sensitive (false);
623 if (single_source && _session) {
624 /* check if it's an Ardour Send feeding.. */
625 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
626 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
628 boost::shared_ptr<Processor> proc;
629 /* nth_send () takes a processor read-lock */
630 while ((proc = (*i)->nth_send (nth))) {
631 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
632 if (!send || !send->output ()) {
636 if (!send->output ()->connected_to (p->name ())) {
640 /* if processor goes away, we're notified by the port disconnect,
641 * there should be no need to explicily connect to proc->DropReferences
643 set<Evoral::Parameter> p = proc->what_can_be_automated ();
644 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
645 Control* c = new Control (proc->automation_control (*i), _("Send"));
646 _controls.push_back (c);
648 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
658 PluginPinWidget::update_element_pos ()
661 _innerwidth = _width - 2. * _margin_x;
663 const double yc = rint (_height * .5);
664 const double bxh2 = rint (_margin_y * .45); // TODO grow?
665 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
666 const double bxw2 = rint (bxw * .5);
667 const double y_in = _margin_y;
668 const double y_out = _height - _margin_y;
673 const double dx = _pin_box_size * .5;
676 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
680 i->x = _innerwidth + _margin_x - dx;
681 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
682 i->h = _pin_box_size;
683 i->w = 1.5 * _pin_box_size;
686 uint32_t idx = i->e->id;
687 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
688 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
689 i->w = _pin_box_size;
690 i->h = 1.5 * _pin_box_size;
696 uint32_t idx = i->e->id;
697 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
698 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
700 i->w = _pin_box_size;
701 i->h = 1.5 * _pin_box_size;
706 uint32_t idx = i->e->id;
707 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
708 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
709 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
710 i->y = yc - bxh2 - dx;
711 i->w = _pin_box_size;
712 i->h = _pin_box_size;
717 uint32_t idx = i->e->id;
718 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
719 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
720 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
721 i->y = yc + bxh2 - dx;
722 i->w = _pin_box_size;
723 i->h = _pin_box_size;
731 PluginPinWidget::set_color (cairo_t* cr, bool midi)
733 // see also gtk2_ardour/processor_box.cc
734 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
735 static const uint32_t midi_port_color = 0x960909FF; //Red
738 cairo_set_source_rgb (cr,
739 UINT_RGBA_R_FLT (midi_port_color),
740 UINT_RGBA_G_FLT (midi_port_color),
741 UINT_RGBA_B_FLT (midi_port_color));
743 cairo_set_source_rgb (cr,
744 UINT_RGBA_R_FLT (audio_port_color),
745 UINT_RGBA_G_FLT (audio_port_color),
746 UINT_RGBA_B_FLT (audio_port_color));
751 PluginPinWidget::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
754 const double dy = w.h * .5;
755 const double dx = w.w - dy;
756 cairo_move_to (cr, w.x, w.y + dy);
757 cairo_rel_line_to (cr, dy, -dy);
758 cairo_rel_line_to (cr, dx, 0);
759 cairo_rel_line_to (cr, 0, w.h);
760 cairo_rel_line_to (cr, -dx, 0);
762 const double dir = (w.e->ct == Input) ? 1 : -1;
763 const double dx = w.w * .5;
764 const double dy = w.h - dx;
766 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
767 cairo_rel_line_to (cr, -dx, -dx * dir);
768 cairo_rel_line_to (cr, 0., -dy * dir);
769 cairo_rel_line_to (cr, 2. * dx, 0.);
770 cairo_rel_line_to (cr, 0., dy * dir);
772 cairo_close_path (cr);
774 cairo_set_line_width (cr, 1.0);
775 cairo_set_source_rgb (cr, 0, 0, 0);
776 cairo_stroke_preserve (cr);
778 set_color (cr, w.e->dt == DataType::MIDI);
781 assert (w.e->ct == Input);
782 cairo_fill_preserve (cr);
783 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
786 if (w.e == _selection || w.e == _actor) {
787 cairo_fill_preserve (cr);
788 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
789 } else if (w.prelight) {
790 cairo_fill_preserve (cr);
791 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
797 PluginPinWidget::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
799 const double dx = w.w * .5;
800 const double dy = w.h * .5;
802 cairo_move_to (cr, w.x + dx, w.y);
803 cairo_rel_line_to (cr, -dx, dy);
804 cairo_rel_line_to (cr, dx, dy);
805 cairo_rel_line_to (cr, dx, -dy);
806 cairo_close_path (cr);
808 cairo_set_line_width (cr, 1.0);
809 cairo_set_source_rgb (cr, 0, 0, 0);
810 cairo_stroke_preserve (cr);
812 set_color (cr, w.e->dt == DataType::MIDI);
815 assert (w.e->ct == Sink);
816 cairo_fill_preserve (cr);
817 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
820 if (w.e == _selection || w.e == _actor) {
821 cairo_fill_preserve (cr);
822 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
823 } else if (w.prelight) {
824 cairo_fill_preserve (cr);
825 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
829 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
832 Glib::RefPtr<Pango::Layout> layout;
833 layout = Pango::Layout::create (get_pango_context ());
834 layout->set_text (w.name);
835 layout->get_pixel_size (text_width, text_height);
837 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
838 cairo_set_source_rgba (cr, 0, 0, 0, .5);
841 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
842 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
843 pango_cairo_show_layout (cr, layout->gobj ());
848 PluginPinWidget::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
850 if (!midi) { i += n_midi; }
851 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
854 const PluginPinWidget::CtrlWidget&
855 PluginPinWidget::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
857 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
858 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
863 fatal << string_compose (_("programming error: %1"),
864 X_("Invalid Plugin I/O Port."))
866 abort (); /*NOTREACHED*/
867 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
868 return screw_old_compilers;
872 PluginPinWidget::edge_coordinates (const CtrlWidget& w, double &x, double &y)
900 PluginPinWidget::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
902 const double bz = 2 * _pin_box_size;
903 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
904 if (x0 > _width * .5) { bc *= -1; }
906 cairo_move_to (cr, x0, y0);
908 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
910 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
912 cairo_set_line_width (cr, 3.0);
913 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
914 cairo_set_source_rgb (cr, 1, 0, 0);
916 const double dashes[] = { 5, 7 };
917 cairo_set_dash (cr, dashes, 2, 0);
919 set_color (cr, midi);
922 cairo_set_dash (cr, 0, 0, 0);
927 PluginPinWidget::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
929 double x0, x1, y0, y1;
930 edge_coordinates (w0, x0, y0);
931 edge_coordinates (w1, x1, y1);
932 assert (w0.e->dt == w1.e->dt);
933 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
938 PluginPinWidget::darea_expose_event (GdkEventExpose* ev)
940 Gtk::Allocation a = darea.get_allocation ();
941 double const width = a.get_width ();
942 double const height = a.get_height ();
944 if (!_position_valid) {
947 update_element_pos ();
948 _position_valid = true;
951 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
952 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
955 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
956 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
957 cairo_rectangle (cr, 0, 0, width, height);
960 const double yc = rint (_height * .5);
963 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
964 cairo_set_line_width (cr, 1.0);
965 cairo_set_source_rgb (cr, .1, .1, .3);
966 cairo_stroke_preserve (cr);
967 cairo_set_source_rgb (cr, .3, .3, .3);
971 Glib::RefPtr<Pango::Layout> layout;
972 layout = Pango::Layout::create (get_pango_context ());
974 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
975 layout->set_width (_height * PANGO_SCALE);
980 layout->set_text (_route ()->name ());
981 layout->get_pixel_size (text_width, text_height);
983 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
984 cairo_rotate (cr, M_PI * -.5);
985 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
986 pango_cairo_show_layout (cr, layout->gobj ());
990 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
991 layout->set_text (_pi->name ());
992 layout->get_pixel_size (text_width, text_height);
993 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
994 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
995 pango_cairo_show_layout (cr, layout->gobj ());
998 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
999 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
1000 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
1001 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
1002 } else if (_pi->signal_latency () > 0) {
1003 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
1005 layout->set_text (_("no-inplace"));
1007 layout->get_pixel_size (text_width, text_height);
1008 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
1009 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1010 pango_cairo_show_layout (cr, layout->gobj ());
1014 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1015 layout->set_text (_("Strict I/O"));
1016 layout->get_pixel_size (text_width, text_height);
1017 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1018 const double sy0 = _height - 3 - text_height;
1020 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1021 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1024 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1025 cairo_move_to (cr, sx0, sy0);
1026 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1027 pango_cairo_show_layout (cr, layout->gobj ());
1030 /* draw midi-bypass (behind) */
1031 if (_has_midi_bypass) {
1032 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1033 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1034 draw_connection (cr, cw0, cw1, true);
1037 /* thru connections */
1038 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1039 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1040 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1041 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1042 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1043 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1044 draw_connection (cr, cw1, cw0, true);
1049 /* plugins & connection wires */
1050 for (uint32_t i = 0; i < _n_plugins; ++i) {
1051 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1054 cairo_set_source_rgb (cr, .5, .5, .5);
1055 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1058 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1059 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1060 layout->get_pixel_size (text_width, text_height);
1061 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1062 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1063 pango_cairo_show_layout (cr, layout->gobj ());
1065 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1066 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1068 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1069 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1070 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1071 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1072 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1073 draw_connection (cr, cw0, cw1);
1078 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1079 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1080 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1081 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1082 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1083 draw_connection (cr, cw0, cw1);
1089 /* pins and ports */
1090 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1094 draw_io_pin (cr, *i);
1098 draw_plugin_pin (cr, *i);
1104 CtrlWidget *drag_src = NULL;
1106 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1107 if (i->e == _selection ) {
1115 if (_selection->ct == Input || _selection->ct == Source) {
1116 edge_coordinates (*drag_src, x0, y0);
1117 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1118 _selection->dt == DataType::MIDI, _selection->sc);
1120 edge_coordinates (*drag_src, x0, y0);
1121 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1122 _selection->dt == DataType::MIDI, _selection->sc);
1131 PluginPinWidget::darea_size_request (Gtk::Requisition* req)
1133 req->width = _min_width;
1134 req->height = _min_height;
1138 PluginPinWidget::darea_size_allocate (Gtk::Allocation&)
1140 _position_valid = false;
1144 PluginPinWidget::drag_type_matches (const CtrlElem& e)
1146 if (!_dragging || !_selection) {
1149 if (_selection->dt != e->dt) {
1152 if (_selection->ct == Input && e->ct == Sink) { return true; }
1153 if (_selection->ct == Sink && e->ct == Input) { return true; }
1154 if (_selection->ct == Output && e->ct == Source) { return true; }
1155 if (_selection->ct == Source && e->ct == Output) { return true; }
1156 if (_selection->ct == Input && e->ct == Output) { return true; }
1157 if (_selection->ct == Output && e->ct == Input) { return true; }
1162 PluginPinWidget::start_drag (const CtrlElem& e, double x, double y)
1164 assert (_selection == e);
1166 if (e->ct == Sink) {
1168 const ChanMapping& map (_in_map[e->ip]);
1169 uint32_t idx = map.get (e->dt, e->id, &valid);
1171 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1176 else if (e->ct == Output) {
1177 for (uint32_t i = 0; i < _n_plugins; ++i) {
1179 const ChanMapping& map (_out_map[i]);
1180 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1182 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1190 const ChanMapping& map (_thru_map);
1191 uint32_t idx = map.get (e->dt, e->id, &valid);
1193 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1205 PluginPinWidget::darea_motion_notify_event (GdkEventMotion* ev)
1207 bool changed = false;
1209 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1210 if (ev->x >= i->x && ev->x <= i->x + i->w
1211 && ev->y >= i->y && ev->y <= i->y + i->h
1212 && drag_type_matches (i->e))
1214 if (!i->prelight) changed = true;
1218 if (i->prelight) changed = true;
1219 i->prelight = false;
1226 if (changed || _dragging) {
1227 darea.queue_draw ();
1233 PluginPinWidget::darea_button_press_event (GdkEventButton* ev)
1235 if (ev->type != GDK_BUTTON_PRESS) {
1239 switch (ev->button) {
1242 if (!_selection || (_selection && !_hover)) {
1243 _selection = _hover;
1246 start_drag (_selection, ev->x, ev->y);
1248 darea.queue_draw ();
1250 } else if (_selection && _hover && _selection != _hover) {
1251 if (_selection->dt != _hover->dt) { _actor.reset (); }
1252 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1253 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1254 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1255 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1256 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1257 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1259 _selection = _hover;
1260 start_drag (_selection, ev->x, ev->y);
1262 darea.queue_draw ();
1264 } else if (_hover) {
1265 _selection = _hover;
1267 start_drag (_selection, ev->x, ev->y);
1272 if (_selection != _hover) {
1273 _selection = _hover;
1274 darea.queue_draw ();
1286 PluginPinWidget::darea_button_release_event (GdkEventButton* ev)
1288 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1289 // select click. (or re-connect same)
1290 assert (_selection != _hover);
1295 darea.queue_draw ();
1299 if (_dragging && _hover && _hover != _selection) {
1303 if (_hover == _actor && _actor && ev->button == 1) {
1304 assert (_selection);
1305 assert (_selection->dt == _actor->dt);
1307 assert (_dragging && _selection != _drag_dst);
1308 handle_disconnect (_drag_dst, true);
1310 if (_selection->ct == Input && _actor->ct == Sink) {
1311 handle_input_action (_actor, _selection);
1313 else if (_selection->ct == Sink && _actor->ct == Input) {
1314 handle_input_action (_selection, _actor);
1316 else if (_selection->ct == Output && _actor->ct == Source) {
1317 handle_output_action (_actor, _selection);
1319 else if (_selection->ct == Source && _actor->ct == Output) {
1320 handle_output_action (_selection, _actor);
1322 else if (_selection->ct == Input && _actor->ct == Output) {
1323 handle_thru_action (_actor, _selection);
1325 else if (_selection->ct == Output && _actor->ct == Input) {
1326 handle_thru_action (_selection, _actor);
1328 _selection.reset ();
1329 } else if (_hover == _selection && _selection && ev->button == 3) {
1330 handle_disconnect (_selection);
1331 } else if (!_hover && ev->button == 3) {
1332 reset_menu.popup (1, ev->time);
1335 if (_dragging && _hover != _selection) {
1336 _selection.reset ();
1341 darea.queue_draw ();
1346 PluginPinWidget::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1348 const int pc = s->ip;
1350 ChanMapping in_map (_pi->input_map (pc));
1351 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1353 if (valid && idx == i->id) {
1356 in_map.unset (s->dt, s->id);
1357 _pi->set_input_map (pc, in_map);
1359 plugin_reconfigured ();
1364 in_map.set (s->dt, s->id, i->id);
1365 _pi->set_input_map (pc, in_map);
1369 in_map.unset (s->dt, s->id);
1370 in_map.set (s->dt, s->id, i->id);
1371 _pi->set_input_map (pc, in_map);
1376 PluginPinWidget::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1378 _ignore_updates = true;
1379 for (uint32_t n = 0; n < _n_plugins; ++n) {
1384 ChanMapping n_out_map (_pi->output_map (n));
1385 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1387 n_out_map.unset (dt, idx);
1388 _pi->set_output_map (n, n_out_map);
1391 _ignore_updates = false;
1395 PluginPinWidget::disconnect_other_thru (DataType dt, uint32_t id)
1397 _ignore_updates = true;
1399 ChanMapping n_thru_map (_pi->thru_map ());
1400 n_thru_map.get (dt, id, &valid);
1402 n_thru_map.unset (dt, id);
1403 _pi->set_thru_map (n_thru_map);
1405 _ignore_updates = false;
1409 PluginPinWidget::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1411 const uint32_t pc = s->ip;
1413 ChanMapping out_map (_pi->output_map (pc));
1414 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1416 if (valid && idx == o->id) {
1419 out_map.unset (s->dt, s->id);
1420 _pi->set_output_map (pc, out_map);
1422 plugin_reconfigured ();
1426 // disconnect source
1427 disconnect_other_outputs (pc, s->dt, o->id);
1428 disconnect_other_thru (s->dt, o->id);
1429 out_map = _pi->output_map (pc); // re-read map
1431 out_map.unset (s->dt, s->id);
1433 idx = out_map.get_src (s->dt, o->id, &valid);
1435 out_map.unset (s->dt, idx);
1438 out_map.set (s->dt, s->id, o->id);
1439 _pi->set_output_map (pc, out_map);
1444 PluginPinWidget::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1447 ChanMapping thru_map (_pi->thru_map ());
1448 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1450 if (valid && idx == i->id) {
1452 thru_map.unset (o->dt, o->id);
1455 // disconnect other outputs first
1456 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1457 disconnect_other_thru (o->dt, o->id);
1458 thru_map = _pi->thru_map (); // re-read map
1460 thru_map.set (o->dt, o->id, i->id);
1462 _pi->set_thru_map (thru_map);
1466 PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal)
1468 _ignore_updates = true;
1469 bool changed = false;
1475 ChanMapping n_thru_map (_pi->thru_map ());
1476 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1477 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1478 if (valid && idx == e->id) {
1479 n_thru_map.unset (e->dt, i);
1484 _pi->set_thru_map (n_thru_map);
1487 for (uint32_t n = 0; n < _n_plugins; ++n) {
1488 ChanMapping map (_pi->input_map (n));
1489 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1490 uint32_t idx = map.get (e->dt, i, &valid);
1491 if (valid && idx == e->id) {
1492 map.unset (e->dt, i);
1496 _pi->set_input_map (n, map);
1501 ChanMapping map (_pi->input_map (e->ip));
1502 map.get (e->dt, e->id, &valid);
1504 map.unset (e->dt, e->id);
1505 _pi->set_input_map (e->ip, map);
1512 ChanMapping map (_pi->output_map (e->ip));
1513 map.get (e->dt, e->id, &valid);
1515 map.unset (e->dt, e->id);
1516 _pi->set_output_map (e->ip, map);
1522 for (uint32_t n = 0; n < _n_plugins; ++n) {
1523 ChanMapping map (_pi->output_map (n));
1524 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1525 uint32_t idx = map.get (e->dt, i, &valid);
1526 if (valid && idx == e->id) {
1527 map.unset (e->dt, i);
1532 _pi->set_output_map (n, map);
1536 ChanMapping n_thru_map (_pi->thru_map ());
1537 n_thru_map.get (e->dt, e->id, &valid);
1539 n_thru_map.unset (e->dt, e->id);
1541 _pi->set_thru_map (n_thru_map);
1546 _ignore_updates = false;
1547 if (changed && !no_signal) {
1548 plugin_reconfigured ();
1554 PluginPinWidget::toggle_sidechain ()
1556 if (_session && _session->actively_recording ()) { return; }
1557 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1561 PluginPinWidget::connect_sidechain ()
1563 if (!_session) { return; }
1565 if (_sidechain_selector == 0) {
1566 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1569 if (_sidechain_selector->is_visible ()) {
1570 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1572 _sidechain_selector->present ();
1577 PluginPinWidget::reset_configuration ()
1579 if (_set_config.get_active ()) {
1580 _route ()->reset_plugin_insert (_pi);
1582 _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
1587 PluginPinWidget::reset_mapping ()
1593 PluginPinWidget::select_output_preset (uint32_t n_audio)
1595 if (_session && _session->actively_recording ()) { return; }
1596 ChanCount out (DataType::AUDIO, n_audio);
1597 _route ()->plugin_preset_output (_pi, out);
1601 PluginPinWidget::add_remove_plugin_clicked (bool add)
1603 if (_session && _session->actively_recording ()) { return; }
1604 ChanCount out = _out;
1605 ChanCount sinks = _sinks;
1606 assert (add || _n_plugins > 0);
1607 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks);
1611 PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1613 if (_session && _session->actively_recording ()) { return; }
1614 ChanCount out = _out;
1615 ChanCount sinks = _sinks;
1616 assert (add || out.get (dt) > 0);
1617 out.set (dt, out.get (dt) + (add ? 1 : -1));
1618 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1622 PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
1624 if (_session && _session->actively_recording ()) { return; }
1625 ChanCount out = _out;
1626 ChanCount sinks = _sinks;
1627 assert (add || sinks.get (dt) > 0);
1628 sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
1629 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1633 PluginPinWidget::add_sidechain_port (DataType dt)
1635 if (_session && _session->actively_recording ()) { return; }
1636 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1641 // this triggers a PluginIoReConfigure with process and processor write lock held
1642 // from /this/ thread.
1643 io->add_port ("", this, dt);
1647 PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1649 if (_session && _session->actively_recording ()) { return; }
1650 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1651 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1655 io->remove_port (p, this);
1659 PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1661 if (_session && _session->actively_recording ()) { return; }
1662 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1663 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1667 p->disconnect_all ();
1671 PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1673 if (_session && _session->actively_recording ()) { return; }
1674 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1675 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1676 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1677 if (!io || !p0 || !p1) {
1680 _ignore_updates = true;
1681 p0->disconnect_all ();
1682 _ignore_updates = false;
1683 p0->connect (p1->name ());
1687 PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1689 if (_session && _session->actively_recording ()) { return; }
1690 boost::shared_ptr<Port> p = wp.lock ();
1691 boost::shared_ptr<Route> r = wr.lock ();
1692 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1693 if (!p || !r || !io || !_session) {
1697 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1698 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1699 const ChanCount& outs (r->amp ()->input_streams ());
1701 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1702 send->output()->ensure_io (outs, false, this);
1703 } catch (AudioEngine::PortRegistrationFailure& err) {
1704 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1708 std::string sendname = send->name ();
1709 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1710 if (last_letter != string::npos) {
1711 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1713 sendname.substr (last_letter + 1)));
1716 _ignore_updates = true;
1717 p->disconnect_all ();
1719 DataType dt = p->type ();
1720 PortSet& ps (send->output ()->ports ());
1721 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1722 p->connect (&(**i));
1725 send->set_remove_on_disconnect (true);
1726 r->add_processor (send, PreFader);
1727 _ignore_updates = false;
1728 queue_idle_update ();
1732 PluginPinWidget::sc_input_release (GdkEventButton *ev)
1734 if (_session && _session->actively_recording ()) { return false; }
1735 if (ev->button == 3) {
1736 connect_sidechain ();
1741 struct RouteCompareByName {
1742 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1743 return a->name ().compare (b->name ()) < 0;
1748 PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1750 using namespace Menu_Helpers;
1751 if (!_session || _session->actively_recording ()) { return false; }
1752 if (!_session->engine ().connected ()) { return false; }
1754 if (ev->button == 1) {
1755 MenuList& citems = input_menu.items ();
1756 input_menu.set_name ("ArdourContextMenu");
1759 boost::shared_ptr<Port> p = wp.lock ();
1760 if (p && p->connected ()) {
1761 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::disconnect_port), wp)));
1762 citems.push_back (SeparatorElem ());
1766 // TODO add system inputs, too ?!
1767 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1768 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1769 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1771 //maybe_add_bundle_to_input_menu (*i, current);
1775 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1776 RouteList copy = *routes;
1777 copy.sort (RouteCompareByName ());
1779 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1780 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1784 citems.push_back (SeparatorElem ());
1786 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinWidget::connect_sidechain)));
1787 input_menu.popup (1, ev->time);
1793 PluginPinWidget::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1796 using namespace Menu_Helpers;
1797 if (r->output () == _route ()->output ()) {
1801 if (_route ()->feeds_according_to_graph (r)) {
1805 MenuList& citems = input_menu.items ();
1807 /*check if there's already a send.. */
1808 bool already_present = false;
1810 boost::shared_ptr<Processor> proc;
1811 /* Note: nth_send () takes a processor read-lock */
1812 while ((proc = r->nth_send (nth))) {
1813 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1814 if (!send || !send->output ()) {
1818 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1819 // only if (send->remove_on_disconnect ()) ??
1820 already_present = true;
1825 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1826 const ChanCount& rc (r->amp ()->input_streams ());
1827 if (!already_present && rc.get (dt) > 0) {
1828 citems.push_back (MenuElemNoMnemonic (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr<Route> (r))));
1835 PluginPinWidget::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1837 boost::shared_ptr<Port> p0 = w0.lock ();
1838 boost::shared_ptr<Port> p1 = w1.lock ();
1840 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1841 if (!io) { return; }
1843 if (p0 && io->has_port (p0)) {
1844 queue_idle_update ();
1846 else if (p1 && io->has_port (p1)) {
1847 queue_idle_update ();
1851 /* lifted from ProcessorEntry::Control */
1852 PluginPinWidget::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1854 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1855 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1856 , _slider_persistant_tooltip (&_slider)
1857 , _ignore_ui_adjustment (false)
1860 _slider.set_controllable (c);
1861 box.set_padding (0, 0, 4, 4);
1863 _slider.set_name ("ProcessorControlSlider");
1864 _slider.set_text (_name);
1869 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1870 double const lo = c->internal_to_interface (desc.lower);
1871 double const up = c->internal_to_interface (desc.upper);
1872 double const normal = c->internal_to_interface (desc.normal);
1873 double const smallstep = c->internal_to_interface (desc.lower + desc.smallstep);
1874 double const largestep = c->internal_to_interface (desc.lower + desc.largestep);
1876 _adjustment.set_lower (lo);
1877 _adjustment.set_upper (up);
1878 _adjustment.set_step_increment (smallstep);
1879 _adjustment.set_page_increment (largestep);
1880 _slider.set_default_value (normal);
1882 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1883 // dup. currently timers are used :(
1884 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1886 // yuck, do we really need to do this?
1887 // according to c404374 this is only needed for send automation
1888 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1893 /* We're providing our own PersistentTooltip */
1894 set_no_tooltip_whatsoever (_slider);
1897 PluginPinWidget::Control::~Control ()
1899 timer_connection.disconnect ();
1903 PluginPinWidget::Control::set_tooltip ()
1905 boost::shared_ptr<AutomationControl> c = _control.lock ();
1909 std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ());
1910 string sm = Gtkmm2ext::markup_escape_text (tt);
1911 _slider_persistant_tooltip.set_tip (sm);
1915 PluginPinWidget::Control::slider_adjusted ()
1917 if (_ignore_ui_adjustment) {
1920 boost::shared_ptr<AutomationControl> c = _control.lock ();
1924 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1930 PluginPinWidget::Control::control_changed ()
1932 boost::shared_ptr<AutomationControl> c = _control.lock ();
1937 _ignore_ui_adjustment = true;
1939 // as long as rapid timers are used, only update the tooltip
1940 // if the value has changed.
1941 const double nval = c->internal_to_interface (c->get_value ());
1942 if (_adjustment.get_value () != nval) {
1943 _adjustment.set_value (nval);
1947 _ignore_ui_adjustment = false;
1952 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
1953 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
1955 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
1960 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
1961 : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
1963 , _height_mapped (false)
1965 vbox = manage (new VBox ());
1966 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
1967 scroller = manage (new ScrolledWindow);
1968 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1969 scroller->set_shadow_type (Gtk::SHADOW_NONE);
1972 scroller->add (*vbox);
1976 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
1978 _route->processors_changed.connect (
1979 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context()
1982 _route->DropReferences.connect (
1983 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context()
1987 PluginPinDialog::set_session (ARDOUR::Session *s)
1989 SessionHandlePtr::set_session (s);
1990 for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) {
1991 (*i)->set_session (s);
1996 PluginPinDialog::map_height (Gtk::Allocation&)
1998 if (!_height_mapped) {
1999 scroller->set_size_request (-1, std::min (600, 2 + vbox->get_height()));
2000 _height_mapped = true;
2005 PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
2008 _height_mapped = false;
2009 scroller->remove ();
2010 vbox = manage (new VBox ());
2011 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
2012 scroller->add (*vbox);
2013 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2018 PluginPinDialog::route_going_away ()
2026 PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
2028 boost::shared_ptr<Processor> proc = p.lock ();
2029 if (!proc || !proc->display_to_user ()) {
2032 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
2034 if (pi && pi->is_channelstrip ()) {
2039 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
2040 vbox->pack_start (*ppw.back());
2042 HBox* hbox = manage (new HBox ());
2043 hbox->pack_start (*manage (new HSeparator ()));
2044 hbox->pack_start (*manage (new Label (proc->display_name ())));
2045 hbox->pack_start (*manage (new HSeparator ()));
2046 vbox->pack_start (*hbox, false, false);