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/amp.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/pannable.h"
35 #include "ardour/plugin.h"
36 #include "ardour/port.h"
37 #include "ardour/profile.h"
38 #include "ardour/send.h"
39 #include "ardour/session.h"
41 #include "plugin_pin_dialog.h"
42 #include "gui_thread.h"
45 #include "ui_config.h"
49 using namespace ARDOUR;
53 using namespace Gtkmm2ext;
55 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
56 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
57 , _set_config (_("Manual Config"), ArdourButton::led_default_elements)
58 , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements)
59 , _add_plugin (_("+"))
60 , _del_plugin (_("-"))
61 , _add_input_audio (_("+"))
62 , _del_input_audio (_("-"))
63 , _add_input_midi (_("+"))
64 , _del_input_midi (_("-"))
65 , _add_output_audio (_("+"))
66 , _del_output_audio (_("-"))
67 , _add_output_midi (_("+"))
68 , _del_output_midi (_("-"))
69 , _add_sc_audio (_("Audio"))
70 , _add_sc_midi (_("MIDI"))
82 , _position_valid (false)
83 , _ignore_updates (false)
84 , _sidechain_selector (0)
87 assert (pi->owner ()); // Route
89 _pi->PluginIoReConfigure.connect (
90 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
93 _pi->PluginMapChanged.connect (
94 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
97 _pi->PluginConfigChanged.connect (
98 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::queue_idle_update, this), gui_context ()
101 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
102 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
103 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
105 _tgl_sidechain.set_name ("pinrouting sidechain");
106 _set_config.set_name ("pinrouting custom");
108 Menu_Helpers::MenuList& citems = reset_menu.items ();
109 reset_menu.set_name ("ArdourContextMenu");
111 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinDialog::reset_mapping)));
113 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
114 _add_plugin.set_tweaks (ArdourButton::Square);
115 _del_plugin.set_tweaks (ArdourButton::Square);
116 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
117 _pm_size_group->add_widget (_add_input_audio);
118 _pm_size_group->add_widget (_del_input_audio);
119 _pm_size_group->add_widget (_add_input_midi);
120 _pm_size_group->add_widget (_del_input_midi);
122 _pm_size_group->add_widget (_add_plugin);
123 _pm_size_group->add_widget (_del_plugin);
125 _pm_size_group->add_widget (_add_output_audio);
126 _pm_size_group->add_widget (_del_output_audio);
127 _pm_size_group->add_widget (_add_output_midi);
128 _pm_size_group->add_widget (_del_output_midi);
133 VBox* tl = manage (new VBox ());
134 tl->set_border_width (2);
137 VBox* tr = manage (new VBox ());
138 tr->set_border_width (2);
142 tl->pack_start (_set_config, false, false);
144 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
145 box = manage (new HBox ());
146 box->set_border_width (2);
147 box->pack_start (_add_input_audio, true, false);
148 box->pack_start (_del_input_audio, true, false);
149 f = manage (new Frame ());
150 f->set_label (_("Audio Input Pins"));
152 tl->pack_start (*f, false, false);
154 box = manage (new HBox ());
155 box->set_border_width (2);
156 box->pack_start (_add_input_midi, true, false);
157 box->pack_start (_del_input_midi, true, false);
158 f = manage (new Frame ());
159 f->set_label (_("MIDI Input Pins"));
161 tl->pack_start (*f, false, false);
163 box = manage (new HBox ());
164 box->set_border_width (2);
165 box->pack_start (_add_plugin, true, false);
166 box->pack_start (_del_plugin, true, false);
167 f = manage (new Frame ());
168 f->set_label (_("Instances"));
170 tl->pack_start (*f, false, false);
173 box = manage (new HBox ());
174 box->set_border_width (2);
175 box->pack_start (_add_output_audio, true, false);
176 box->pack_start (_del_output_audio, true, false);
177 f = manage (new Frame ());
178 f->set_label (_("Audio Out"));
180 tl->pack_start (*f, false, false);
182 box = manage (new HBox ());
183 box->set_border_width (2);
184 box->pack_start (_add_output_midi, true, false);
185 box->pack_start (_del_output_midi, true, false);
186 f = manage (new Frame ());
187 f->set_label (_("MIDI Out"));
189 tl->pack_start (*f, false, false);
191 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
192 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
193 _out_presets.disable_scrolling ();
194 ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
195 tl->pack_start (_out_presets, false, false);
198 _sidechain_tbl = manage (new Gtk::Table ());
199 _sidechain_tbl->set_spacings (2);
201 tr->pack_start (_tgl_sidechain, false, false);
202 tr->pack_start (*_sidechain_tbl, true, true);
204 box = manage (new VBox ());
205 box->set_border_width (2);
206 box->set_spacing (2);
207 box->pack_start (_add_sc_audio, false, false);
208 box->pack_start (_add_sc_midi , false, false);
209 f = manage (new Frame ());
210 f->set_label (_("Add Sidechain Input"));
213 tr->pack_start (*f, false, false);
216 HBox* hbox = manage (new HBox ());
217 hbox->set_spacing (4);
218 hbox->pack_start (*tl, false, false);
219 hbox->pack_start (darea, true, true);
220 hbox->pack_start (*tr, false, false);
222 VBox* vbox = manage (new VBox ());
223 vbox->pack_start (*hbox, true, true);
224 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, &PluginPinDialog::darea_size_request));
232 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_allocate));
233 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event));
234 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_press_event));
235 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_release_event));
236 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_motion_notify_event));
238 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::toggle_sidechain));
240 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinDialog::reset_configuration));
241 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), true));
242 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_plugin_clicked), false));
244 _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_inpin_clicked), true, DataType::AUDIO));
245 _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_inpin_clicked), false, DataType::AUDIO));
246 _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_inpin_clicked), true, DataType::MIDI));
247 _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_inpin_clicked), false, DataType::MIDI));
249 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::AUDIO));
250 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::AUDIO));
251 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::MIDI));
252 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::MIDI));
254 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::AUDIO));
255 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_sidechain_port), DataType::MIDI));
257 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
258 _io_connection, invalidator (*this), boost::bind (&PluginPinDialog::port_connected_or_disconnected, this, _1, _3), gui_context ()
262 PluginPinDialog::~PluginPinDialog ()
264 delete _sidechain_selector;
268 PluginPinDialog::set_session (ARDOUR::Session *s)
270 SessionHandlePtr::set_session (s);
271 plugin_reconfigured ();
275 PluginPinDialog::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, &PluginPinDialog::idle_update));
299 PluginPinDialog::idle_update ()
301 plugin_reconfigured ();
307 PluginPinDialog::plugin_reconfigured ()
309 ENSURE_GUI_THREAD (*this, &PluginPinDialog::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 PluginPinDialog::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 PluginPinDialog::refill_output_presets ()
475 using namespace Menu_Helpers;
476 _out_presets.clear_items ();
477 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
479 bool need_dropdown = true;
481 if (ppc.size () == 0) {
482 need_dropdown = false;
485 if (!_pi->strict_io () && ppc.size () == 1) {
486 need_dropdown = false;
489 if (_pi->strict_io () && ppc.size () == 1) {
490 // "stereo" is currently preferred default for instruments, see PluginInsert
491 if (ppc.find (2) != ppc.end ()) {
492 need_dropdown = false;
496 if (!_pi->needs_midi_input ()) {
497 /* loose definition of instruments, maybe impose additional
498 * || _pi->natural_input_streams ().n_audio () != 0
499 * and special case variable output plugins
500 * && !_pi->plugin (0)->info->reconfigurable_io()
502 need_dropdown = false;
505 if (!need_dropdown) {
506 _out_presets.set_sensitive (false);
507 _out_presets.set_text (_("Automatic"));
511 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), 0)));
513 const uint32_t n_audio = _pi->preset_out ().n_audio ();
515 _out_presets.set_text (_("Automatic"));
518 if (ppc.find (0) != ppc.end ()) {
522 ppc.insert (n_audio);
532 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
543 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
546 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::select_output_preset), *i)));
548 _out_presets.set_text (tmp);
554 PluginPinDialog::port_label (const std::string& portname, bool strip)
556 // compare to MixerStrip::update_io_button()
557 string lpn (PROGRAM_NAME);
558 boost::to_lower (lpn);
559 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
561 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
563 string::size_type slash = pn.find ("/");
564 if (slash != string::npos) {
565 pn = pn.substr (0, slash);
569 std::string label (portname);
570 if (label.find ("system:capture_") == 0) {
571 if (label.empty ()) {
572 label = portname.substr (15);
574 } else if (label.find ("system:midi_capture_") == 0) {
575 if (label.empty ()) {
576 // "system:midi_capture_123" -> "123"
577 label = "M " + portname.substr (20);
579 } else if (label.find (program_port_prefix) == 0) {
580 label = label.substr (program_port_prefix.size ());
582 string::size_type slash = label.find ("/");
583 if (slash != string::npos) {
584 label = label.substr (0, slash);
592 PluginPinDialog::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
595 std::string tip = p->name ();
596 std::vector<std::string> cns;
597 bool single_source = true;
598 p->get_connections (cns);
600 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
602 lbl = port_label (*i, true);
605 if (port_label (*i, true) != lbl) {
607 single_source = false;
612 if (cns.size () == 0) {
614 single_source = false;
615 } else if (cns.size () == 1) {
617 lbl = port_label (cns[0], false);
621 replace_all (lbl, "_", " ");
623 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
628 ArdourButton *pb = manage (new ArdourButton (lbl));
629 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
630 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
631 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
632 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
634 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::sc_input_press), boost::weak_ptr<Port> (p)), false);
635 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinDialog::sc_input_release), false);
637 pb = manage (new ArdourButton ("-"));
638 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
640 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::remove_port), boost::weak_ptr<Port> (p)));
642 pb->set_sensitive (false);
647 if (single_source && _session) {
648 /* check if it's an Ardour Send feeding.. */
649 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
650 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
652 boost::shared_ptr<Processor> proc;
653 /* nth_send () takes a processor read-lock */
654 while ((proc = (*i)->nth_send (nth))) {
655 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
656 if (!send || !send->output ()) {
660 if (!send->output ()->connected_to (p->name ())) {
664 /* if processor goes away, we're notified by the port disconnect,
665 * there should be no need to explicily connect to proc->DropReferences
667 set<Evoral::Parameter> p = proc->what_can_be_automated ();
668 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
669 Control* c = new Control (proc->automation_control (*i), _("Send"));
670 _controls.push_back (c);
672 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
682 PluginPinDialog::update_element_pos ()
685 _innerwidth = _width - 2. * _margin_x;
687 const double yc = rint (_height * .5);
688 const double bxh2 = rint (_margin_y * .45); // TODO grow?
689 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
690 const double bxw2 = rint (bxw * .5);
691 const double y_in = _margin_y;
692 const double y_out = _height - _margin_y;
697 const double dx = _pin_box_size * .5;
700 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
704 i->x = _innerwidth + _margin_x - dx;
705 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
706 i->h = _pin_box_size;
707 i->w = 1.5 * _pin_box_size;
710 uint32_t idx = i->e->id;
711 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
712 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
713 i->w = _pin_box_size;
714 i->h = 1.5 * _pin_box_size;
720 uint32_t idx = i->e->id;
721 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
722 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
724 i->w = _pin_box_size;
725 i->h = 1.5 * _pin_box_size;
730 uint32_t idx = i->e->id;
731 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
732 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
733 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
734 i->y = yc - bxh2 - dx;
735 i->w = _pin_box_size;
736 i->h = _pin_box_size;
741 uint32_t idx = i->e->id;
742 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
743 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
744 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
745 i->y = yc + bxh2 - dx;
746 i->w = _pin_box_size;
747 i->h = _pin_box_size;
755 PluginPinDialog::set_color (cairo_t* cr, bool midi)
757 // see also gtk2_ardour/processor_box.cc
758 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
759 static const uint32_t midi_port_color = 0x960909FF; //Red
762 cairo_set_source_rgb (cr,
763 UINT_RGBA_R_FLT (midi_port_color),
764 UINT_RGBA_G_FLT (midi_port_color),
765 UINT_RGBA_B_FLT (midi_port_color));
767 cairo_set_source_rgb (cr,
768 UINT_RGBA_R_FLT (audio_port_color),
769 UINT_RGBA_G_FLT (audio_port_color),
770 UINT_RGBA_B_FLT (audio_port_color));
775 PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
778 const double dy = w.h * .5;
779 const double dx = w.w - dy;
780 cairo_move_to (cr, w.x, w.y + dy);
781 cairo_rel_line_to (cr, dy, -dy);
782 cairo_rel_line_to (cr, dx, 0);
783 cairo_rel_line_to (cr, 0, w.h);
784 cairo_rel_line_to (cr, -dx, 0);
786 const double dir = (w.e->ct == Input) ? 1 : -1;
787 const double dx = w.w * .5;
788 const double dy = w.h - dx;
790 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
791 cairo_rel_line_to (cr, -dx, -dx * dir);
792 cairo_rel_line_to (cr, 0., -dy * dir);
793 cairo_rel_line_to (cr, 2. * dx, 0.);
794 cairo_rel_line_to (cr, 0., dy * dir);
796 cairo_close_path (cr);
798 cairo_set_line_width (cr, 1.0);
799 cairo_set_source_rgb (cr, 0, 0, 0);
800 cairo_stroke_preserve (cr);
802 set_color (cr, w.e->dt == DataType::MIDI);
805 assert (w.e->ct == Input);
806 cairo_fill_preserve (cr);
807 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
810 if (w.e == _selection || w.e == _actor) {
811 cairo_fill_preserve (cr);
812 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
813 } else if (w.prelight) {
814 cairo_fill_preserve (cr);
815 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
821 PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
823 const double dx = w.w * .5;
824 const double dy = w.h * .5;
826 cairo_move_to (cr, w.x + dx, w.y);
827 cairo_rel_line_to (cr, -dx, dy);
828 cairo_rel_line_to (cr, dx, dy);
829 cairo_rel_line_to (cr, dx, -dy);
830 cairo_close_path (cr);
832 cairo_set_line_width (cr, 1.0);
833 cairo_set_source_rgb (cr, 0, 0, 0);
834 cairo_stroke_preserve (cr);
836 set_color (cr, w.e->dt == DataType::MIDI);
839 assert (w.e->ct == Sink);
840 cairo_fill_preserve (cr);
841 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
844 if (w.e == _selection || w.e == _actor) {
845 cairo_fill_preserve (cr);
846 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
847 } else if (w.prelight) {
848 cairo_fill_preserve (cr);
849 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
853 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
856 Glib::RefPtr<Pango::Layout> layout;
857 layout = Pango::Layout::create (get_pango_context ());
858 layout->set_text (w.name);
859 layout->get_pixel_size (text_width, text_height);
861 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
862 cairo_set_source_rgba (cr, 0, 0, 0, .5);
865 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
866 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
867 pango_cairo_show_layout (cr, layout->gobj ());
872 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
874 if (!midi) { i += n_midi; }
875 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
878 const PluginPinDialog::CtrlWidget&
879 PluginPinDialog::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
881 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
882 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
887 fatal << string_compose (_("programming error: %1"),
888 X_("Invalid Plugin I/O Port."))
890 abort (); /*NOTREACHED*/
891 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
892 return screw_old_compilers;
896 PluginPinDialog::edge_coordinates (const CtrlWidget& w, double &x, double &y)
924 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
926 const double bz = 2 * _pin_box_size;
927 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
928 if (x0 > _width * .5) { bc *= -1; }
930 cairo_move_to (cr, x0, y0);
932 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
934 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
936 cairo_set_line_width (cr, 3.0);
937 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
938 cairo_set_source_rgb (cr, 1, 0, 0);
940 const double dashes[] = { 5, 7 };
941 cairo_set_dash (cr, dashes, 2, 0);
943 set_color (cr, midi);
946 cairo_set_dash (cr, 0, 0, 0);
951 PluginPinDialog::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
953 double x0, x1, y0, y1;
954 edge_coordinates (w0, x0, y0);
955 edge_coordinates (w1, x1, y1);
956 assert (w0.e->dt == w1.e->dt);
957 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
962 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
964 Gtk::Allocation a = darea.get_allocation ();
965 double const width = a.get_width ();
966 double const height = a.get_height ();
968 if (!_position_valid) {
971 update_element_pos ();
972 _position_valid = true;
975 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
976 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
979 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
980 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
981 cairo_rectangle (cr, 0, 0, width, height);
984 const double yc = rint (_height * .5);
987 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
988 cairo_set_line_width (cr, 1.0);
989 cairo_set_source_rgb (cr, .1, .1, .3);
990 cairo_stroke_preserve (cr);
991 cairo_set_source_rgb (cr, .3, .3, .3);
995 Glib::RefPtr<Pango::Layout> layout;
996 layout = Pango::Layout::create (get_pango_context ());
998 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
999 layout->set_width (_height * PANGO_SCALE);
1004 layout->set_text (_route ()->name ());
1005 layout->get_pixel_size (text_width, text_height);
1007 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
1008 cairo_rotate (cr, M_PI * -.5);
1009 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1010 pango_cairo_show_layout (cr, layout->gobj ());
1011 cairo_new_path (cr);
1014 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
1015 layout->set_text (_pi->name ());
1016 layout->get_pixel_size (text_width, text_height);
1017 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
1018 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1019 pango_cairo_show_layout (cr, layout->gobj ());
1022 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
1023 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
1024 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
1025 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
1026 } else if (_pi->signal_latency () > 0) {
1027 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
1029 layout->set_text (_("no-inplace"));
1031 layout->get_pixel_size (text_width, text_height);
1032 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
1033 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1034 pango_cairo_show_layout (cr, layout->gobj ());
1038 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1039 layout->set_text (_("Strict I/O"));
1040 layout->get_pixel_size (text_width, text_height);
1041 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1042 const double sy0 = _height - 3 - text_height;
1044 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1045 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1048 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1049 cairo_move_to (cr, sx0, sy0);
1050 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1051 pango_cairo_show_layout (cr, layout->gobj ());
1054 /* draw midi-bypass (behind) */
1055 if (_has_midi_bypass) {
1056 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1057 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1058 draw_connection (cr, cw0, cw1, true);
1061 /* thru connections */
1062 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1063 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1064 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1065 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1066 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1067 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1068 draw_connection (cr, cw1, cw0, true);
1073 /* plugins & connection wires */
1074 for (uint32_t i = 0; i < _n_plugins; ++i) {
1075 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1078 cairo_set_source_rgb (cr, .5, .5, .5);
1079 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1082 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1083 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1084 layout->get_pixel_size (text_width, text_height);
1085 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1086 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1087 pango_cairo_show_layout (cr, layout->gobj ());
1089 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1090 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1092 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1093 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1094 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1095 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1096 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1097 draw_connection (cr, cw0, cw1);
1102 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1103 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1104 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1105 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1106 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1107 draw_connection (cr, cw0, cw1);
1113 /* pins and ports */
1114 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1118 draw_io_pin (cr, *i);
1122 draw_plugin_pin (cr, *i);
1128 CtrlWidget *drag_src = NULL;
1130 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1131 if (i->e == _selection ) {
1139 if (_selection->ct == Input || _selection->ct == Source) {
1140 edge_coordinates (*drag_src, x0, y0);
1141 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1142 _selection->dt == DataType::MIDI, _selection->sc);
1144 edge_coordinates (*drag_src, x0, y0);
1145 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1146 _selection->dt == DataType::MIDI, _selection->sc);
1155 PluginPinDialog::darea_size_request (Gtk::Requisition* req)
1157 req->width = _min_width;
1158 req->height = _min_height;
1162 PluginPinDialog::darea_size_allocate (Gtk::Allocation&)
1164 _position_valid = false;
1168 PluginPinDialog::drag_type_matches (const CtrlElem& e)
1170 if (!_dragging || !_selection) {
1173 if (_selection->dt != e->dt) {
1176 if (_selection->ct == Input && e->ct == Sink) { return true; }
1177 if (_selection->ct == Sink && e->ct == Input) { return true; }
1178 if (_selection->ct == Output && e->ct == Source) { return true; }
1179 if (_selection->ct == Source && e->ct == Output) { return true; }
1180 if (_selection->ct == Input && e->ct == Output) { return true; }
1181 if (_selection->ct == Output && e->ct == Input) { return true; }
1186 PluginPinDialog::start_drag (const CtrlElem& e, double x, double y)
1188 assert (_selection == e);
1190 if (e->ct == Sink) {
1192 const ChanMapping& map (_in_map[e->ip]);
1193 uint32_t idx = map.get (e->dt, e->id, &valid);
1195 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1200 else if (e->ct == Output) {
1201 for (uint32_t i = 0; i < _n_plugins; ++i) {
1203 const ChanMapping& map (_out_map[i]);
1204 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1206 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1214 const ChanMapping& map (_thru_map);
1215 uint32_t idx = map.get (e->dt, e->id, &valid);
1217 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1229 PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev)
1231 bool changed = false;
1233 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1234 if (ev->x >= i->x && ev->x <= i->x + i->w
1235 && ev->y >= i->y && ev->y <= i->y + i->h
1236 && drag_type_matches (i->e))
1238 if (!i->prelight) changed = true;
1242 if (i->prelight) changed = true;
1243 i->prelight = false;
1250 if (changed || _dragging) {
1251 darea.queue_draw ();
1257 PluginPinDialog::darea_button_press_event (GdkEventButton* ev)
1259 if (ev->type != GDK_BUTTON_PRESS) {
1263 switch (ev->button) {
1266 if (!_selection || (_selection && !_hover)) {
1267 _selection = _hover;
1270 start_drag (_selection, ev->x, ev->y);
1272 darea.queue_draw ();
1274 } else if (_selection && _hover && _selection != _hover) {
1275 if (_selection->dt != _hover->dt) { _actor.reset (); }
1276 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1277 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1278 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1279 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1280 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1281 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1283 _selection = _hover;
1284 start_drag (_selection, ev->x, ev->y);
1286 darea.queue_draw ();
1288 } else if (_hover) {
1289 _selection = _hover;
1291 start_drag (_selection, ev->x, ev->y);
1296 if (_selection != _hover) {
1297 _selection = _hover;
1298 darea.queue_draw ();
1310 PluginPinDialog::darea_button_release_event (GdkEventButton* ev)
1312 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1313 // select click. (or re-connect same)
1314 assert (_selection != _hover);
1319 darea.queue_draw ();
1323 if (_dragging && _hover && _hover != _selection) {
1327 if (_hover == _actor && _actor && ev->button == 1) {
1328 assert (_selection);
1329 assert (_selection->dt == _actor->dt);
1331 assert (_dragging && _selection != _drag_dst);
1332 handle_disconnect (_drag_dst, true);
1334 if (_selection->ct == Input && _actor->ct == Sink) {
1335 handle_input_action (_actor, _selection);
1337 else if (_selection->ct == Sink && _actor->ct == Input) {
1338 handle_input_action (_selection, _actor);
1340 else if (_selection->ct == Output && _actor->ct == Source) {
1341 handle_output_action (_actor, _selection);
1343 else if (_selection->ct == Source && _actor->ct == Output) {
1344 handle_output_action (_selection, _actor);
1346 else if (_selection->ct == Input && _actor->ct == Output) {
1347 handle_thru_action (_actor, _selection);
1349 else if (_selection->ct == Output && _actor->ct == Input) {
1350 handle_thru_action (_selection, _actor);
1352 _selection.reset ();
1353 } else if (_hover == _selection && _selection && ev->button == 3) {
1354 handle_disconnect (_selection);
1355 } else if (!_hover && ev->button == 3) {
1356 reset_menu.popup (1, ev->time);
1359 if (_dragging && _hover != _selection) {
1360 _selection.reset ();
1365 darea.queue_draw ();
1370 PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1372 const int pc = s->ip;
1374 ChanMapping in_map (_pi->input_map (pc));
1375 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1377 if (valid && idx == i->id) {
1380 in_map.unset (s->dt, s->id);
1381 _pi->set_input_map (pc, in_map);
1383 plugin_reconfigured ();
1388 in_map.set (s->dt, s->id, i->id);
1389 _pi->set_input_map (pc, in_map);
1393 in_map.unset (s->dt, s->id);
1394 in_map.set (s->dt, s->id, i->id);
1395 _pi->set_input_map (pc, in_map);
1400 PluginPinDialog::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1402 _ignore_updates = true;
1403 for (uint32_t n = 0; n < _n_plugins; ++n) {
1408 ChanMapping n_out_map (_pi->output_map (n));
1409 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1411 n_out_map.unset (dt, idx);
1412 _pi->set_output_map (n, n_out_map);
1415 _ignore_updates = false;
1419 PluginPinDialog::disconnect_other_thru (DataType dt, uint32_t id)
1421 _ignore_updates = true;
1423 ChanMapping n_thru_map (_pi->thru_map ());
1424 n_thru_map.get (dt, id, &valid);
1426 n_thru_map.unset (dt, id);
1427 _pi->set_thru_map (n_thru_map);
1429 _ignore_updates = false;
1433 PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1435 const uint32_t pc = s->ip;
1437 ChanMapping out_map (_pi->output_map (pc));
1438 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1440 if (valid && idx == o->id) {
1443 out_map.unset (s->dt, s->id);
1444 _pi->set_output_map (pc, out_map);
1446 plugin_reconfigured ();
1450 // disconnect source
1451 disconnect_other_outputs (pc, s->dt, o->id);
1452 disconnect_other_thru (s->dt, o->id);
1453 out_map = _pi->output_map (pc); // re-read map
1455 out_map.unset (s->dt, s->id);
1457 idx = out_map.get_src (s->dt, o->id, &valid);
1459 out_map.unset (s->dt, idx);
1462 out_map.set (s->dt, s->id, o->id);
1463 _pi->set_output_map (pc, out_map);
1468 PluginPinDialog::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1471 ChanMapping thru_map (_pi->thru_map ());
1472 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1474 if (valid && idx == i->id) {
1476 thru_map.unset (o->dt, o->id);
1479 // disconnect other outputs first
1480 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1481 disconnect_other_thru (o->dt, o->id);
1482 thru_map = _pi->thru_map (); // re-read map
1484 thru_map.set (o->dt, o->id, i->id);
1486 _pi->set_thru_map (thru_map);
1490 PluginPinDialog::handle_disconnect (const CtrlElem &e, bool no_signal)
1492 _ignore_updates = true;
1493 bool changed = false;
1499 ChanMapping n_thru_map (_pi->thru_map ());
1500 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1501 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1502 if (valid && idx == e->id) {
1503 n_thru_map.unset (e->dt, i);
1508 _pi->set_thru_map (n_thru_map);
1511 for (uint32_t n = 0; n < _n_plugins; ++n) {
1512 ChanMapping map (_pi->input_map (n));
1513 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1514 uint32_t idx = map.get (e->dt, i, &valid);
1515 if (valid && idx == e->id) {
1516 map.unset (e->dt, i);
1520 _pi->set_input_map (n, map);
1525 ChanMapping map (_pi->input_map (e->ip));
1526 map.get (e->dt, e->id, &valid);
1528 map.unset (e->dt, e->id);
1529 _pi->set_input_map (e->ip, map);
1536 ChanMapping map (_pi->output_map (e->ip));
1537 map.get (e->dt, e->id, &valid);
1539 map.unset (e->dt, e->id);
1540 _pi->set_output_map (e->ip, map);
1546 for (uint32_t n = 0; n < _n_plugins; ++n) {
1547 ChanMapping map (_pi->output_map (n));
1548 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1549 uint32_t idx = map.get (e->dt, i, &valid);
1550 if (valid && idx == e->id) {
1551 map.unset (e->dt, i);
1556 _pi->set_output_map (n, map);
1560 ChanMapping n_thru_map (_pi->thru_map ());
1561 n_thru_map.get (e->dt, e->id, &valid);
1563 n_thru_map.unset (e->dt, e->id);
1565 _pi->set_thru_map (n_thru_map);
1570 _ignore_updates = false;
1571 if (changed && !no_signal) {
1572 plugin_reconfigured ();
1578 PluginPinDialog::toggle_sidechain ()
1580 if (_session && _session->actively_recording ()) { return; }
1581 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1585 PluginPinDialog::connect_sidechain ()
1587 if (!_session) { return; }
1589 if (_sidechain_selector == 0) {
1590 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1593 if (_sidechain_selector->is_visible ()) {
1594 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1596 _sidechain_selector->present ();
1601 PluginPinDialog::reset_configuration ()
1603 if (_set_config.get_active ()) {
1604 _route ()->reset_plugin_insert (_pi);
1606 _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
1611 PluginPinDialog::reset_mapping ()
1617 PluginPinDialog::select_output_preset (uint32_t n_audio)
1619 if (_session && _session->actively_recording ()) { return; }
1620 ChanCount out (DataType::AUDIO, n_audio);
1621 _route ()->plugin_preset_output (_pi, out);
1625 PluginPinDialog::add_remove_plugin_clicked (bool add)
1627 if (_session && _session->actively_recording ()) { return; }
1628 ChanCount out = _out;
1629 ChanCount sinks = _sinks;
1630 assert (add || _n_plugins > 0);
1631 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks);
1635 PluginPinDialog::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1637 if (_session && _session->actively_recording ()) { return; }
1638 ChanCount out = _out;
1639 ChanCount sinks = _sinks;
1640 assert (add || out.get (dt) > 0);
1641 out.set (dt, out.get (dt) + (add ? 1 : -1));
1642 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1646 PluginPinDialog::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
1648 if (_session && _session->actively_recording ()) { return; }
1649 ChanCount out = _out;
1650 ChanCount sinks = _sinks;
1651 assert (add || sinks.get (dt) > 0);
1652 sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
1653 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1657 PluginPinDialog::add_sidechain_port (DataType dt)
1659 if (_session && _session->actively_recording ()) { return; }
1660 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1665 // this triggers a PluginIoReConfigure with process and processor write lock held
1666 // from /this/ thread.
1667 io->add_port ("", this, dt);
1671 PluginPinDialog::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1673 if (_session && _session->actively_recording ()) { return; }
1674 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1675 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1679 io->remove_port (p, this);
1683 PluginPinDialog::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1685 if (_session && _session->actively_recording ()) { return; }
1686 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1687 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1691 p->disconnect_all ();
1695 PluginPinDialog::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1697 if (_session && _session->actively_recording ()) { return; }
1698 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1699 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1700 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1701 if (!io || !p0 || !p1) {
1704 _ignore_updates = true;
1705 p0->disconnect_all ();
1706 _ignore_updates = false;
1707 p0->connect (p1->name ());
1711 PluginPinDialog::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1713 if (_session && _session->actively_recording ()) { return; }
1714 boost::shared_ptr<Port> p = wp.lock ();
1715 boost::shared_ptr<Route> r = wr.lock ();
1716 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1717 if (!p || !r || !io || !_session) {
1721 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1722 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1723 const ChanCount& outs (r->amp ()->input_streams ());
1725 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1726 send->output()->ensure_io (outs, false, this);
1727 } catch (AudioEngine::PortRegistrationFailure& err) {
1728 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1732 std::string sendname = send->name ();
1733 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1734 if (last_letter != string::npos) {
1735 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1737 sendname.substr (last_letter + 1)));
1740 _ignore_updates = true;
1741 p->disconnect_all ();
1743 DataType dt = p->type ();
1744 PortSet& ps (send->output ()->ports ());
1745 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1746 p->connect (&(**i));
1749 send->set_remove_on_disconnect (true);
1750 r->add_processor (send, PreFader);
1751 _ignore_updates = false;
1752 queue_idle_update ();
1756 PluginPinDialog::sc_input_release (GdkEventButton *ev)
1758 if (_session && _session->actively_recording ()) { return false; }
1759 if (ev->button == 3) {
1760 connect_sidechain ();
1765 struct RouteCompareByName {
1766 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1767 return a->name ().compare (b->name ()) < 0;
1772 PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1774 using namespace Menu_Helpers;
1775 if (!_session || _session->actively_recording ()) { return false; }
1776 if (!_session->engine ().connected ()) { return false; }
1778 if (ev->button == 1) {
1779 MenuList& citems = input_menu.items ();
1780 input_menu.set_name ("ArdourContextMenu");
1783 boost::shared_ptr<Port> p = wp.lock ();
1784 if (p && p->connected ()) {
1785 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::disconnect_port), wp)));
1786 citems.push_back (SeparatorElem ());
1790 // TODO add system inputs, too ?!
1791 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1792 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1793 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1795 //maybe_add_bundle_to_input_menu (*i, current);
1799 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1800 RouteList copy = *routes;
1801 copy.sort (RouteCompareByName ());
1803 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1804 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1808 citems.push_back (SeparatorElem ());
1810 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinDialog::connect_sidechain)));
1811 input_menu.popup (1, ev->time);
1817 PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1820 using namespace Menu_Helpers;
1821 if (r->output () == _route ()->output ()) {
1825 if (_route ()->feeds_according_to_graph (r)) {
1829 MenuList& citems = input_menu.items ();
1831 /*check if there's already a send.. */
1832 bool already_present = false;
1834 boost::shared_ptr<Processor> proc;
1835 /* Note: nth_send () takes a processor read-lock */
1836 while ((proc = r->nth_send (nth))) {
1837 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1838 if (!send || !send->output ()) {
1842 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1843 // only if (send->remove_on_disconnect ()) ??
1844 already_present = true;
1849 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1850 const ChanCount& rc (r->amp ()->input_streams ());
1851 if (!already_present && rc.get (dt) > 0) {
1852 citems.push_back (MenuElem (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::add_send_from), wp, boost::weak_ptr<Route> (r))));
1859 PluginPinDialog::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1861 boost::shared_ptr<Port> p0 = w0.lock ();
1862 boost::shared_ptr<Port> p1 = w1.lock ();
1864 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1865 if (!io) { return; }
1867 if (p0 && io->has_port (p0)) {
1868 queue_idle_update ();
1870 else if (p1 && io->has_port (p1)) {
1871 queue_idle_update ();
1875 /* lifted from ProcessorEntry::Control */
1876 PluginPinDialog::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1878 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1879 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1880 , _slider_persistant_tooltip (&_slider)
1881 , _ignore_ui_adjustment (false)
1884 _slider.set_controllable (c);
1885 box.set_padding (0, 0, 4, 4);
1887 _slider.set_name ("ProcessorControlSlider");
1888 _slider.set_text (_name);
1893 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1894 double const lo = c->internal_to_interface (desc.lower);
1895 double const up = c->internal_to_interface (desc.upper);
1896 double const normal = c->internal_to_interface (desc.normal);
1897 double smallstep = desc.smallstep;
1898 double largestep = desc.largestep;
1900 if (smallstep == 0.0) {
1901 smallstep = up / 1000.;
1903 smallstep = c->internal_to_interface (desc.lower + smallstep);
1906 if (largestep == 0.0) {
1907 largestep = up / 40.;
1909 largestep = c->internal_to_interface (desc.lower + largestep);
1912 _adjustment.set_lower (lo);
1913 _adjustment.set_upper (up);
1914 _adjustment.set_step_increment (smallstep);
1915 _adjustment.set_page_increment (largestep);
1916 _slider.set_default_value (normal);
1918 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1919 // dup. currently timers are used :(
1920 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1922 // yuck, do we really need to do this?
1923 // according to c404374 this is only needed for send automation
1924 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1929 /* We're providing our own PersistentTooltip */
1930 set_no_tooltip_whatsoever (_slider);
1933 PluginPinDialog::Control::~Control ()
1935 timer_connection.disconnect ();
1939 PluginPinDialog::Control::set_tooltip ()
1941 boost::shared_ptr<AutomationControl> c = _control.lock ();
1946 snprintf (tmp, sizeof (tmp), "%s: %.2f", _name.c_str (), c->internal_to_user (c->get_value ()));
1948 string sm = Gtkmm2ext::markup_escape_text (tmp);
1949 _slider_persistant_tooltip.set_tip (sm);
1953 PluginPinDialog::Control::slider_adjusted ()
1955 if (_ignore_ui_adjustment) {
1958 boost::shared_ptr<AutomationControl> c = _control.lock ();
1962 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1968 PluginPinDialog::Control::control_changed ()
1970 boost::shared_ptr<AutomationControl> c = _control.lock ();
1975 _ignore_ui_adjustment = true;
1977 // as long as rapid timers are used, only update the tooltip
1978 // if the value has changed.
1979 const double nval = c->internal_to_interface (c->get_value ());
1980 if (_adjustment.get_value () != nval) {
1981 _adjustment.set_value (nval);
1985 _ignore_ui_adjustment = false;