2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2011 Paul Davis
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <boost/algorithm/string.hpp>
22 #include <gtkmm/table.h>
23 #include <gtkmm/frame.h>
24 #include <gtkmm/label.h>
26 #include "pbd/replace_all.h"
28 #include "gtkmm2ext/utils.h"
29 #include "gtkmm2ext/rgb_macros.h"
31 #include "ardour/amp.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/pannable.h"
34 #include "ardour/plugin.h"
35 #include "ardour/port.h"
36 #include "ardour/profile.h"
37 #include "ardour/send.h"
38 #include "ardour/session.h"
40 #include "plugin_pin_dialog.h"
41 #include "gui_thread.h"
44 #include "ui_config.h"
48 using namespace ARDOUR;
52 using namespace Gtkmm2ext;
54 PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
55 : _set_config (_("Manual Config"), ArdourButton::led_default_elements)
56 , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements)
57 , _add_plugin (_("+"))
58 , _del_plugin (_("-"))
59 , _add_input_audio (_("+"))
60 , _del_input_audio (_("-"))
61 , _add_input_midi (_("+"))
62 , _del_input_midi (_("-"))
63 , _add_output_audio (_("+"))
64 , _del_output_audio (_("-"))
65 , _add_output_midi (_("+"))
66 , _del_output_midi (_("-"))
67 , _add_sc_audio (_("Audio"))
68 , _add_sc_midi (_("MIDI"))
80 , _position_valid (false)
81 , _ignore_updates (false)
82 , _sidechain_selector (0)
85 assert (pi->owner ()); // Route
87 _pi->PluginIoReConfigure.connect (
88 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
91 _pi->PluginMapChanged.connect (
92 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
95 _pi->PluginConfigChanged.connect (
96 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
99 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
100 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
101 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
103 _tgl_sidechain.set_name ("pinrouting sidechain");
104 _set_config.set_name ("pinrouting custom");
106 Menu_Helpers::MenuList& citems = reset_menu.items ();
107 reset_menu.set_name ("ArdourContextMenu");
109 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinWidget::reset_mapping)));
111 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
112 _add_plugin.set_tweaks (ArdourButton::Square);
113 _del_plugin.set_tweaks (ArdourButton::Square);
114 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
115 _pm_size_group->add_widget (_add_input_audio);
116 _pm_size_group->add_widget (_del_input_audio);
117 _pm_size_group->add_widget (_add_input_midi);
118 _pm_size_group->add_widget (_del_input_midi);
120 _pm_size_group->add_widget (_add_plugin);
121 _pm_size_group->add_widget (_del_plugin);
123 _pm_size_group->add_widget (_add_output_audio);
124 _pm_size_group->add_widget (_del_output_audio);
125 _pm_size_group->add_widget (_add_output_midi);
126 _pm_size_group->add_widget (_del_output_midi);
131 VBox* tl = manage (new VBox ());
132 tl->set_border_width (2);
135 VBox* tr = manage (new VBox ());
136 tr->set_border_width (2);
140 tl->pack_start (_set_config, false, false);
142 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
143 box = manage (new HBox ());
144 box->set_border_width (2);
145 box->pack_start (_add_input_audio, true, false);
146 box->pack_start (_del_input_audio, true, false);
147 f = manage (new Frame ());
148 f->set_label (_("Audio Input Pins"));
150 tl->pack_start (*f, false, false);
152 box = manage (new HBox ());
153 box->set_border_width (2);
154 box->pack_start (_add_input_midi, true, false);
155 box->pack_start (_del_input_midi, true, false);
156 f = manage (new Frame ());
157 f->set_label (_("MIDI Input Pins"));
159 tl->pack_start (*f, false, false);
161 box = manage (new HBox ());
162 box->set_border_width (2);
163 box->pack_start (_add_plugin, true, false);
164 box->pack_start (_del_plugin, true, false);
165 f = manage (new Frame ());
166 f->set_label (_("Instances"));
168 tl->pack_start (*f, false, false);
171 box = manage (new HBox ());
172 box->set_border_width (2);
173 box->pack_start (_add_output_audio, true, false);
174 box->pack_start (_del_output_audio, true, false);
175 f = manage (new Frame ());
176 f->set_label (_("Audio Out"));
178 tl->pack_start (*f, false, false);
180 box = manage (new HBox ());
181 box->set_border_width (2);
182 box->pack_start (_add_output_midi, true, false);
183 box->pack_start (_del_output_midi, true, false);
184 f = manage (new Frame ());
185 f->set_label (_("MIDI Out"));
187 tl->pack_start (*f, false, false);
189 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
190 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
191 _out_presets.disable_scrolling ();
192 ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
193 tl->pack_start (_out_presets, false, false);
196 _sidechain_tbl = manage (new Gtk::Table ());
197 _sidechain_tbl->set_spacings (2);
199 tr->pack_start (_tgl_sidechain, false, false);
200 tr->pack_start (*_sidechain_tbl, true, true);
202 box = manage (new VBox ());
203 box->set_border_width (2);
204 box->set_spacing (2);
205 box->pack_start (_add_sc_audio, false, false);
206 box->pack_start (_add_sc_midi , false, false);
207 f = manage (new Frame ());
208 f->set_label (_("Add Sidechain Input"));
211 tr->pack_start (*f, false, false);
214 HBox* hbox = manage (new HBox ());
215 hbox->set_spacing (4);
216 hbox->pack_start (*tl, false, false);
217 hbox->pack_start (darea, true, true);
218 hbox->pack_start (*tr, false, false);
220 pack_start (*hbox, true, true);
221 set_border_width (4);
224 plugin_reconfigured ();
226 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
227 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_request));
228 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_allocate));
229 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_expose_event));
230 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_press_event));
231 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_release_event));
232 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_motion_notify_event));
234 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::toggle_sidechain));
236 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::reset_configuration));
237 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), true));
238 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), false));
240 _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::AUDIO));
241 _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::AUDIO));
242 _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::MIDI));
243 _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::MIDI));
245 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::AUDIO));
246 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::AUDIO));
247 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::MIDI));
248 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::MIDI));
250 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::AUDIO));
251 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::MIDI));
253 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
254 _io_connection, invalidator (*this), boost::bind (&PluginPinWidget::port_connected_or_disconnected, this, _1, _3), gui_context ()
258 PluginPinWidget::~PluginPinWidget ()
260 delete _sidechain_selector;
264 PluginPinWidget::set_session (ARDOUR::Session *s)
266 SessionHandlePtr::set_session (s);
267 plugin_reconfigured ();
271 PluginPinWidget::queue_idle_update ()
273 /* various actions here are directly executed, in the GUI thread,
274 * with the GUI-thread eventually taking the process and processor lock.
275 * "connect gui_context()" will call back immediately and this
276 * signal-handler will run with the locks held.
278 * This will lead to a crash with calling nth_send() which takes
279 * a processor read-lock while holding a write lock in the same thread.
281 * decouple update to GUI idle.
283 * BUT, do delete existing controls here (in case they're affected by
284 * the change and hit by the Timer before idle comes around)
286 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
287 _sidechain_tbl->remove ((*i)->box);
291 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinWidget::idle_update));
295 PluginPinWidget::idle_update ()
297 plugin_reconfigured ();
303 PluginPinWidget::plugin_reconfigured ()
305 ENSURE_GUI_THREAD (*this, &PluginPinWidget::plugin_reconfigured);
306 if (_ignore_updates) {
309 _n_plugins = _pi->get_count ();
310 _pi->configured_io (_in, _out);
311 _ins = _pi->internal_streams (); // with sidechain
312 _sinks = _pi->natural_input_streams ();
313 _sources = _pi->natural_output_streams ();
316 _tgl_sidechain.set_active (_pi->has_sidechain ());
317 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
318 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
320 if (_pi->custom_cfg ()) {
321 _set_config.set_active (true);
322 _add_plugin.set_sensitive (true);
323 _del_plugin.set_sensitive (_n_plugins > 1);
324 _add_output_audio.set_sensitive (true);
325 _add_output_midi.set_sensitive (true);
326 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
327 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
328 _add_input_audio.set_sensitive (true);
329 _add_input_midi.set_sensitive (true);
330 _del_input_audio.set_sensitive (_sinks.n_audio () > 0 && _sinks.n_total () > 1);
331 _del_input_midi.set_sensitive (_sinks.n_midi () > 0 && _sinks.n_total () > 1);
332 _out_presets.set_sensitive (false);
333 _out_presets.set_text (_("Manual"));
335 _set_config.set_active (false);
336 _add_plugin.set_sensitive (false);
337 _del_plugin.set_sensitive (false);
338 _add_input_audio.set_sensitive (false);
339 _add_input_midi.set_sensitive (false);
340 _del_input_audio.set_sensitive (false);
341 _del_input_midi.set_sensitive (false);
342 _add_output_audio.set_sensitive (false);
343 _add_output_midi.set_sensitive (false);
344 _del_output_audio.set_sensitive (false);
345 _del_output_midi.set_sensitive (false);
346 _out_presets.set_sensitive (true);
347 refill_output_presets ();
350 if (!_pi->has_sidechain () && _sidechain_selector) {
351 delete _sidechain_selector;
352 _sidechain_selector = 0;
355 refill_sidechain_table ();
357 /* update elements */
366 _n_inputs = _n_sidechains = 0;
368 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
369 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
370 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
371 bool sidechain = id >= _in.get (dt) ? true : false;
378 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
379 _elements.push_back (cw);
382 for (uint32_t i = 0; i < _out.n_total (); ++i) {
383 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
384 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
390 for (uint32_t n = 0; n < _n_plugins; ++n) {
391 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
392 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
393 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
394 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
395 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
396 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
397 _elements.push_back (cw);
399 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
400 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
401 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
402 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
403 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
405 _in_map[n] = _pi->input_map (n);
406 _out_map[n] = _pi->output_map (n);
408 _has_midi_bypass = _pi->has_midi_bypass ();
409 _thru_map = _pi->thru_map ();
413 /* calc minimum size */
414 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
415 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
416 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
417 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
418 min_width = std::max ((uint32_t)300, min_width);
420 min_width = 50 + 10 * ceilf (min_width / 10.f);
422 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
423 min_height = std::max ((uint32_t)200, min_height);
424 min_height = 4 * ceilf (min_height / 4.f);
426 if (min_width != _min_width || min_height != _min_height) {
427 _min_width = min_width;
428 _min_height = min_height;
429 darea.queue_resize ();
432 _position_valid = false;
437 PluginPinWidget::refill_sidechain_table ()
439 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
440 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
443 _sidechain_tbl->resize (1, 1);
444 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
448 if (!_pi->has_sidechain () && _sidechain_selector) {
451 boost::shared_ptr<IO> io = _pi->sidechain_input ();
457 PortSet& p (io->ports ());
458 bool can_remove = p.num_ports () > 1;
459 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
460 r += add_port_to_table (*i, r, can_remove);
462 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
463 r += add_port_to_table (*i, r, can_remove);
465 _sidechain_tbl->show_all ();
469 PluginPinWidget::refill_output_presets ()
471 using namespace Menu_Helpers;
472 _out_presets.clear_items ();
473 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
475 bool need_dropdown = true;
477 if (ppc.size () == 0) {
478 need_dropdown = false;
481 if (!_pi->strict_io () && ppc.size () == 1) {
482 need_dropdown = false;
485 if (_pi->strict_io () && ppc.size () == 1) {
486 // "stereo" is currently preferred default for instruments, see PluginInsert
487 if (ppc.find (2) != ppc.end ()) {
488 need_dropdown = false;
492 if (!_pi->needs_midi_input ()) {
493 /* loose definition of instruments, maybe impose additional
494 * || _pi->natural_input_streams ().n_audio () != 0
495 * and special case variable output plugins
496 * && !_pi->plugin (0)->info->reconfigurable_io()
498 need_dropdown = false;
501 if (!need_dropdown) {
502 _out_presets.set_sensitive (false);
503 _out_presets.set_text (_("Automatic"));
507 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), 0)));
509 const uint32_t n_audio = _pi->preset_out ().n_audio ();
511 _out_presets.set_text (_("Automatic"));
514 if (ppc.find (0) != ppc.end ()) {
518 ppc.insert (n_audio);
528 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
539 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
542 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), *i)));
544 _out_presets.set_text (tmp);
550 PluginPinWidget::port_label (const std::string& portname, bool strip)
552 // compare to MixerStrip::update_io_button()
553 string lpn (PROGRAM_NAME);
554 boost::to_lower (lpn);
555 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
557 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
559 string::size_type slash = pn.find ("/");
560 if (slash != string::npos) {
561 pn = pn.substr (0, slash);
565 std::string label (portname);
566 if (label.find ("system:capture_") == 0) {
567 if (label.empty ()) {
568 label = portname.substr (15);
570 } else if (label.find ("system:midi_capture_") == 0) {
571 if (label.empty ()) {
572 // "system:midi_capture_123" -> "123"
573 label = "M " + portname.substr (20);
575 } else if (label.find (program_port_prefix) == 0) {
576 label = label.substr (program_port_prefix.size ());
578 string::size_type slash = label.find ("/");
579 if (slash != string::npos) {
580 label = label.substr (0, slash);
588 PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
591 std::string tip = p->name ();
592 std::vector<std::string> cns;
593 bool single_source = true;
594 p->get_connections (cns);
596 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
598 lbl = port_label (*i, true);
601 if (port_label (*i, true) != lbl) {
603 single_source = false;
608 if (cns.size () == 0) {
610 single_source = false;
611 } else if (cns.size () == 1) {
613 lbl = port_label (cns[0], false);
617 replace_all (lbl, "_", " ");
619 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
624 ArdourButton *pb = manage (new ArdourButton (lbl));
625 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
626 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
627 ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
628 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
630 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr<Port> (p)), false);
631 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::sc_input_release), false);
633 pb = manage (new ArdourButton ("-"));
634 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
636 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::remove_port), boost::weak_ptr<Port> (p)));
638 pb->set_sensitive (false);
643 if (single_source && _session) {
644 /* check if it's an Ardour Send feeding.. */
645 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
646 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
648 boost::shared_ptr<Processor> proc;
649 /* nth_send () takes a processor read-lock */
650 while ((proc = (*i)->nth_send (nth))) {
651 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
652 if (!send || !send->output ()) {
656 if (!send->output ()->connected_to (p->name ())) {
660 /* if processor goes away, we're notified by the port disconnect,
661 * there should be no need to explicily connect to proc->DropReferences
663 set<Evoral::Parameter> p = proc->what_can_be_automated ();
664 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
665 Control* c = new Control (proc->automation_control (*i), _("Send"));
666 _controls.push_back (c);
668 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
678 PluginPinWidget::update_element_pos ()
681 _innerwidth = _width - 2. * _margin_x;
683 const double yc = rint (_height * .5);
684 const double bxh2 = rint (_margin_y * .45); // TODO grow?
685 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
686 const double bxw2 = rint (bxw * .5);
687 const double y_in = _margin_y;
688 const double y_out = _height - _margin_y;
693 const double dx = _pin_box_size * .5;
696 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
700 i->x = _innerwidth + _margin_x - dx;
701 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
702 i->h = _pin_box_size;
703 i->w = 1.5 * _pin_box_size;
706 uint32_t idx = i->e->id;
707 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
708 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
709 i->w = _pin_box_size;
710 i->h = 1.5 * _pin_box_size;
716 uint32_t idx = i->e->id;
717 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
718 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
720 i->w = _pin_box_size;
721 i->h = 1.5 * _pin_box_size;
726 uint32_t idx = i->e->id;
727 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
728 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
729 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
730 i->y = yc - bxh2 - dx;
731 i->w = _pin_box_size;
732 i->h = _pin_box_size;
737 uint32_t idx = i->e->id;
738 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
739 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
740 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
741 i->y = yc + bxh2 - dx;
742 i->w = _pin_box_size;
743 i->h = _pin_box_size;
751 PluginPinWidget::set_color (cairo_t* cr, bool midi)
753 // see also gtk2_ardour/processor_box.cc
754 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
755 static const uint32_t midi_port_color = 0x960909FF; //Red
758 cairo_set_source_rgb (cr,
759 UINT_RGBA_R_FLT (midi_port_color),
760 UINT_RGBA_G_FLT (midi_port_color),
761 UINT_RGBA_B_FLT (midi_port_color));
763 cairo_set_source_rgb (cr,
764 UINT_RGBA_R_FLT (audio_port_color),
765 UINT_RGBA_G_FLT (audio_port_color),
766 UINT_RGBA_B_FLT (audio_port_color));
771 PluginPinWidget::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
774 const double dy = w.h * .5;
775 const double dx = w.w - dy;
776 cairo_move_to (cr, w.x, w.y + dy);
777 cairo_rel_line_to (cr, dy, -dy);
778 cairo_rel_line_to (cr, dx, 0);
779 cairo_rel_line_to (cr, 0, w.h);
780 cairo_rel_line_to (cr, -dx, 0);
782 const double dir = (w.e->ct == Input) ? 1 : -1;
783 const double dx = w.w * .5;
784 const double dy = w.h - dx;
786 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
787 cairo_rel_line_to (cr, -dx, -dx * dir);
788 cairo_rel_line_to (cr, 0., -dy * dir);
789 cairo_rel_line_to (cr, 2. * dx, 0.);
790 cairo_rel_line_to (cr, 0., dy * dir);
792 cairo_close_path (cr);
794 cairo_set_line_width (cr, 1.0);
795 cairo_set_source_rgb (cr, 0, 0, 0);
796 cairo_stroke_preserve (cr);
798 set_color (cr, w.e->dt == DataType::MIDI);
801 assert (w.e->ct == Input);
802 cairo_fill_preserve (cr);
803 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
806 if (w.e == _selection || w.e == _actor) {
807 cairo_fill_preserve (cr);
808 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
809 } else if (w.prelight) {
810 cairo_fill_preserve (cr);
811 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
817 PluginPinWidget::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
819 const double dx = w.w * .5;
820 const double dy = w.h * .5;
822 cairo_move_to (cr, w.x + dx, w.y);
823 cairo_rel_line_to (cr, -dx, dy);
824 cairo_rel_line_to (cr, dx, dy);
825 cairo_rel_line_to (cr, dx, -dy);
826 cairo_close_path (cr);
828 cairo_set_line_width (cr, 1.0);
829 cairo_set_source_rgb (cr, 0, 0, 0);
830 cairo_stroke_preserve (cr);
832 set_color (cr, w.e->dt == DataType::MIDI);
835 assert (w.e->ct == Sink);
836 cairo_fill_preserve (cr);
837 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
840 if (w.e == _selection || w.e == _actor) {
841 cairo_fill_preserve (cr);
842 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
843 } else if (w.prelight) {
844 cairo_fill_preserve (cr);
845 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
849 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
852 Glib::RefPtr<Pango::Layout> layout;
853 layout = Pango::Layout::create (get_pango_context ());
854 layout->set_text (w.name);
855 layout->get_pixel_size (text_width, text_height);
857 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
858 cairo_set_source_rgba (cr, 0, 0, 0, .5);
861 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
862 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
863 pango_cairo_show_layout (cr, layout->gobj ());
868 PluginPinWidget::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
870 if (!midi) { i += n_midi; }
871 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
874 const PluginPinWidget::CtrlWidget&
875 PluginPinWidget::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
877 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
878 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
883 fatal << string_compose (_("programming error: %1"),
884 X_("Invalid Plugin I/O Port."))
886 abort (); /*NOTREACHED*/
887 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
888 return screw_old_compilers;
892 PluginPinWidget::edge_coordinates (const CtrlWidget& w, double &x, double &y)
920 PluginPinWidget::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
922 const double bz = 2 * _pin_box_size;
923 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
924 if (x0 > _width * .5) { bc *= -1; }
926 cairo_move_to (cr, x0, y0);
928 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
930 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
932 cairo_set_line_width (cr, 3.0);
933 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
934 cairo_set_source_rgb (cr, 1, 0, 0);
936 const double dashes[] = { 5, 7 };
937 cairo_set_dash (cr, dashes, 2, 0);
939 set_color (cr, midi);
942 cairo_set_dash (cr, 0, 0, 0);
947 PluginPinWidget::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
949 double x0, x1, y0, y1;
950 edge_coordinates (w0, x0, y0);
951 edge_coordinates (w1, x1, y1);
952 assert (w0.e->dt == w1.e->dt);
953 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
958 PluginPinWidget::darea_expose_event (GdkEventExpose* ev)
960 Gtk::Allocation a = darea.get_allocation ();
961 double const width = a.get_width ();
962 double const height = a.get_height ();
964 if (!_position_valid) {
967 update_element_pos ();
968 _position_valid = true;
971 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
972 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
975 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
976 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
977 cairo_rectangle (cr, 0, 0, width, height);
980 const double yc = rint (_height * .5);
983 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
984 cairo_set_line_width (cr, 1.0);
985 cairo_set_source_rgb (cr, .1, .1, .3);
986 cairo_stroke_preserve (cr);
987 cairo_set_source_rgb (cr, .3, .3, .3);
991 Glib::RefPtr<Pango::Layout> layout;
992 layout = Pango::Layout::create (get_pango_context ());
994 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
995 layout->set_width (_height * PANGO_SCALE);
1000 layout->set_text (_route ()->name ());
1001 layout->get_pixel_size (text_width, text_height);
1003 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
1004 cairo_rotate (cr, M_PI * -.5);
1005 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1006 pango_cairo_show_layout (cr, layout->gobj ());
1007 cairo_new_path (cr);
1010 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
1011 layout->set_text (_pi->name ());
1012 layout->get_pixel_size (text_width, text_height);
1013 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
1014 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1015 pango_cairo_show_layout (cr, layout->gobj ());
1018 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
1019 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
1020 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
1021 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
1022 } else if (_pi->signal_latency () > 0) {
1023 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
1025 layout->set_text (_("no-inplace"));
1027 layout->get_pixel_size (text_width, text_height);
1028 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
1029 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1030 pango_cairo_show_layout (cr, layout->gobj ());
1034 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1035 layout->set_text (_("Strict I/O"));
1036 layout->get_pixel_size (text_width, text_height);
1037 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1038 const double sy0 = _height - 3 - text_height;
1040 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1041 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1044 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1045 cairo_move_to (cr, sx0, sy0);
1046 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1047 pango_cairo_show_layout (cr, layout->gobj ());
1050 /* draw midi-bypass (behind) */
1051 if (_has_midi_bypass) {
1052 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1053 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1054 draw_connection (cr, cw0, cw1, true);
1057 /* thru connections */
1058 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1059 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1060 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1061 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1062 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1063 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1064 draw_connection (cr, cw1, cw0, true);
1069 /* plugins & connection wires */
1070 for (uint32_t i = 0; i < _n_plugins; ++i) {
1071 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1074 cairo_set_source_rgb (cr, .5, .5, .5);
1075 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1078 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1079 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1080 layout->get_pixel_size (text_width, text_height);
1081 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1082 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1083 pango_cairo_show_layout (cr, layout->gobj ());
1085 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1086 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1088 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1089 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1090 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1091 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1092 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1093 draw_connection (cr, cw0, cw1);
1098 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
1099 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1100 const CtrlWidget& cw0 = get_io_ctrl (Source, t->first, c->first, i);
1101 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1102 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1103 draw_connection (cr, cw0, cw1);
1109 /* pins and ports */
1110 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1114 draw_io_pin (cr, *i);
1118 draw_plugin_pin (cr, *i);
1124 CtrlWidget *drag_src = NULL;
1126 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1127 if (i->e == _selection ) {
1135 if (_selection->ct == Input || _selection->ct == Source) {
1136 edge_coordinates (*drag_src, x0, y0);
1137 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1138 _selection->dt == DataType::MIDI, _selection->sc);
1140 edge_coordinates (*drag_src, x0, y0);
1141 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1142 _selection->dt == DataType::MIDI, _selection->sc);
1151 PluginPinWidget::darea_size_request (Gtk::Requisition* req)
1153 req->width = _min_width;
1154 req->height = _min_height;
1158 PluginPinWidget::darea_size_allocate (Gtk::Allocation&)
1160 _position_valid = false;
1164 PluginPinWidget::drag_type_matches (const CtrlElem& e)
1166 if (!_dragging || !_selection) {
1169 if (_selection->dt != e->dt) {
1172 if (_selection->ct == Input && e->ct == Sink) { return true; }
1173 if (_selection->ct == Sink && e->ct == Input) { return true; }
1174 if (_selection->ct == Output && e->ct == Source) { return true; }
1175 if (_selection->ct == Source && e->ct == Output) { return true; }
1176 if (_selection->ct == Input && e->ct == Output) { return true; }
1177 if (_selection->ct == Output && e->ct == Input) { return true; }
1182 PluginPinWidget::start_drag (const CtrlElem& e, double x, double y)
1184 assert (_selection == e);
1186 if (e->ct == Sink) {
1188 const ChanMapping& map (_in_map[e->ip]);
1189 uint32_t idx = map.get (e->dt, e->id, &valid);
1191 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1196 else if (e->ct == Output) {
1197 for (uint32_t i = 0; i < _n_plugins; ++i) {
1199 const ChanMapping& map (_out_map[i]);
1200 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1202 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1210 const ChanMapping& map (_thru_map);
1211 uint32_t idx = map.get (e->dt, e->id, &valid);
1213 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1225 PluginPinWidget::darea_motion_notify_event (GdkEventMotion* ev)
1227 bool changed = false;
1229 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1230 if (ev->x >= i->x && ev->x <= i->x + i->w
1231 && ev->y >= i->y && ev->y <= i->y + i->h
1232 && drag_type_matches (i->e))
1234 if (!i->prelight) changed = true;
1238 if (i->prelight) changed = true;
1239 i->prelight = false;
1246 if (changed || _dragging) {
1247 darea.queue_draw ();
1253 PluginPinWidget::darea_button_press_event (GdkEventButton* ev)
1255 if (ev->type != GDK_BUTTON_PRESS) {
1259 switch (ev->button) {
1262 if (!_selection || (_selection && !_hover)) {
1263 _selection = _hover;
1266 start_drag (_selection, ev->x, ev->y);
1268 darea.queue_draw ();
1270 } else if (_selection && _hover && _selection != _hover) {
1271 if (_selection->dt != _hover->dt) { _actor.reset (); }
1272 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1273 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1274 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1275 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1276 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1277 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1279 _selection = _hover;
1280 start_drag (_selection, ev->x, ev->y);
1282 darea.queue_draw ();
1284 } else if (_hover) {
1285 _selection = _hover;
1287 start_drag (_selection, ev->x, ev->y);
1292 if (_selection != _hover) {
1293 _selection = _hover;
1294 darea.queue_draw ();
1306 PluginPinWidget::darea_button_release_event (GdkEventButton* ev)
1308 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1309 // select click. (or re-connect same)
1310 assert (_selection != _hover);
1315 darea.queue_draw ();
1319 if (_dragging && _hover && _hover != _selection) {
1323 if (_hover == _actor && _actor && ev->button == 1) {
1324 assert (_selection);
1325 assert (_selection->dt == _actor->dt);
1327 assert (_dragging && _selection != _drag_dst);
1328 handle_disconnect (_drag_dst, true);
1330 if (_selection->ct == Input && _actor->ct == Sink) {
1331 handle_input_action (_actor, _selection);
1333 else if (_selection->ct == Sink && _actor->ct == Input) {
1334 handle_input_action (_selection, _actor);
1336 else if (_selection->ct == Output && _actor->ct == Source) {
1337 handle_output_action (_actor, _selection);
1339 else if (_selection->ct == Source && _actor->ct == Output) {
1340 handle_output_action (_selection, _actor);
1342 else if (_selection->ct == Input && _actor->ct == Output) {
1343 handle_thru_action (_actor, _selection);
1345 else if (_selection->ct == Output && _actor->ct == Input) {
1346 handle_thru_action (_selection, _actor);
1348 _selection.reset ();
1349 } else if (_hover == _selection && _selection && ev->button == 3) {
1350 handle_disconnect (_selection);
1351 } else if (!_hover && ev->button == 3) {
1352 reset_menu.popup (1, ev->time);
1355 if (_dragging && _hover != _selection) {
1356 _selection.reset ();
1361 darea.queue_draw ();
1366 PluginPinWidget::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1368 const int pc = s->ip;
1370 ChanMapping in_map (_pi->input_map (pc));
1371 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1373 if (valid && idx == i->id) {
1376 in_map.unset (s->dt, s->id);
1377 _pi->set_input_map (pc, in_map);
1379 plugin_reconfigured ();
1384 in_map.set (s->dt, s->id, i->id);
1385 _pi->set_input_map (pc, in_map);
1389 in_map.unset (s->dt, s->id);
1390 in_map.set (s->dt, s->id, i->id);
1391 _pi->set_input_map (pc, in_map);
1396 PluginPinWidget::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1398 _ignore_updates = true;
1399 for (uint32_t n = 0; n < _n_plugins; ++n) {
1404 ChanMapping n_out_map (_pi->output_map (n));
1405 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1407 n_out_map.unset (dt, idx);
1408 _pi->set_output_map (n, n_out_map);
1411 _ignore_updates = false;
1415 PluginPinWidget::disconnect_other_thru (DataType dt, uint32_t id)
1417 _ignore_updates = true;
1419 ChanMapping n_thru_map (_pi->thru_map ());
1420 n_thru_map.get (dt, id, &valid);
1422 n_thru_map.unset (dt, id);
1423 _pi->set_thru_map (n_thru_map);
1425 _ignore_updates = false;
1429 PluginPinWidget::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1431 const uint32_t pc = s->ip;
1433 ChanMapping out_map (_pi->output_map (pc));
1434 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1436 if (valid && idx == o->id) {
1439 out_map.unset (s->dt, s->id);
1440 _pi->set_output_map (pc, out_map);
1442 plugin_reconfigured ();
1446 // disconnect source
1447 disconnect_other_outputs (pc, s->dt, o->id);
1448 disconnect_other_thru (s->dt, o->id);
1449 out_map = _pi->output_map (pc); // re-read map
1451 out_map.unset (s->dt, s->id);
1453 idx = out_map.get_src (s->dt, o->id, &valid);
1455 out_map.unset (s->dt, idx);
1458 out_map.set (s->dt, s->id, o->id);
1459 _pi->set_output_map (pc, out_map);
1464 PluginPinWidget::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1467 ChanMapping thru_map (_pi->thru_map ());
1468 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1470 if (valid && idx == i->id) {
1472 thru_map.unset (o->dt, o->id);
1475 // disconnect other outputs first
1476 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1477 disconnect_other_thru (o->dt, o->id);
1478 thru_map = _pi->thru_map (); // re-read map
1480 thru_map.set (o->dt, o->id, i->id);
1482 _pi->set_thru_map (thru_map);
1486 PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal)
1488 _ignore_updates = true;
1489 bool changed = false;
1495 ChanMapping n_thru_map (_pi->thru_map ());
1496 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1497 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1498 if (valid && idx == e->id) {
1499 n_thru_map.unset (e->dt, i);
1504 _pi->set_thru_map (n_thru_map);
1507 for (uint32_t n = 0; n < _n_plugins; ++n) {
1508 ChanMapping map (_pi->input_map (n));
1509 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1510 uint32_t idx = map.get (e->dt, i, &valid);
1511 if (valid && idx == e->id) {
1512 map.unset (e->dt, i);
1516 _pi->set_input_map (n, map);
1521 ChanMapping map (_pi->input_map (e->ip));
1522 map.get (e->dt, e->id, &valid);
1524 map.unset (e->dt, e->id);
1525 _pi->set_input_map (e->ip, map);
1532 ChanMapping map (_pi->output_map (e->ip));
1533 map.get (e->dt, e->id, &valid);
1535 map.unset (e->dt, e->id);
1536 _pi->set_output_map (e->ip, map);
1542 for (uint32_t n = 0; n < _n_plugins; ++n) {
1543 ChanMapping map (_pi->output_map (n));
1544 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1545 uint32_t idx = map.get (e->dt, i, &valid);
1546 if (valid && idx == e->id) {
1547 map.unset (e->dt, i);
1552 _pi->set_output_map (n, map);
1556 ChanMapping n_thru_map (_pi->thru_map ());
1557 n_thru_map.get (e->dt, e->id, &valid);
1559 n_thru_map.unset (e->dt, e->id);
1561 _pi->set_thru_map (n_thru_map);
1566 _ignore_updates = false;
1567 if (changed && !no_signal) {
1568 plugin_reconfigured ();
1574 PluginPinWidget::toggle_sidechain ()
1576 if (_session && _session->actively_recording ()) { return; }
1577 _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
1581 PluginPinWidget::connect_sidechain ()
1583 if (!_session) { return; }
1585 if (_sidechain_selector == 0) {
1586 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1589 if (_sidechain_selector->is_visible ()) {
1590 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1592 _sidechain_selector->present ();
1597 PluginPinWidget::reset_configuration ()
1599 if (_set_config.get_active ()) {
1600 _route ()->reset_plugin_insert (_pi);
1602 _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
1607 PluginPinWidget::reset_mapping ()
1613 PluginPinWidget::select_output_preset (uint32_t n_audio)
1615 if (_session && _session->actively_recording ()) { return; }
1616 ChanCount out (DataType::AUDIO, n_audio);
1617 _route ()->plugin_preset_output (_pi, out);
1621 PluginPinWidget::add_remove_plugin_clicked (bool add)
1623 if (_session && _session->actively_recording ()) { return; }
1624 ChanCount out = _out;
1625 ChanCount sinks = _sinks;
1626 assert (add || _n_plugins > 0);
1627 _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks);
1631 PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
1633 if (_session && _session->actively_recording ()) { return; }
1634 ChanCount out = _out;
1635 ChanCount sinks = _sinks;
1636 assert (add || out.get (dt) > 0);
1637 out.set (dt, out.get (dt) + (add ? 1 : -1));
1638 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1642 PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
1644 if (_session && _session->actively_recording ()) { return; }
1645 ChanCount out = _out;
1646 ChanCount sinks = _sinks;
1647 assert (add || sinks.get (dt) > 0);
1648 sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
1649 _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
1653 PluginPinWidget::add_sidechain_port (DataType dt)
1655 if (_session && _session->actively_recording ()) { return; }
1656 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1661 // this triggers a PluginIoReConfigure with process and processor write lock held
1662 // from /this/ thread.
1663 io->add_port ("", this, dt);
1667 PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1669 if (_session && _session->actively_recording ()) { return; }
1670 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1671 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1675 io->remove_port (p, this);
1679 PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1681 if (_session && _session->actively_recording ()) { return; }
1682 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1683 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1687 p->disconnect_all ();
1691 PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1693 if (_session && _session->actively_recording ()) { return; }
1694 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1695 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1696 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1697 if (!io || !p0 || !p1) {
1700 _ignore_updates = true;
1701 p0->disconnect_all ();
1702 _ignore_updates = false;
1703 p0->connect (p1->name ());
1707 PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1709 if (_session && _session->actively_recording ()) { return; }
1710 boost::shared_ptr<Port> p = wp.lock ();
1711 boost::shared_ptr<Route> r = wr.lock ();
1712 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1713 if (!p || !r || !io || !_session) {
1717 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1718 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1719 const ChanCount& outs (r->amp ()->input_streams ());
1721 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1722 send->output()->ensure_io (outs, false, this);
1723 } catch (AudioEngine::PortRegistrationFailure& err) {
1724 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1728 std::string sendname = send->name ();
1729 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1730 if (last_letter != string::npos) {
1731 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1733 sendname.substr (last_letter + 1)));
1736 _ignore_updates = true;
1737 p->disconnect_all ();
1739 DataType dt = p->type ();
1740 PortSet& ps (send->output ()->ports ());
1741 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1742 p->connect (&(**i));
1745 send->set_remove_on_disconnect (true);
1746 r->add_processor (send, PreFader);
1747 _ignore_updates = false;
1748 queue_idle_update ();
1752 PluginPinWidget::sc_input_release (GdkEventButton *ev)
1754 if (_session && _session->actively_recording ()) { return false; }
1755 if (ev->button == 3) {
1756 connect_sidechain ();
1761 struct RouteCompareByName {
1762 bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
1763 return a->name ().compare (b->name ()) < 0;
1768 PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1770 using namespace Menu_Helpers;
1771 if (!_session || _session->actively_recording ()) { return false; }
1772 if (!_session->engine ().connected ()) { return false; }
1774 if (ev->button == 1) {
1775 MenuList& citems = input_menu.items ();
1776 input_menu.set_name ("ArdourContextMenu");
1779 boost::shared_ptr<Port> p = wp.lock ();
1780 if (p && p->connected ()) {
1781 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::disconnect_port), wp)));
1782 citems.push_back (SeparatorElem ());
1786 // TODO add system inputs, too ?!
1787 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1788 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1789 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1791 //maybe_add_bundle_to_input_menu (*i, current);
1795 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
1796 RouteList copy = *routes;
1797 copy.sort (RouteCompareByName ());
1799 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1800 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1804 citems.push_back (SeparatorElem ());
1806 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinWidget::connect_sidechain)));
1807 input_menu.popup (1, ev->time);
1813 PluginPinWidget::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1816 using namespace Menu_Helpers;
1817 if (r->output () == _route ()->output ()) {
1821 if (_route ()->feeds_according_to_graph (r)) {
1825 MenuList& citems = input_menu.items ();
1827 /*check if there's already a send.. */
1828 bool already_present = false;
1830 boost::shared_ptr<Processor> proc;
1831 /* Note: nth_send () takes a processor read-lock */
1832 while ((proc = r->nth_send (nth))) {
1833 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1834 if (!send || !send->output ()) {
1838 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1839 // only if (send->remove_on_disconnect ()) ??
1840 already_present = true;
1845 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1846 const ChanCount& rc (r->amp ()->input_streams ());
1847 if (!already_present && rc.get (dt) > 0) {
1848 citems.push_back (MenuElem (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr<Route> (r))));
1855 PluginPinWidget::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1857 boost::shared_ptr<Port> p0 = w0.lock ();
1858 boost::shared_ptr<Port> p1 = w1.lock ();
1860 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1861 if (!io) { return; }
1863 if (p0 && io->has_port (p0)) {
1864 queue_idle_update ();
1866 else if (p1 && io->has_port (p1)) {
1867 queue_idle_update ();
1871 /* lifted from ProcessorEntry::Control */
1872 PluginPinWidget::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1874 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1875 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1876 , _slider_persistant_tooltip (&_slider)
1877 , _ignore_ui_adjustment (false)
1880 _slider.set_controllable (c);
1881 box.set_padding (0, 0, 4, 4);
1883 _slider.set_name ("ProcessorControlSlider");
1884 _slider.set_text (_name);
1889 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1890 double const lo = c->internal_to_interface (desc.lower);
1891 double const up = c->internal_to_interface (desc.upper);
1892 double const normal = c->internal_to_interface (desc.normal);
1893 double smallstep = desc.smallstep;
1894 double largestep = desc.largestep;
1896 if (smallstep == 0.0) {
1897 smallstep = up / 1000.;
1899 smallstep = c->internal_to_interface (desc.lower + smallstep);
1902 if (largestep == 0.0) {
1903 largestep = up / 40.;
1905 largestep = c->internal_to_interface (desc.lower + largestep);
1908 _adjustment.set_lower (lo);
1909 _adjustment.set_upper (up);
1910 _adjustment.set_step_increment (smallstep);
1911 _adjustment.set_page_increment (largestep);
1912 _slider.set_default_value (normal);
1914 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1915 // dup. currently timers are used :(
1916 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1918 // yuck, do we really need to do this?
1919 // according to c404374 this is only needed for send automation
1920 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1925 /* We're providing our own PersistentTooltip */
1926 set_no_tooltip_whatsoever (_slider);
1929 PluginPinWidget::Control::~Control ()
1931 timer_connection.disconnect ();
1935 PluginPinWidget::Control::set_tooltip ()
1937 boost::shared_ptr<AutomationControl> c = _control.lock ();
1942 snprintf (tmp, sizeof (tmp), "%s: %.2f", _name.c_str (), c->internal_to_user (c->get_value ()));
1944 string sm = Gtkmm2ext::markup_escape_text (tmp);
1945 _slider_persistant_tooltip.set_tip (sm);
1949 PluginPinWidget::Control::slider_adjusted ()
1951 if (_ignore_ui_adjustment) {
1954 boost::shared_ptr<AutomationControl> c = _control.lock ();
1958 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1964 PluginPinWidget::Control::control_changed ()
1966 boost::shared_ptr<AutomationControl> c = _control.lock ();
1971 _ignore_ui_adjustment = true;
1973 // as long as rapid timers are used, only update the tooltip
1974 // if the value has changed.
1975 const double nval = c->internal_to_interface (c->get_value ());
1976 if (_adjustment.get_value () != nval) {
1977 _adjustment.set_value (nval);
1981 _ignore_ui_adjustment = false;
1986 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
1987 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
1989 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
1994 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
1995 : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
1998 vbox = manage (new VBox ());
2002 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2004 _route->processors_changed.connect (
2005 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context()
2008 _route->DropReferences.connect (
2009 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context()
2013 PluginPinDialog::set_session (ARDOUR::Session *s)
2015 SessionHandlePtr::set_session (s);
2016 for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) {
2017 (*i)->set_session (s);
2022 PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
2026 vbox = manage (new VBox ());
2029 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2033 PluginPinDialog::route_going_away ()
2041 PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
2043 boost::shared_ptr<Processor> proc = p.lock ();
2044 if (!proc || !proc->display_to_user ()) {
2047 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
2049 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
2050 vbox->pack_start (*ppw.back());
2052 HBox* hbox = manage (new HBox ());
2053 hbox->pack_start (*manage (new HSeparator ()));
2054 hbox->pack_start (*manage (new Label (proc->display_name ())));
2055 hbox->pack_start (*manage (new HSeparator ()));
2056 vbox->pack_start (*hbox);