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/box.h>
25 #include <gtkmm/label.h>
27 #include "pbd/replace_all.h"
29 #include "gtkmm2ext/utils.h"
30 #include "gtkmm2ext/rgb_macros.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/plugin.h"
34 #include "ardour/port.h"
35 #include "ardour/profile.h"
36 #include "ardour/session.h"
38 #include "plugin_pin_dialog.h"
39 #include "gui_thread.h"
42 #include "ui_config.h"
46 using namespace ARDOUR;
50 using namespace Gtkmm2ext;
52 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
53 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
54 , _set_config (_("Manual Config"), ArdourButton::led_default_elements)
55 , _tgl_sidechain (_("Side Chain"), ArdourButton::led_default_elements)
56 , _add_plugin (_("+"))
57 , _del_plugin (_("-"))
58 , _add_output_audio (_("+"))
59 , _del_output_audio (_("-"))
60 , _add_output_midi (_("+"))
61 , _del_output_midi (_("-"))
62 , _add_sc_audio (_("Audio"))
63 , _add_sc_midi (_("MIDI"))
75 , _position_valid (false)
76 , _ignore_updates (false)
77 , _sidechain_selector (0)
80 assert (pi->owner ()); // Route
82 _pi->PluginIoReConfigure.connect (
83 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
86 _pi->PluginMapChanged.connect (
87 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
90 _pi->PluginConfigChanged.connect (
91 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
94 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
95 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
96 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
98 _tgl_sidechain.set_name ("pinrouting sidechain");
99 _set_config.set_name ("pinrouting custom");
101 Menu_Helpers::MenuList& citems = reset_menu.items ();
102 reset_menu.set_name ("ArdourContextMenu");
104 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinDialog::reset_mapping)));
106 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
107 _add_plugin.set_tweaks (ArdourButton::Square);
108 _del_plugin.set_tweaks (ArdourButton::Square);
109 _pm_size_group->add_widget (_add_plugin);
110 _pm_size_group->add_widget (_del_plugin);
111 _pm_size_group->add_widget (_add_output_audio);
112 _pm_size_group->add_widget (_del_output_audio);
113 _pm_size_group->add_widget (_add_output_midi);
114 _pm_size_group->add_widget (_del_output_midi);
119 VBox* tl = manage (new VBox ());
120 tl->set_border_width (2);
123 VBox* tr = manage (new VBox ());
124 tr->set_border_width (2);
128 tl->pack_start (_set_config, false, false);
130 box = manage (new HBox ());
131 box->set_border_width (2);
132 box->pack_start (_add_plugin, true, false);
133 box->pack_start (_del_plugin, true, false);
134 f = manage (new Frame ());
135 f->set_label (_("Instances"));
137 tl->pack_start (*f, false, false);
139 box = manage (new HBox ());
140 box->set_border_width (2);
141 box->pack_start (_add_output_audio, true, false);
142 box->pack_start (_del_output_audio, true, false);
143 f = manage (new Frame ());
144 f->set_label (_("Audio Out"));
146 tl->pack_start (*f, false, false);
148 box = manage (new HBox ());
149 box->set_border_width (2);
150 box->pack_start (_add_output_midi, true, false);
151 box->pack_start (_del_output_midi, true, false);
152 f = manage (new Frame ());
153 f->set_label (_("MIDI Out"));
155 tl->pack_start (*f, false, false);
157 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
158 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
159 _out_presets.disable_scrolling ();
160 ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
161 tl->pack_start (_out_presets, false, false);
164 _sidechain_tbl = manage (new Gtk::Table ());
165 _sidechain_tbl->set_spacings (2);
167 tr->pack_start (_tgl_sidechain, false, false);
168 tr->pack_start (*_sidechain_tbl, true, true);
170 box = manage (new VBox ());
171 box->set_border_width (2);
172 box->set_spacing (2);
173 box->pack_start (_add_sc_audio, false, false);
174 box->pack_start (_add_sc_midi , false, false);
175 f = manage (new Frame ());
176 f->set_label (_("Add Sidechain Input"));
179 tr->pack_start (*f, false, false);
182 HBox* hbox = manage (new HBox ());
183 hbox->set_spacing (4);
184 hbox->pack_start (*tl, false, false);
185 hbox->pack_start (darea, true, true);
186 hbox->pack_start (*tr, false, false);
188 VBox* vbox = manage (new VBox ());
189 vbox->pack_start (*hbox, true, true);
190 set_border_width (4);
194 plugin_reconfigured ();
196 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
197 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_request));
198 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_allocate));
199 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event));
200 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_press_event));
201 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_release_event));
202 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_motion_notify_event));
204 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::toggle_sidechain));
206 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::reset_configuration));
207 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), true));
208 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), false));
210 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::AUDIO));
211 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::AUDIO));
212 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::MIDI));
213 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::MIDI));
214 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::AUDIO));
215 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::MIDI));
217 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
218 _io_connection, invalidator (*this), boost::bind (&PluginPinDialog::port_connected_or_disconnected, this, _1, _3), gui_context ()
222 PluginPinDialog::~PluginPinDialog ()
224 delete _sidechain_selector;
228 PluginPinDialog::set_session (ARDOUR::Session *s)
230 SessionHandlePtr::set_session (s);
231 plugin_reconfigured ();
235 PluginPinDialog::queue_idle_update ()
237 /* various actions here are directly executed, in the GUI thread,
238 * with the GUI-thread eventually taking the process and processor lock.
239 * "connect gui_context()" will call back immediately and this
240 * signal-handler will run with the locks held.
242 * This will lead to a crash with calling nth_send() which takes
243 * a processor read-lock while holding a write lock in the same thread.
245 * decouple update to GUI idle.
247 * BUT, do delete existing controls here (in case they're affected by
248 * the change and hit by the Timer before idle comes around)
250 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
251 _sidechain_tbl->remove ((*i)->box);
255 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinDialog::idle_update));
259 PluginPinDialog::idle_update ()
261 plugin_reconfigured ();
267 PluginPinDialog::plugin_reconfigured ()
269 ENSURE_GUI_THREAD (*this, &PluginPinDialog::plugin_reconfigured);
270 if (_ignore_updates) {
273 _n_plugins = _pi->get_count ();
274 _pi->configured_io (_in, _out);
275 _ins = _pi->internal_streams (); // with sidechain
276 _sinks = _pi->natural_input_streams ();
277 _sources = _pi->natural_output_streams ();
280 _tgl_sidechain.set_active (_pi->has_sidechain ());
281 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
282 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
284 if (_pi->custom_cfg ()) {
285 _set_config.set_active (true);
286 _add_plugin.set_sensitive (true);
287 _add_output_audio.set_sensitive (true);
288 _add_output_midi.set_sensitive (true);
289 _del_plugin.set_sensitive (_n_plugins > 1);
290 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
291 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
292 _out_presets.set_sensitive (false);
293 _out_presets.set_text (_("Manual"));
295 _set_config.set_active (false);
296 _add_plugin.set_sensitive (false);
297 _add_output_audio.set_sensitive (false);
298 _add_output_midi.set_sensitive (false);
299 _del_plugin.set_sensitive (false);
300 _del_output_audio.set_sensitive (false);
301 _del_output_midi.set_sensitive (false);
302 _out_presets.set_sensitive (true);
303 refill_output_presets ();
306 if (!_pi->has_sidechain () && _sidechain_selector) {
307 delete _sidechain_selector;
308 _sidechain_selector = 0;
311 refill_sidechain_table ();
313 /* update elements */
322 _n_inputs = _n_sidechains = 0;
324 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
325 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
326 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
327 bool sidechain = id >= _in.get (dt) ? true : false;
334 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
335 _elements.push_back (cw);
338 for (uint32_t i = 0; i < _out.n_total (); ++i) {
339 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
340 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
343 for (uint32_t n = 0; n < _n_plugins; ++n) {
344 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
345 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
346 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
347 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
348 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
349 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
350 _elements.push_back (cw);
352 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
353 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
354 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
355 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
356 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
360 /* calc minimum size */
361 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
362 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
363 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
364 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
365 min_width = std::max ((uint32_t)300, min_width);
367 min_width = 50 + 10 * ceilf (min_width / 10.f);
369 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
370 min_height = std::max ((uint32_t)200, min_height);
371 min_height = 4 * ceilf (min_height / 4.f);
373 if (min_width != _min_width || min_height != _min_height) {
374 _min_width = min_width;
375 _min_height = min_height;
376 darea.queue_resize ();
379 _position_valid = false;
384 PluginPinDialog::refill_sidechain_table ()
386 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
387 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
390 _sidechain_tbl->resize (1, 1);
391 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
395 if (!_pi->has_sidechain () && _sidechain_selector) {
398 boost::shared_ptr<IO> io = _pi->sidechain_input ();
404 PortSet& p (io->ports ());
405 bool can_remove = p.num_ports () > 1;
406 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
407 r += add_port_to_table (*i, r, can_remove);
409 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
410 r += add_port_to_table (*i, r, can_remove);
412 _sidechain_tbl->show_all ();
416 PluginPinDialog::refill_output_presets ()
418 using namespace Menu_Helpers;
419 _out_presets.clear_items ();
420 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
422 bool need_dropdown = true;
424 if (ppc.size () == 0) {
425 need_dropdown = false;
428 if (!_pi->strict_io () && ppc.size () == 1) {
429 need_dropdown = false;
432 if (_pi->strict_io () && ppc.size () == 1) {
433 // "stereo" is currently preferred default for instruments, see PluginInsert
434 if (ppc.find (2) != ppc.end ()) {
435 need_dropdown = false;
439 if (!_pi->needs_midi_input ()) {
440 /* loose definition of instruments, maybe impose additional
441 * || _pi->natural_input_streams ().n_audio () != 0
442 * and special case variable output plugins
443 * && !_pi->plugin (0)->info->reconfigurable_io()
445 need_dropdown = false;
448 if (!need_dropdown) {
449 _out_presets.set_sensitive (false);
450 _out_presets.set_text (_("Automatic"));
454 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), 0)));
456 const uint32_t n_audio = _pi->preset_out ().n_audio ();
458 _out_presets.set_text (_("Automatic"));
461 if (ppc.find (0) != ppc.end ()) {
465 ppc.insert (n_audio);
475 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
486 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
489 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), *i)));
491 _out_presets.set_text (tmp);
497 PluginPinDialog::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
500 std::string tip = p->name ();
501 std::vector<std::string> cns;
502 p->get_connections (cns);
504 // TODO proper labels, see MixerStrip::update_io_button()
505 if (cns.size () == 0) {
507 } else if (cns.size () > 1) {
511 string lpn (PROGRAM_NAME);
512 boost::to_lower (lpn);
513 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
517 if (lbl.find ("system:capture_") == 0) {
518 lbl = AudioEngine::instance ()->get_pretty_name_by_name (lbl);
520 lbl = cns[0].substr (15);
522 } else if (lbl.find ("system:midi_capture_") == 0) {
523 lbl = AudioEngine::instance ()->get_pretty_name_by_name (lbl);
525 // "system:midi_capture_123" -> "123"
526 lbl = "M " + cns[0].substr (20);
528 } else if (lbl.find (program_port_prefix) == 0) {
529 lbl = lbl.substr (program_port_prefix.size ());
532 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
536 replace_all (lbl, "_", " ");
538 ArdourButton *pb = manage (new ArdourButton (lbl));
539 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
540 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
541 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
542 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
544 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::sc_input_press), boost::weak_ptr<Port> (p)), false);
545 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::sc_input_release), false);
547 pb = manage (new ArdourButton ("-"));
548 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
550 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::remove_port), boost::weak_ptr<Port> (p)));
552 pb->set_sensitive (false);
557 if (cns.size () == 1 && _session) {
558 /* check if it's an Ardour Send feeding.. */
559 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
560 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
562 boost::shared_ptr<Processor> proc;
563 /* nth_send () takes a processor read-lock */
564 while ((proc = (*i)->nth_send (nth))) {
565 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
566 if (!send || !send->output ()) {
570 if (!send->output ()->connected_to (p->name ())) {
574 /* if processor goes away, we're notified by the port disconnect,
575 * there should be no need to explicily connect to proc->DropReferences
577 set<Evoral::Parameter> p = proc->what_can_be_automated ();
578 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
579 Control* c = new Control (proc->automation_control (*i), _("Send"));
580 _controls.push_back (c);
582 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
592 PluginPinDialog::update_element_pos ()
595 _innerwidth = _width - 2. * _margin_x;
597 const double yc = rint (_height * .5);
598 const double bxh2 = rint (_margin_y * .45); // TODO grow?
599 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
600 const double bxw2 = rint (bxw * .5);
601 const double y_in = _margin_y;
602 const double y_out = _height - _margin_y;
607 const double dx = _pin_box_size * .5;
610 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
614 i->x = _innerwidth + _margin_x - dx;
615 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
616 i->h = _pin_box_size;
617 i->w = 1.5 * _pin_box_size;
620 uint32_t idx = i->e->id;
621 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
622 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
623 i->w = _pin_box_size;
624 i->h = 1.5 * _pin_box_size;
630 uint32_t idx = i->e->id;
631 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
632 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
634 i->w = _pin_box_size;
635 i->h = 1.5 * _pin_box_size;
640 uint32_t idx = i->e->id;
641 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
642 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
643 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
644 i->y = yc - bxh2 - dx;
645 i->w = _pin_box_size;
646 i->h = _pin_box_size;
651 uint32_t idx = i->e->id;
652 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
653 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
654 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
655 i->y = yc + bxh2 - dx;
656 i->w = _pin_box_size;
657 i->h = _pin_box_size;
665 PluginPinDialog::set_color (cairo_t* cr, bool midi)
667 // see also gtk2_ardour/processor_box.cc
668 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
669 static const uint32_t midi_port_color = 0x960909FF; //Red
672 cairo_set_source_rgb (cr,
673 UINT_RGBA_R_FLT (midi_port_color),
674 UINT_RGBA_G_FLT (midi_port_color),
675 UINT_RGBA_B_FLT (midi_port_color));
677 cairo_set_source_rgb (cr,
678 UINT_RGBA_R_FLT (audio_port_color),
679 UINT_RGBA_G_FLT (audio_port_color),
680 UINT_RGBA_B_FLT (audio_port_color));
685 PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
688 const double dy = w.h * .5;
689 const double dx = w.w - dy;
690 cairo_move_to (cr, w.x, w.y + dy);
691 cairo_rel_line_to (cr, dy, -dy);
692 cairo_rel_line_to (cr, dx, 0);
693 cairo_rel_line_to (cr, 0, w.h);
694 cairo_rel_line_to (cr, -dx, 0);
696 const double dir = (w.e->ct == Input) ? 1 : -1;
697 const double dx = w.w * .5;
698 const double dy = w.h - dx;
700 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
701 cairo_rel_line_to (cr, -dx, -dx * dir);
702 cairo_rel_line_to (cr, 0., -dy * dir);
703 cairo_rel_line_to (cr, 2. * dx, 0.);
704 cairo_rel_line_to (cr, 0., dy * dir);
706 cairo_close_path (cr);
708 cairo_set_line_width (cr, 1.0);
709 cairo_set_source_rgb (cr, 0, 0, 0);
710 cairo_stroke_preserve (cr);
712 set_color (cr, w.e->dt == DataType::MIDI);
715 assert (w.e->ct == Input);
716 cairo_fill_preserve (cr);
717 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
720 if (w.e == _selection || w.e == _actor) {
721 cairo_fill_preserve (cr);
722 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
723 } else if (w.prelight) {
724 cairo_fill_preserve (cr);
725 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
731 PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
733 const double dx = w.w * .5;
734 const double dy = w.h * .5;
736 cairo_move_to (cr, w.x + dx, w.y);
737 cairo_rel_line_to (cr, -dx, dy);
738 cairo_rel_line_to (cr, dx, dy);
739 cairo_rel_line_to (cr, dx, -dy);
740 cairo_close_path (cr);
742 cairo_set_line_width (cr, 1.0);
743 cairo_set_source_rgb (cr, 0, 0, 0);
744 cairo_stroke_preserve (cr);
746 set_color (cr, w.e->dt == DataType::MIDI);
749 assert (w.e->ct == Sink);
750 cairo_fill_preserve (cr);
751 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
754 if (w.e == _selection || w.e == _actor) {
755 cairo_fill_preserve (cr);
756 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
757 } else if (w.prelight) {
758 cairo_fill_preserve (cr);
759 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
763 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
766 Glib::RefPtr<Pango::Layout> layout;
767 layout = Pango::Layout::create (get_pango_context ());
768 layout->set_text (w.name);
769 layout->get_pixel_size (text_width, text_height);
771 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
772 cairo_set_source_rgba (cr, 0, 0, 0, .5);
775 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
776 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
777 pango_cairo_show_layout (cr, layout->gobj ());
782 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
784 if (!midi) { i += n_midi; }
785 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
788 const PluginPinDialog::CtrlWidget&
789 PluginPinDialog::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
791 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
792 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
797 fatal << string_compose (_("programming error: %1"),
798 X_("Invalid Plugin I/O Port."))
800 abort (); /*NOTREACHED*/
801 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
802 return screw_old_compilers;
806 PluginPinDialog::edge_coordinates (const CtrlWidget& w, double &x, double &y)
834 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
836 const double bz = 2 * _pin_box_size;
837 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
838 if (x0 > _width * .5) { bc *= -1; }
840 cairo_move_to (cr, x0, y0);
842 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
844 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
846 cairo_set_line_width (cr, 3.0);
847 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
848 cairo_set_source_rgb (cr, 1, 0, 0);
850 const double dashes[] = { 5, 7 };
851 cairo_set_dash (cr, dashes, 2, 0);
853 set_color (cr, midi);
856 cairo_set_dash (cr, 0, 0, 0);
861 PluginPinDialog::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
863 double x0, x1, y0, y1;
864 edge_coordinates (w0, x0, y0);
865 edge_coordinates (w1, x1, y1);
866 assert (w0.e->dt == w1.e->dt);
867 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
872 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
874 Gtk::Allocation a = darea.get_allocation ();
875 double const width = a.get_width ();
876 double const height = a.get_height ();
878 if (!_position_valid) {
881 update_element_pos ();
882 _position_valid = true;
885 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
886 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
889 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
890 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
891 cairo_rectangle (cr, 0, 0, width, height);
894 const double yc = rint (_height * .5);
897 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
898 cairo_set_line_width (cr, 1.0);
899 cairo_set_source_rgb (cr, .1, .1, .3);
900 cairo_stroke_preserve (cr);
901 cairo_set_source_rgb (cr, .3, .3, .3);
905 Glib::RefPtr<Pango::Layout> layout;
906 layout = Pango::Layout::create (get_pango_context ());
908 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
909 layout->set_width (_height * PANGO_SCALE);
914 layout->set_text (_route ()->name ());
915 layout->get_pixel_size (text_width, text_height);
917 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
918 cairo_rotate (cr, M_PI * -.5);
919 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
920 pango_cairo_show_layout (cr, layout->gobj ());
924 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
925 layout->set_text (_pi->name ());
926 layout->get_pixel_size (text_width, text_height);
927 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
928 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
929 pango_cairo_show_layout (cr, layout->gobj ());
931 if (_pi->signal_latency () > 0) {
932 // TODO: this needs a better location also format to msec (and cache)
933 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
934 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
935 layout->get_pixel_size (text_width, text_height);
936 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
937 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
938 pango_cairo_show_layout (cr, layout->gobj ());
941 if (_pi->strict_io () && !Profile->get_mixbus ()) {
942 layout->set_text (_("Strict I/O"));
943 layout->get_pixel_size (text_width, text_height);
944 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
945 const double sy0 = _height - 3 - text_height;
947 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
948 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
951 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
952 cairo_move_to (cr, sx0, sy0);
953 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
954 pango_cairo_show_layout (cr, layout->gobj ());
957 /* draw midi-bypass (behind) */
958 if (_pi->has_midi_bypass ()) {
959 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
960 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
961 draw_connection (cr, cw0, cw1, true);
964 /* thru connections */
965 const ChanMapping::Mappings thru_map = _pi->thru_map ().mappings ();
966 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
967 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
968 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
969 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
970 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
971 draw_connection (cr, cw1, cw0, true);
977 /* plugins & connection wires */
978 for (uint32_t i = 0; i < _n_plugins; ++i) {
979 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
982 cairo_set_source_rgb (cr, .5, .5, .5);
983 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
986 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
987 layout->set_text (string_compose (_("Instance #%1"), i + 1));
988 layout->get_pixel_size (text_width, text_height);
989 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
990 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
991 pango_cairo_show_layout (cr, layout->gobj ());
993 const ChanMapping::Mappings in_map = _pi->input_map (i).mappings ();
994 const ChanMapping::Mappings out_map = _pi->output_map (i).mappings ();
996 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
997 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
998 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
999 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1000 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1001 draw_connection (cr, cw0, cw1);
1006 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1007 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1008 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1009 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1010 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1011 draw_connection (cr, cw0, cw1);
1017 /* pins and ports */
1018 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1022 draw_io_pin (cr, *i);
1026 draw_plugin_pin (cr, *i);
1032 CtrlWidget *drag_src = NULL;
1034 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1035 if (i->e == _selection ) {
1043 if (_selection->ct == Input || _selection->ct == Source) {
1044 edge_coordinates (*drag_src, x0, y0);
1045 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1046 _selection->dt == DataType::MIDI, _selection->sc);
1048 edge_coordinates (*drag_src, x0, y0);
1049 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1050 _selection->dt == DataType::MIDI, _selection->sc);
1059 PluginPinDialog::darea_size_request (Gtk::Requisition* req)
1061 req->width = _min_width;
1062 req->height = _min_height;
1066 PluginPinDialog::darea_size_allocate (Gtk::Allocation&)
1068 _position_valid = false;
1072 PluginPinDialog::drag_type_matches (const CtrlElem& e)
1074 if (!_dragging || !_selection) {
1077 if (_selection->dt != e->dt) {
1080 if (_selection->ct == Input && e->ct == Sink) { return true; }
1081 if (_selection->ct == Sink && e->ct == Input) { return true; }
1082 if (_selection->ct == Output && e->ct == Source) { return true; }
1083 if (_selection->ct == Source && e->ct == Output) { return true; }
1084 if (_selection->ct == Input && e->ct == Output) { return true; }
1085 if (_selection->ct == Output && e->ct == Input) { return true; }
1090 PluginPinDialog::start_drag (const CtrlElem& e, double x, double y)
1092 assert (_selection == e);
1094 if (e->ct == Sink) {
1096 const ChanMapping& map (_pi->input_map (e->ip));
1097 uint32_t idx = map.get (e->dt, e->id, &valid);
1099 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1104 else if (e->ct == Output) {
1105 for (uint32_t i = 0; i < _n_plugins; ++i) {
1107 const ChanMapping& map (_pi->output_map (i));
1108 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1110 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1118 const ChanMapping& map (_pi->thru_map ());
1119 uint32_t idx = map.get (e->dt, e->id, &valid);
1121 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1133 PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev)
1135 bool changed = false;
1137 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1138 if (ev->x >= i->x && ev->x <= i->x + i->w
1139 && ev->y >= i->y && ev->y <= i->y + i->h
1140 && drag_type_matches (i->e))
1142 if (!i->prelight) changed = true;
1146 if (i->prelight) changed = true;
1147 i->prelight = false;
1154 if (changed || _dragging) {
1155 darea.queue_draw ();
1161 PluginPinDialog::darea_button_press_event (GdkEventButton* ev)
1163 if (ev->type != GDK_BUTTON_PRESS) {
1167 switch (ev->button) {
1170 if (!_selection || (_selection && !_hover)) {
1171 _selection = _hover;
1174 start_drag (_selection, ev->x, ev->y);
1176 darea.queue_draw ();
1178 } else if (_selection && _hover && _selection != _hover) {
1179 if (_selection->dt != _hover->dt) { _actor.reset (); }
1180 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1181 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1182 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1183 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1184 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1185 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1187 _selection = _hover;
1188 start_drag (_selection, ev->x, ev->y);
1190 darea.queue_draw ();
1192 } else if (_hover) {
1193 _selection = _hover;
1195 start_drag (_selection, ev->x, ev->y);
1200 if (_selection != _hover) {
1201 _selection = _hover;
1202 darea.queue_draw ();
1214 PluginPinDialog::darea_button_release_event (GdkEventButton* ev)
1216 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1217 // select click. (or re-connect same)
1218 assert (_selection != _hover);
1223 darea.queue_draw ();
1227 if (_dragging && _hover && _hover != _selection) {
1231 if (_hover == _actor && _actor && ev->button == 1) {
1232 assert (_selection);
1233 assert (_selection->dt == _actor->dt);
1235 assert (_dragging && _selection != _drag_dst);
1236 handle_disconnect (_drag_dst, true);
1238 if (_selection->ct == Input && _actor->ct == Sink) {
1239 handle_input_action (_actor, _selection);
1241 else if (_selection->ct == Sink && _actor->ct == Input) {
1242 handle_input_action (_selection, _actor);
1244 else if (_selection->ct == Output && _actor->ct == Source) {
1245 handle_output_action (_actor, _selection);
1247 else if (_selection->ct == Source && _actor->ct == Output) {
1248 handle_output_action (_selection, _actor);
1250 else if (_selection->ct == Input && _actor->ct == Output) {
1251 handle_thru_action (_actor, _selection);
1253 else if (_selection->ct == Output && _actor->ct == Input) {
1254 handle_thru_action (_selection, _actor);
1256 _selection.reset ();
1257 } else if (_hover == _selection && _selection && ev->button == 3) {
1258 handle_disconnect (_selection);
1259 } else if (!_hover && ev->button == 3) {
1260 reset_menu.popup (1, ev->time);
1263 if (_dragging && _hover != _selection) {
1264 _selection.reset ();
1269 darea.queue_draw ();
1274 PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1276 const int pc = s->ip;
1278 ChanMapping in_map (_pi->input_map (pc));
1279 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1281 if (valid && idx == i->id) {
1284 in_map.unset (s->dt, s->id);
1285 _pi->set_input_map (pc, in_map);
1287 plugin_reconfigured ();
1292 in_map.set (s->dt, s->id, i->id);
1293 _pi->set_input_map (pc, in_map);
1297 in_map.unset (s->dt, s->id);
1298 in_map.set (s->dt, s->id, i->id);
1299 _pi->set_input_map (pc, in_map);
1304 PluginPinDialog::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1306 _ignore_updates = true;
1307 for (uint32_t n = 0; n < _n_plugins; ++n) {
1312 ChanMapping n_out_map (_pi->output_map (n));
1313 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1315 n_out_map.unset (dt, idx);
1316 _pi->set_output_map (n, n_out_map);
1319 _ignore_updates = false;
1323 PluginPinDialog::disconnect_other_thru (DataType dt, uint32_t id)
1325 _ignore_updates = true;
1327 ChanMapping n_thru_map (_pi->thru_map ());
1328 n_thru_map.get (dt, id, &valid);
1330 n_thru_map.unset (dt, id);
1331 _pi->set_thru_map (n_thru_map);
1333 _ignore_updates = false;
1337 PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1339 const uint32_t pc = s->ip;
1341 ChanMapping out_map (_pi->output_map (pc));
1342 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1344 if (valid && idx == o->id) {
1347 out_map.unset (s->dt, s->id);
1348 _pi->set_output_map (pc, out_map);
1350 plugin_reconfigured ();
1354 // disconnect source
1355 disconnect_other_outputs (pc, s->dt, o->id);
1356 disconnect_other_thru (s->dt, o->id);
1357 out_map = _pi->output_map (pc); // re-read map
1359 out_map.unset (s->dt, s->id);
1361 idx = out_map.get_src (s->dt, o->id, &valid);
1363 out_map.unset (s->dt, idx);
1366 out_map.set (s->dt, s->id, o->id);
1367 _pi->set_output_map (pc, out_map);
1372 PluginPinDialog::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1375 ChanMapping thru_map (_pi->thru_map ());
1376 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1378 if (valid && idx == i->id) {
1380 thru_map.unset (o->dt, o->id);
1383 // disconnect other outputs first
1384 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1385 disconnect_other_thru (o->dt, o->id);
1386 thru_map = _pi->thru_map (); // re-read map
1388 thru_map.set (o->dt, o->id, i->id);
1390 _pi->set_thru_map (thru_map);
1394 PluginPinDialog::handle_disconnect (const CtrlElem &e, bool no_signal)
1396 _ignore_updates = true;
1397 bool changed = false;
1403 ChanMapping n_thru_map (_pi->thru_map ());
1404 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1405 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1406 if (valid && idx == e->id) {
1407 n_thru_map.unset (e->dt, i);
1412 _pi->set_thru_map (n_thru_map);
1415 for (uint32_t n = 0; n < _n_plugins; ++n) {
1416 ChanMapping map (_pi->input_map (n));
1417 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1418 uint32_t idx = map.get (e->dt, i, &valid);
1419 if (valid && idx == e->id) {
1420 map.unset (e->dt, i);
1424 _pi->set_input_map (n, map);
1429 ChanMapping map (_pi->input_map (e->ip));
1430 map.get (e->dt, e->id, &valid);
1432 map.unset (e->dt, e->id);
1433 _pi->set_input_map (e->ip, map);
1440 ChanMapping map (_pi->output_map (e->ip));
1441 map.get (e->dt, e->id, &valid);
1443 map.unset (e->dt, e->id);
1444 _pi->set_output_map (e->ip, map);
1450 for (uint32_t n = 0; n < _n_plugins; ++n) {
1451 ChanMapping map (_pi->output_map (n));
1452 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1453 uint32_t idx = map.get (e->dt, i, &valid);
1454 if (valid && idx == e->id) {
1455 map.unset (e->dt, i);
1460 _pi->set_output_map (n, map);
1464 ChanMapping n_thru_map (_pi->thru_map ());
1465 n_thru_map.get (e->dt, e->id, &valid);
1467 n_thru_map.unset (e->dt, e->id);
1469 _pi->set_thru_map (n_thru_map);
1474 _ignore_updates = false;
1475 if (changed && !no_signal) {
1476 plugin_reconfigured ();
1482 PluginPinDialog::toggle_sidechain ()
1484 if (_session && _session->actively_recording ()) { return; }
1485 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1489 PluginPinDialog::connect_sidechain ()
1491 if (!_session) { return; }
1493 if (_sidechain_selector == 0) {
1494 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1497 if (_sidechain_selector->is_visible ()) {
1498 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1500 _sidechain_selector->present ();
1505 PluginPinDialog::reset_configuration ()
1507 if (_set_config.get_active ()) {
1508 _route ()->reset_plugin_insert (_pi);
1510 _route ()->customize_plugin_insert (_pi, _n_plugins, _out);
1515 PluginPinDialog::reset_mapping ()
1521 PluginPinDialog::select_output_preset (uint32_t n_audio)
1523 if (_session && _session->actively_recording ()) { return; }
1524 ChanCount out (DataType::AUDIO, n_audio);
1525 _route ()->plugin_preset_output (_pi, out);
1529 PluginPinDialog::add_remove_plugin_clicked (bool add)
1531 if (_session && _session->actively_recording ()) { return; }
1532 ChanCount out = _out;
1533 assert (add || _n_plugins > 0);
1534 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out);
1538 PluginPinDialog::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1540 if (_session && _session->actively_recording ()) { return; }
1541 ChanCount out = _out;
1542 assert (add || out.get (dt) > 0);
1543 out.set (dt, out.get (dt) + (add ? 1 : -1));
1544 _route ()->customize_plugin_insert (_pi, _n_plugins, out);
1548 PluginPinDialog::add_sidechain_port (DataType dt)
1550 if (_session && _session->actively_recording ()) { return; }
1551 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1556 // this triggers a PluginIoReConfigure with process and processor write lock held
1557 // from /this/ thread.
1558 io->add_port ("", this, dt);
1562 PluginPinDialog::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1564 if (_session && _session->actively_recording ()) { return; }
1565 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1566 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1570 io->remove_port (p, this);
1574 PluginPinDialog::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1576 if (_session && _session->actively_recording ()) { return; }
1577 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1578 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1582 p->disconnect_all ();
1586 PluginPinDialog::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1588 if (_session && _session->actively_recording ()) { return; }
1589 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1590 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1591 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1592 if (!io || !p0 || !p1) {
1595 _ignore_updates = true;
1596 p0->disconnect_all ();
1597 _ignore_updates = false;
1598 p0->connect (p1->name ());
1602 PluginPinDialog::sc_input_release (GdkEventButton *ev)
1604 if (_session && _session->actively_recording ()) { return false; }
1605 if (ev->button == 3) {
1606 connect_sidechain ();
1611 struct RouteCompareByName {
1612 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1613 return a->name ().compare (b->name ()) < 0;
1618 PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1620 using namespace Menu_Helpers;
1621 if (!_session || _session->actively_recording ()) { return false; }
1622 if (!_session->engine ().connected ()) { return false; }
1624 if (ev->button == 1) {
1625 MenuList& citems = input_menu.items ();
1626 input_menu.set_name ("ArdourContextMenu");
1629 boost::shared_ptr<Port> p = wp.lock ();
1630 if (p && p->connected ()) {
1631 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::disconnect_port), wp)));
1632 citems.push_back (SeparatorElem ());
1636 // TODO add system inputs, too ?!
1637 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1638 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1639 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1641 //maybe_add_bundle_to_input_menu (*i, current);
1645 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1646 RouteList copy = *routes;
1647 copy.sort (RouteCompareByName ());
1649 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1650 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1654 citems.push_back (SeparatorElem ());
1656 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinDialog::connect_sidechain)));
1657 input_menu.popup (1, ev->time);
1663 PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1666 using namespace Menu_Helpers;
1667 if (r->output () == _route ()->output ()) {
1671 if (_route ()->feeds_according_to_graph (r)) {
1675 MenuList& citems = input_menu.items ();
1676 const IOVector& iov (r->all_outputs ());
1678 for (IOVector::const_iterator o = iov.begin (); o != iov.end (); ++o) {
1679 boost::shared_ptr<IO> op = o->lock ();
1683 PortSet& p (op->ports ());
1684 for (PortSet::iterator i = p.begin (dt); i != p.end (dt); ++i) {
1685 std::string n = i->name ();
1686 replace_all (n, "_", " ");
1687 citems.push_back (MenuElem (n, sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::connect_port), wp, boost::weak_ptr<Port> (*i))));
1695 PluginPinDialog::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1697 boost::shared_ptr<Port> p0 = w0.lock ();
1698 boost::shared_ptr<Port> p1 = w1.lock ();
1700 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1701 if (!io) { return; }
1703 if (p0 && io->has_port (p0)) {
1704 queue_idle_update ();
1706 else if (p1 && io->has_port (p1)) {
1707 queue_idle_update ();
1711 /* lifted from ProcessorEntry::Control */
1712 PluginPinDialog::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1714 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1715 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1716 , _slider_persistant_tooltip (&_slider)
1717 , _ignore_ui_adjustment (false)
1720 _slider.set_controllable (c);
1721 box.set_padding (0, 0, 4, 4);
1723 _slider.set_name ("ProcessorControlSlider");
1724 _slider.set_text (_name);
1729 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1730 double const lo = c->internal_to_interface (desc.lower);
1731 double const up = c->internal_to_interface (desc.upper);
1732 double const normal = c->internal_to_interface (desc.normal);
1733 double smallstep = desc.smallstep;
1734 double largestep = desc.largestep;
1736 if (smallstep == 0.0) {
1737 smallstep = up / 1000.;
1739 smallstep = c->internal_to_interface (desc.lower + smallstep);
1742 if (largestep == 0.0) {
1743 largestep = up / 40.;
1745 largestep = c->internal_to_interface (desc.lower + largestep);
1748 _adjustment.set_lower (lo);
1749 _adjustment.set_upper (up);
1750 _adjustment.set_step_increment (smallstep);
1751 _adjustment.set_page_increment (largestep);
1752 _slider.set_default_value (normal);
1754 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1755 // dup. currently timers are used :(
1756 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1758 // yuck, do we really need to do this?
1759 // according to c404374 this is only needed for send automation
1760 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1765 /* We're providing our own PersistentTooltip */
1766 set_no_tooltip_whatsoever (_slider);
1769 PluginPinDialog::Control::~Control ()
1771 timer_connection.disconnect ();
1775 PluginPinDialog::Control::set_tooltip ()
1777 boost::shared_ptr<AutomationControl> c = _control.lock ();
1782 snprintf (tmp, sizeof (tmp), "%s: %.2f", _name.c_str (), c->internal_to_user (c->get_value ()));
1784 string sm = Gtkmm2ext::markup_escape_text (tmp);
1785 _slider_persistant_tooltip.set_tip (sm);
1789 PluginPinDialog::Control::slider_adjusted ()
1791 if (_ignore_ui_adjustment) {
1794 boost::shared_ptr<AutomationControl> c = _control.lock ();
1798 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1804 PluginPinDialog::Control::control_changed ()
1806 boost::shared_ptr<AutomationControl> c = _control.lock ();
1811 _ignore_ui_adjustment = true;
1813 // as long as rapid timers are used, only update the tooltip
1814 // if the value has changed.
1815 const double nval = c->internal_to_interface (c->get_value ());
1816 if (_adjustment.get_value () != nval) {
1817 _adjustment.set_value (nval);
1821 _ignore_ui_adjustment = false;