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/box.h>
23 #include <gtkmm/frame.h>
24 #include <gtkmm/label.h>
25 #include <gtkmm/messagedialog.h>
26 #include <gtkmm/separator.h>
27 #include <gtkmm/table.h>
29 #include "pbd/replace_all.h"
31 #include "gtkmm2ext/utils.h"
32 #include "gtkmm2ext/rgb_macros.h"
33 #include "gtkmm2ext/menu_elems.h"
35 #include "widgets/tooltips.h"
37 #include "ardour/amp.h"
38 #include "ardour/audioengine.h"
39 #include "ardour/pannable.h"
40 #include "ardour/plugin.h"
41 #include "ardour/port.h"
42 #include "ardour/profile.h"
43 #include "ardour/send.h"
44 #include "ardour/session.h"
45 #include "ardour/value_as_string.h"
47 #include "plugin_pin_dialog.h"
48 #include "gui_thread.h"
50 #include "ui_config.h"
55 using namespace ARDOUR;
59 using namespace Gtkmm2ext;
60 using namespace ArdourWidgets;
62 PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
63 : _set_config (_("Manual Config"), ArdourButton::led_default_elements)
64 , _tgl_sidechain (_("Sidechain"), ArdourButton::led_default_elements)
65 , _add_plugin (_("+"))
66 , _del_plugin (_("-"))
67 , _add_input_audio (_("+"))
68 , _del_input_audio (_("-"))
69 , _add_input_midi (_("+"))
70 , _del_input_midi (_("-"))
71 , _add_output_audio (_("+"))
72 , _del_output_audio (_("-"))
73 , _add_output_midi (_("+"))
74 , _del_output_midi (_("-"))
75 , _add_sc_audio (_("Audio"))
76 , _add_sc_midi (_("MIDI"))
88 , _position_valid (false)
89 , _ignore_updates (false)
90 , _sidechain_selector (0)
93 assert (pi->owner ()); // Route
95 _pi->PluginIoReConfigure.connect (
96 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
99 _pi->PluginMapChanged.connect (
100 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
103 _pi->PluginConfigChanged.connect (
104 _plugin_connections, invalidator (*this), boost::bind (&PluginPinWidget::queue_idle_update, this), gui_context ()
107 _pin_box_size = 2 * ceil (max (8., 10. * UIConfiguration::instance ().get_ui_scale ()) * .5);
108 _margin_x = 2 * ceil (max (24., 28. * UIConfiguration::instance ().get_ui_scale ()) * .5);
109 _margin_y = 2 * ceil (max (36., 40. * UIConfiguration::instance ().get_ui_scale ()) * .5);
111 _tgl_sidechain.set_name ("pinrouting sidechain");
112 _set_config.set_name ("pinrouting custom");
114 Menu_Helpers::MenuList& citems = reset_menu.items ();
115 reset_menu.set_name ("ArdourContextMenu");
117 citems.push_back (Menu_Helpers::MenuElem (_("Reset"), sigc::mem_fun (*this, &PluginPinWidget::reset_mapping)));
119 _pm_size_group = SizeGroup::create (SIZE_GROUP_BOTH);
120 _add_plugin.set_tweaks (ArdourButton::Square);
121 _del_plugin.set_tweaks (ArdourButton::Square);
122 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
123 _pm_size_group->add_widget (_add_input_audio);
124 _pm_size_group->add_widget (_del_input_audio);
125 _pm_size_group->add_widget (_add_input_midi);
126 _pm_size_group->add_widget (_del_input_midi);
128 _pm_size_group->add_widget (_add_plugin);
129 _pm_size_group->add_widget (_del_plugin);
131 _pm_size_group->add_widget (_add_output_audio);
132 _pm_size_group->add_widget (_del_output_audio);
133 _pm_size_group->add_widget (_add_output_midi);
134 _pm_size_group->add_widget (_del_output_midi);
139 VBox* tl = manage (new VBox ());
140 tl->set_border_width (2);
143 VBox* tr = manage (new VBox ());
144 tr->set_border_width (2);
148 tl->pack_start (_set_config, false, false);
150 if (_pi->plugin (0)->get_info()->reconfigurable_io ()) {
151 box = manage (new HBox ());
152 box->set_border_width (2);
153 box->pack_start (_add_input_audio, true, false);
154 box->pack_start (_del_input_audio, true, false);
155 f = manage (new Frame ());
156 f->set_label (_("Audio Input Pins"));
158 tl->pack_start (*f, false, false);
160 box = manage (new HBox ());
161 box->set_border_width (2);
162 box->pack_start (_add_input_midi, true, false);
163 box->pack_start (_del_input_midi, true, false);
164 f = manage (new Frame ());
165 f->set_label (_("MIDI Input Pins"));
167 tl->pack_start (*f, false, false);
169 box = manage (new HBox ());
170 box->set_border_width (2);
171 box->pack_start (_add_plugin, true, false);
172 box->pack_start (_del_plugin, true, false);
173 f = manage (new Frame ());
174 f->set_label (_("Instances"));
176 tl->pack_start (*f, false, false);
179 box = manage (new HBox ());
180 box->set_border_width (2);
181 box->pack_start (_add_output_audio, true, false);
182 box->pack_start (_del_output_audio, true, false);
183 f = manage (new Frame ());
184 f->set_label (_("Audio Out"));
186 tl->pack_start (*f, false, false);
188 box = manage (new HBox ());
189 box->set_border_width (2);
190 box->pack_start (_add_output_midi, true, false);
191 box->pack_start (_del_output_midi, true, false);
192 f = manage (new Frame ());
193 f->set_label (_("MIDI Out"));
195 tl->pack_start (*f, false, false);
197 tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
198 tl->pack_start (*manage (new HSeparator ()), false, false, 4);
199 _out_presets.disable_scrolling ();
200 ArdourWidgets::set_tooltip (_out_presets, _("Output Presets"));
201 tl->pack_start (_out_presets, false, false);
204 _sidechain_tbl = manage (new Gtk::Table ());
205 _sidechain_tbl->set_spacings (2);
207 tr->pack_start (_tgl_sidechain, false, false);
208 tr->pack_start (*_sidechain_tbl, true, true);
210 box = manage (new VBox ());
211 box->set_border_width (2);
212 box->set_spacing (2);
213 box->pack_start (_add_sc_audio, false, false);
214 box->pack_start (_add_sc_midi , false, false);
215 f = manage (new Frame ());
216 f->set_label (_("Add Sidechain Input"));
219 tr->pack_start (*f, false, false);
222 HBox* hbox = manage (new HBox ());
223 hbox->set_spacing (4);
224 hbox->pack_start (*tl, false, false);
225 hbox->pack_start (darea, true, true);
226 hbox->pack_start (*tr, false, false);
228 pack_start (*hbox, true, true);
229 set_border_width (4);
232 plugin_reconfigured ();
234 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
235 darea.signal_size_request ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_request));
236 darea.signal_size_allocate ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_size_allocate));
237 darea.signal_expose_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_expose_event));
238 darea.signal_button_press_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_press_event));
239 darea.signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_button_release_event));
240 darea.signal_motion_notify_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::darea_motion_notify_event));
242 _tgl_sidechain.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::toggle_sidechain));
244 _set_config.signal_clicked.connect (sigc::mem_fun (*this, &PluginPinWidget::reset_configuration));
245 _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), true));
246 _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_plugin_clicked), false));
248 _add_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::AUDIO));
249 _del_input_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::AUDIO));
250 _add_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), true, DataType::MIDI));
251 _del_input_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_inpin_clicked), false, DataType::MIDI));
253 _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::AUDIO));
254 _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::AUDIO));
255 _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), true, DataType::MIDI));
256 _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_remove_port_clicked), false, DataType::MIDI));
258 _add_sc_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::AUDIO));
259 _add_sc_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_sidechain_port), DataType::MIDI));
261 AudioEngine::instance ()->PortConnectedOrDisconnected.connect (
262 _io_connection, invalidator (*this), boost::bind (&PluginPinWidget::port_connected_or_disconnected, this, _1, _3), gui_context ()
266 PluginPinWidget::~PluginPinWidget ()
268 delete _sidechain_selector;
272 PluginPinWidget::set_session (ARDOUR::Session *s)
274 SessionHandlePtr::set_session (s);
275 plugin_reconfigured ();
279 PluginPinWidget::queue_idle_update ()
281 /* various actions here are directly executed, in the GUI thread,
282 * with the GUI-thread eventually taking the process and processor lock.
283 * "connect gui_context()" will call back immediately and this
284 * signal-handler will run with the locks held.
286 * This will lead to a crash with calling nth_send() which takes
287 * a processor read-lock while holding a write lock in the same thread.
289 * decouple update to GUI idle.
291 * BUT, do delete existing controls here (in case they're affected by
292 * the change and hit by the Timer before idle comes around)
294 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
295 _sidechain_tbl->remove ((*i)->box);
299 Glib::signal_idle().connect (sigc::mem_fun(*this, &PluginPinWidget::idle_update));
303 PluginPinWidget::idle_update ()
305 plugin_reconfigured ();
310 PluginPinWidget::error_message_dialog (std::string const& msg) const
313 Gtk::MessageDialog d (
314 _session->actively_recording () ? _("Cannot perform operation while actively recording.") : msg
315 , false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);
321 PluginPinWidget::plugin_reconfigured ()
323 ENSURE_GUI_THREAD (*this, &PluginPinWidget::plugin_reconfigured);
324 if (_ignore_updates) {
327 _n_plugins = _pi->get_count ();
328 _pi->configured_io (_in, _out);
329 _ins = _pi->internal_streams (); // with sidechain
330 _sinks = _pi->natural_input_streams ();
331 _sources = _pi->natural_output_streams ();
334 _tgl_sidechain.set_active (_pi->has_sidechain ());
335 _add_sc_audio.set_sensitive (_pi->has_sidechain ());
336 _add_sc_midi.set_sensitive (_pi->has_sidechain ());
338 if (_pi->custom_cfg ()) {
339 _set_config.set_active (true);
340 _add_plugin.set_sensitive (true);
341 _del_plugin.set_sensitive (_n_plugins > 1);
342 _add_output_audio.set_sensitive (true);
343 _add_output_midi.set_sensitive (true);
344 _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
345 _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
346 _add_input_audio.set_sensitive (true);
347 _add_input_midi.set_sensitive (true);
348 _del_input_audio.set_sensitive (_sinks.n_audio () > 0 && _sinks.n_total () > 1);
349 _del_input_midi.set_sensitive (_sinks.n_midi () > 0 && _sinks.n_total () > 1);
350 _out_presets.set_sensitive (false);
351 _out_presets.set_text (_("Manual"));
353 _set_config.set_active (false);
354 _add_plugin.set_sensitive (false);
355 _del_plugin.set_sensitive (false);
356 _add_input_audio.set_sensitive (false);
357 _add_input_midi.set_sensitive (false);
358 _del_input_audio.set_sensitive (false);
359 _del_input_midi.set_sensitive (false);
360 _add_output_audio.set_sensitive (false);
361 _add_output_midi.set_sensitive (false);
362 _del_output_audio.set_sensitive (false);
363 _del_output_midi.set_sensitive (false);
364 _out_presets.set_sensitive (true);
365 refill_output_presets ();
368 if (!_pi->has_sidechain () && _sidechain_selector) {
369 delete _sidechain_selector;
370 _sidechain_selector = 0;
373 refill_sidechain_table ();
375 /* update elements */
384 _n_inputs = _n_sidechains = 0;
386 for (uint32_t i = 0; i < _ins.n_total (); ++i) {
387 DataType dt = i < _ins.n_midi () ? DataType::MIDI : DataType::AUDIO;
388 uint32_t id = dt == DataType::MIDI ? i : i - _ins.n_midi ();
389 bool sidechain = id >= _in.get (dt) ? true : false;
396 CtrlWidget cw (CtrlWidget ("", Input, dt, id, 0, sidechain));
397 _elements.push_back (cw);
400 for (uint32_t i = 0; i < _out.n_total (); ++i) {
401 int id = (i < _out.n_midi ()) ? i : i - _out.n_midi ();
402 _elements.push_back (CtrlWidget ("", Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), id));
408 for (uint32_t n = 0; n < _n_plugins; ++n) {
409 boost::shared_ptr<Plugin> plugin = _pi->plugin (n);
410 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
411 DataType dt (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO);
412 int idx = (dt == DataType::MIDI) ? i : i - _sinks.n_midi ();
413 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, true, idx));
414 CtrlWidget cw (CtrlWidget (iod.name, Sink, dt, idx, n, iod.is_sidechain));
415 _elements.push_back (cw);
417 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
418 DataType dt (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO);
419 int idx = (dt == DataType::MIDI) ? i : i - _sources.n_midi ();
420 const Plugin::IOPortDescription& iod (plugin->describe_io_port (dt, false, idx));
421 _elements.push_back (CtrlWidget (iod.name, Source, dt, idx, n));
423 _in_map[n] = _pi->input_map (n);
424 _out_map[n] = _pi->output_map (n);
426 _has_midi_bypass = _pi->has_midi_bypass ();
427 _thru_map = _pi->thru_map ();
431 /* calc minimum size */
432 const uint32_t max_ports = std::max (_ins.n_total (), _out.n_total ());
433 const uint32_t max_pins = std::max ((_sinks * _n_plugins).n_total (), (_sources * _n_plugins).n_total ());
434 uint32_t min_width = std::max (25 * max_ports, (uint32_t)(20 + _pin_box_size) * max_pins);
435 min_width = std::max (min_width, (uint32_t)ceilf (_margin_y * .45 * _n_plugins * 16. / 9.)); // 16 : 9 aspect
436 min_width = std::max ((uint32_t)300, min_width);
438 min_width = 50 + 10 * ceilf (min_width / 10.f);
440 uint32_t min_height = 3.5 * _margin_y + 2 * (_n_sidechains + 1) * _pin_box_size;
441 min_height = std::max ((uint32_t)200, min_height);
442 min_height = 4 * ceilf (min_height / 4.f);
444 if (min_width != _min_width || min_height != _min_height) {
445 _min_width = min_width;
446 _min_height = min_height;
447 darea.queue_resize ();
450 _position_valid = false;
455 PluginPinWidget::refill_sidechain_table ()
457 Table_Helpers::TableList& kids = _sidechain_tbl->children ();
458 for (Table_Helpers::TableList::iterator i = kids.begin (); i != kids.end ();) {
461 _sidechain_tbl->resize (1, 1);
462 for (list<Control*>::iterator i = _controls.begin (); i != _controls.end (); ++i) {
466 if (!_pi->has_sidechain () && _sidechain_selector) {
469 boost::shared_ptr<IO> io = _pi->sidechain_input ();
475 PortSet& p (io->ports ());
476 bool can_remove = p.num_ports () > 1;
477 for (PortSet::iterator i = p.begin (DataType::MIDI); i != p.end (DataType::MIDI); ++i) {
478 r += add_port_to_table (*i, r, can_remove);
480 for (PortSet::iterator i = p.begin (DataType::AUDIO); i != p.end (DataType::AUDIO); ++i) {
481 r += add_port_to_table (*i, r, can_remove);
483 _sidechain_tbl->show_all ();
487 PluginPinWidget::refill_output_presets ()
489 using namespace Menu_Helpers;
490 _out_presets.clear_items ();
492 bool need_dropdown = _pi->has_output_presets ();
494 if (!need_dropdown) {
495 _out_presets.set_sensitive (false);
496 _out_presets.set_text (_("Automatic"));
500 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), 0)));
502 const uint32_t n_audio = _pi->preset_out ().n_audio ();
504 _out_presets.set_text (_("Automatic"));
507 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
508 if (ppc.find (0) != ppc.end ()) {
512 ppc.insert (n_audio);
522 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
533 tmp = string_compose (P_("%1 Channel", "%1 Channels", *i), *i);
536 _out_presets.AddMenuElem (MenuElem (tmp, sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::select_output_preset), *i)));
538 _out_presets.set_text (tmp);
544 PluginPinWidget::port_label (const std::string& portname, bool strip)
546 // compare to MixerStrip::update_io_button()
547 string lpn (PROGRAM_NAME);
548 boost::to_lower (lpn);
549 std::string program_port_prefix = lpn + ":"; // e.g. "ardour:"
551 std::string pn = AudioEngine::instance ()->get_pretty_name_by_name (portname);
553 string::size_type slash = pn.find ("/");
554 if (slash != string::npos) {
555 pn = pn.substr (0, slash);
559 std::string label (portname);
560 if (label.find ("system:capture_") == 0) {
561 if (label.empty ()) {
562 label = portname.substr (15);
564 } else if (label.find ("system:midi_capture_") == 0) {
565 if (label.empty ()) {
566 // "system:midi_capture_123" -> "123"
567 label = "M " + portname.substr (20);
569 } else if (label.find (program_port_prefix) == 0) {
570 label = label.substr (program_port_prefix.size ());
572 string::size_type slash = label.find ("/");
573 if (slash != string::npos) {
574 label = label.substr (0, slash);
582 PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
585 std::string tip = Gtkmm2ext::markup_escape_text (p->name ());
586 std::vector<std::string> cns;
587 bool single_source = true;
588 p->get_connections (cns);
590 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
592 lbl = port_label (*i, true);
595 if (port_label (*i, true) != lbl) {
597 single_source = false;
602 if (cns.size () == 0) {
604 single_source = false;
605 } else if (cns.size () == 1) {
607 lbl = port_label (cns[0], false);
611 replace_all (lbl, "_", " ");
613 for (std::vector<std::string>::const_iterator i = cns.begin (); i != cns.end (); ++i) {
618 ArdourButton *pb = manage (new ArdourButton (lbl));
619 pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
620 pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
621 ArdourWidgets::set_tooltip (*pb, tip);
622 _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
624 pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr<Port> (p)), false);
625 pb->signal_button_release_event ().connect (sigc::mem_fun (*this, &PluginPinWidget::sc_input_release), false);
627 pb = manage (new ArdourButton ("-"));
628 _sidechain_tbl->attach (*pb, 1, 2, r, r + 1, FILL, SHRINK);
630 pb->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::remove_port), boost::weak_ptr<Port> (p)));
632 pb->set_sensitive (false);
637 if (single_source && _session) {
638 /* check if it's an Ardour Send feeding.. */
639 boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
640 for (ARDOUR::RouteList::const_iterator i = routes->begin (); i != routes->end (); ++i) {
642 boost::shared_ptr<Processor> proc;
643 /* nth_send () takes a processor read-lock */
644 while ((proc = (*i)->nth_send (nth))) {
645 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
646 if (!send || !send->output ()) {
650 if (!send->output ()->connected_to (p->name ())) {
654 /* if processor goes away, we're notified by the port disconnect,
655 * there should be no need to explicily connect to proc->DropReferences
657 set<Evoral::Parameter> p = proc->what_can_be_automated ();
658 for (set<Evoral::Parameter>::iterator i = p.begin (); i != p.end (); ++i) {
659 Control* c = new Control (proc->automation_control (*i), _("Send"));
660 _controls.push_back (c);
662 _sidechain_tbl->attach (c->box, 0, 2, r, r + 1, EXPAND|FILL, SHRINK);
672 PluginPinWidget::update_element_pos ()
675 _innerwidth = _width - 2. * _margin_x;
677 const double yc = rint (_height * .5);
678 const double bxh2 = rint (_margin_y * .45); // TODO grow?
679 const double bxw = rint ((_innerwidth * .95) / ((_n_plugins) + .2 * (_n_plugins - 1)));
680 const double bxw2 = rint (bxw * .5);
681 const double y_in = _margin_y;
682 const double y_out = _height - _margin_y;
687 const double dx = _pin_box_size * .5;
690 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
694 i->x = _innerwidth + _margin_x - dx;
695 i->y = y_in + (sc_cnt + .5) * _pin_box_size;
696 i->h = _pin_box_size;
697 i->w = 1.5 * _pin_box_size;
700 uint32_t idx = i->e->id;
701 if (i->e->dt == DataType::AUDIO) { idx += _in.n_midi (); }
702 i->x = rint ((idx + 1) * _width / (1. + _n_inputs)) - 0.5 - dx;
703 i->w = _pin_box_size;
704 i->h = 1.5 * _pin_box_size;
710 uint32_t idx = i->e->id;
711 if (i->e->dt == DataType::AUDIO) { idx += _out.n_midi (); }
712 i->x = rint ((idx + 1) * _width / (1. + _out.n_total ())) - 0.5 - dx;
714 i->w = _pin_box_size;
715 i->h = 1.5 * _pin_box_size;
720 uint32_t idx = i->e->id;
721 if (i->e->dt == DataType::AUDIO) { idx += _sinks.n_midi (); }
722 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
723 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sinks.n_total ())) - .5 - dx;
724 i->y = yc - bxh2 - dx;
725 i->w = _pin_box_size;
726 i->h = _pin_box_size;
731 uint32_t idx = i->e->id;
732 if (i->e->dt == DataType::AUDIO) { idx += _sources.n_midi (); }
733 const double x0 = rint ((i->e->ip + .5) * _innerwidth / (double)(_n_plugins)) - .5 - bxw2;
734 i->x = _margin_x + rint (x0 + (idx + 1) * bxw / (1. + _sources.n_total ())) - .5 - dx;
735 i->y = yc + bxh2 - dx;
736 i->w = _pin_box_size;
737 i->h = _pin_box_size;
745 PluginPinWidget::set_color (cairo_t* cr, bool midi)
747 // see also gtk2_ardour/processor_box.cc
748 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
749 static const uint32_t midi_port_color = 0x960909FF; //Red
752 cairo_set_source_rgb (cr,
753 UINT_RGBA_R_FLT (midi_port_color),
754 UINT_RGBA_G_FLT (midi_port_color),
755 UINT_RGBA_B_FLT (midi_port_color));
757 cairo_set_source_rgb (cr,
758 UINT_RGBA_R_FLT (audio_port_color),
759 UINT_RGBA_G_FLT (audio_port_color),
760 UINT_RGBA_B_FLT (audio_port_color));
765 PluginPinWidget::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
768 const double dy = w.h * .5;
769 const double dx = w.w - dy;
770 cairo_move_to (cr, w.x, w.y + dy);
771 cairo_rel_line_to (cr, dy, -dy);
772 cairo_rel_line_to (cr, dx, 0);
773 cairo_rel_line_to (cr, 0, w.h);
774 cairo_rel_line_to (cr, -dx, 0);
776 const double dir = (w.e->ct == Input) ? 1 : -1;
777 const double dx = w.w * .5;
778 const double dy = w.h - dx;
780 cairo_move_to (cr, w.x + dx, w.y + ((w.e->ct == Input) ? w.h : 0));
781 cairo_rel_line_to (cr, -dx, -dx * dir);
782 cairo_rel_line_to (cr, 0., -dy * dir);
783 cairo_rel_line_to (cr, 2. * dx, 0.);
784 cairo_rel_line_to (cr, 0., dy * dir);
786 cairo_close_path (cr);
788 cairo_set_line_width (cr, 1.0);
789 cairo_set_source_rgb (cr, 0, 0, 0);
790 cairo_stroke_preserve (cr);
792 set_color (cr, w.e->dt == DataType::MIDI);
795 assert (w.e->ct == Input);
796 cairo_fill_preserve (cr);
797 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
800 if (w.e == _selection || w.e == _actor) {
801 cairo_fill_preserve (cr);
802 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
803 } else if (w.prelight) {
804 cairo_fill_preserve (cr);
805 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
811 PluginPinWidget::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
813 const double dx = w.w * .5;
814 const double dy = w.h * .5;
816 cairo_move_to (cr, w.x + dx, w.y);
817 cairo_rel_line_to (cr, -dx, dy);
818 cairo_rel_line_to (cr, dx, dy);
819 cairo_rel_line_to (cr, dx, -dy);
820 cairo_close_path (cr);
822 cairo_set_line_width (cr, 1.0);
823 cairo_set_source_rgb (cr, 0, 0, 0);
824 cairo_stroke_preserve (cr);
826 set_color (cr, w.e->dt == DataType::MIDI);
829 assert (w.e->ct == Sink);
830 cairo_fill_preserve (cr);
831 cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.4);
834 if (w.e == _selection || w.e == _actor) {
835 cairo_fill_preserve (cr);
836 cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 0.6);
837 } else if (w.prelight) {
838 cairo_fill_preserve (cr);
839 cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.3);
843 if ((w.prelight || w.e == _selection) && !w.name.empty ()) {
846 Glib::RefPtr<Pango::Layout> layout;
847 layout = Pango::Layout::create (get_pango_context ());
848 layout->set_text (w.name);
849 layout->get_pixel_size (text_width, text_height);
851 rounded_rectangle (cr, w.x + dx - .5 * text_width - 2, w.y - text_height - 2, text_width + 4, text_height + 2, 7);
852 cairo_set_source_rgba (cr, 0, 0, 0, .5);
855 cairo_move_to (cr, w.x + dx - .5 * text_width, w.y - text_height - 1);
856 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
857 pango_cairo_show_layout (cr, layout->gobj ());
862 PluginPinWidget::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
864 if (!midi) { i += n_midi; }
865 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
868 const PluginPinWidget::CtrlWidget&
869 PluginPinWidget::get_io_ctrl (CtrlType ct, DataType dt, uint32_t id, uint32_t ip) const
871 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
872 if (i->e->ct == ct && i->e->dt == dt && i->e->id == id && i->e->ip == ip) {
877 fatal << string_compose (_("programming error: %1"),
878 X_("Invalid Plugin I/O Port."))
880 abort (); /*NOTREACHED*/
881 static CtrlWidget screw_old_compilers ("", Input, DataType::NIL, 0);
882 return screw_old_compilers;
886 PluginPinWidget::edge_coordinates (const CtrlWidget& w, double &x, double &y)
914 PluginPinWidget::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool horiz, bool dashed)
916 const double bz = 2 * _pin_box_size;
917 double bc = (dashed && x0 == x1) ? 1.25 * _pin_box_size : 0;
918 if (x0 > _width * .5) { bc *= -1; }
920 cairo_move_to (cr, x0, y0);
922 cairo_curve_to (cr, x0 - bz, y0 + bc, x1 - bc, y1 - bz, x1, y1);
924 cairo_curve_to (cr, x0 - bc, y0 + bz, x1 - bc, y1 - bz, x1, y1);
926 cairo_set_line_width (cr, 3.0);
927 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
928 cairo_set_source_rgb (cr, 1, 0, 0);
930 const double dashes[] = { 5, 7 };
931 cairo_set_dash (cr, dashes, 2, 0);
933 set_color (cr, midi);
936 cairo_set_dash (cr, 0, 0, 0);
941 PluginPinWidget::draw_connection (cairo_t* cr, const CtrlWidget& w0, const CtrlWidget& w1, bool dashed)
943 double x0, x1, y0, y1;
944 edge_coordinates (w0, x0, y0);
945 edge_coordinates (w1, x1, y1);
946 assert (w0.e->dt == w1.e->dt);
947 draw_connection (cr, x0, x1, y0, y1, w0.e->dt == DataType::MIDI, w0.e->sc, dashed);
952 PluginPinWidget::darea_expose_event (GdkEventExpose* ev)
954 Gtk::Allocation a = darea.get_allocation ();
955 double const width = a.get_width ();
956 double const height = a.get_height ();
958 if (!_position_valid) {
961 update_element_pos ();
962 _position_valid = true;
965 cairo_t* cr = gdk_cairo_create (darea.get_window ()->gobj ());
966 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
969 Gdk::Color const bg = get_style ()->get_bg (STATE_NORMAL);
970 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
971 cairo_rectangle (cr, 0, 0, width, height);
974 const double yc = rint (_height * .5);
977 rounded_rectangle (cr, _margin_x, _margin_y - _pin_box_size * .5, _innerwidth, _height - 2 * _margin_y + _pin_box_size, 7);
978 cairo_set_line_width (cr, 1.0);
979 cairo_set_source_rgb (cr, .1, .1, .3);
980 cairo_stroke_preserve (cr);
981 cairo_set_source_rgb (cr, .3, .3, .3);
985 Glib::RefPtr<Pango::Layout> layout;
986 layout = Pango::Layout::create (get_pango_context ());
988 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
989 layout->set_width (_height * PANGO_SCALE);
994 layout->set_text (_route ()->name ());
995 layout->get_pixel_size (text_width, text_height);
997 cairo_move_to (cr, .5 * (_margin_x - text_height), .5 * (_height + text_width));
998 cairo_rotate (cr, M_PI * -.5);
999 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1000 pango_cairo_show_layout (cr, layout->gobj ());
1001 cairo_new_path (cr);
1004 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
1005 layout->set_text (_pi->name ());
1006 layout->get_pixel_size (text_width, text_height);
1007 cairo_move_to (cr, _margin_x + _innerwidth - text_width - _pin_box_size * .5, _height - _margin_y - text_height);
1008 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1009 pango_cairo_show_layout (cr, layout->gobj ());
1012 if (_pi->signal_latency () > 0 || !_pi->inplace()) {
1013 layout->set_width ((_innerwidth - 2 * _pin_box_size) * PANGO_SCALE);
1014 if (_pi->signal_latency () > 0 && !_pi->inplace()) {
1015 layout->set_text (string_compose (_("Latency %1 spl%2 %3"), _pi->signal_latency (), ", ", _("no-inplace")));
1016 } else if (_pi->signal_latency () > 0) {
1017 layout->set_text (string_compose (_("Latency %1 spl"), _pi->signal_latency ()));
1019 layout->set_text (_("no-inplace"));
1021 layout->get_pixel_size (text_width, text_height);
1022 cairo_move_to (cr, _margin_x + _pin_box_size * .5, _margin_y + 2);
1023 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1024 pango_cairo_show_layout (cr, layout->gobj ());
1028 if (_pi->strict_io () && !Profile->get_mixbus ()) {
1029 layout->set_text (_("Strict I/O"));
1030 layout->get_pixel_size (text_width, text_height);
1031 const double sx0 = _margin_x + .5 * (_innerwidth - text_width);
1032 const double sy0 = _height - 3 - text_height;
1034 rounded_rectangle (cr, sx0 - 2, sy0 - 1, text_width + 4, text_height + 2, 7);
1035 cairo_set_source_rgba (cr, .4, .3, .1, 1.);
1038 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1039 cairo_move_to (cr, sx0, sy0);
1040 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1041 pango_cairo_show_layout (cr, layout->gobj ());
1044 /* draw midi-bypass (behind) */
1045 if (_has_midi_bypass) {
1046 const CtrlWidget& cw0 = get_io_ctrl (Input, DataType::MIDI, 0);
1047 const CtrlWidget& cw1 = get_io_ctrl (Output, DataType::MIDI, 0);
1048 draw_connection (cr, cw0, cw1, true);
1051 /* thru connections */
1052 const ChanMapping::Mappings thru_map (_thru_map.mappings ());
1053 for (ChanMapping::Mappings::const_iterator t = thru_map.begin (); t != thru_map.end (); ++t) {
1054 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1055 const CtrlWidget& cw0 = get_io_ctrl (Output, t->first, c->first);
1056 const CtrlWidget& cw1 = get_io_ctrl (Input, t->first, c->second);
1057 if (!(_dragging && cw1.e == _selection && cw0.e == _drag_dst)) {
1058 draw_connection (cr, cw1, cw0, true);
1063 /* plugins & connection wires */
1064 for (uint32_t i = 0; i < _n_plugins; ++i) {
1065 double x0 = _margin_x + rint ((i + .5) * _innerwidth / (double)(_n_plugins)) - .5;
1068 cairo_set_source_rgb (cr, .5, .5, .5);
1069 rounded_rectangle (cr, x0 - _bxw2, yc - _bxh2, 2 * _bxw2, 2 * _bxh2, 7);
1072 layout->set_width (1.9 * _bxw2 * PANGO_SCALE);
1073 layout->set_text (string_compose (_("Instance #%1"), i + 1));
1074 layout->get_pixel_size (text_width, text_height);
1075 cairo_move_to (cr, x0 - text_width * .5, yc - text_height * .5);
1076 cairo_set_source_rgba (cr, 1., 1., 1., 1.);
1077 pango_cairo_show_layout (cr, layout->gobj ());
1079 const ChanMapping::Mappings in_map = _in_map[i].mappings ();
1080 const ChanMapping::Mappings out_map = _out_map[i].mappings ();
1082 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
1083 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1084 const CtrlWidget& cw0 = get_io_ctrl (Input, t->first, c->second);
1085 const CtrlWidget& cw1 = get_io_ctrl (Sink, t->first, c->first, i);
1086 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1087 draw_connection (cr, cw0, cw1);
1092 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_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 (Source, t->first, c->first, i);
1095 const CtrlWidget& cw1 = get_io_ctrl (Output, t->first, c->second);
1096 if (!(_dragging && cw0.e == _selection && cw1.e == _drag_dst)) {
1097 draw_connection (cr, cw0, cw1);
1103 /* pins and ports */
1104 for (CtrlElemList::const_iterator i = _elements.begin (); i != _elements.end (); ++i) {
1108 draw_io_pin (cr, *i);
1112 draw_plugin_pin (cr, *i);
1118 CtrlWidget *drag_src = NULL;
1120 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1121 if (i->e == _selection ) {
1129 if (_selection->ct == Input || _selection->ct == Source) {
1130 edge_coordinates (*drag_src, x0, y0);
1131 draw_connection (cr, x0, _drag_x, y0, _drag_y,
1132 _selection->dt == DataType::MIDI, _selection->sc);
1134 edge_coordinates (*drag_src, x0, y0);
1135 draw_connection (cr, _drag_x, x0, _drag_y, y0,
1136 _selection->dt == DataType::MIDI, _selection->sc);
1145 PluginPinWidget::darea_size_request (Gtk::Requisition* req)
1147 req->width = _min_width;
1148 req->height = _min_height;
1152 PluginPinWidget::darea_size_allocate (Gtk::Allocation&)
1154 _position_valid = false;
1158 PluginPinWidget::drag_type_matches (const CtrlElem& e)
1160 if (!_dragging || !_selection) {
1163 if (_selection->dt != e->dt) {
1166 if (_selection->ct == Input && e->ct == Sink) { return true; }
1167 if (_selection->ct == Sink && e->ct == Input) { return true; }
1168 if (_selection->ct == Output && e->ct == Source) { return true; }
1169 if (_selection->ct == Source && e->ct == Output) { return true; }
1170 if (_selection->ct == Input && e->ct == Output) { return true; }
1171 if (_selection->ct == Output && e->ct == Input) { return true; }
1176 PluginPinWidget::start_drag (const CtrlElem& e, double x, double y)
1178 assert (_selection == e);
1180 if (e->ct == Sink) {
1182 const ChanMapping& map (_in_map[e->ip]);
1183 uint32_t idx = map.get (e->dt, e->id, &valid);
1185 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1190 else if (e->ct == Output) {
1191 for (uint32_t i = 0; i < _n_plugins; ++i) {
1193 const ChanMapping& map (_out_map[i]);
1194 uint32_t idx = map.get_src (e->dt, e->id, &valid);
1196 const CtrlWidget& cw = get_io_ctrl (Source, e->dt, idx, i);
1204 const ChanMapping& map (_thru_map);
1205 uint32_t idx = map.get (e->dt, e->id, &valid);
1207 const CtrlWidget& cw = get_io_ctrl (Input, e->dt, idx, 0);
1219 PluginPinWidget::darea_motion_notify_event (GdkEventMotion* ev)
1221 bool changed = false;
1223 for (CtrlElemList::iterator i = _elements.begin (); i != _elements.end (); ++i) {
1224 if (ev->x >= i->x && ev->x <= i->x + i->w
1225 && ev->y >= i->y && ev->y <= i->y + i->h
1226 && drag_type_matches (i->e))
1228 if (!i->prelight) changed = true;
1232 if (i->prelight) changed = true;
1233 i->prelight = false;
1240 if (changed || _dragging) {
1241 darea.queue_draw ();
1247 PluginPinWidget::darea_button_press_event (GdkEventButton* ev)
1249 if (ev->type != GDK_BUTTON_PRESS) {
1253 switch (ev->button) {
1256 if (!_selection || (_selection && !_hover)) {
1257 _selection = _hover;
1260 start_drag (_selection, ev->x, ev->y);
1262 darea.queue_draw ();
1264 } else if (_selection && _hover && _selection != _hover) {
1265 if (_selection->dt != _hover->dt) { _actor.reset (); }
1266 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
1267 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
1268 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
1269 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
1270 else if (_selection->ct == Input && _hover->ct == Output) { _actor = _hover; }
1271 else if (_selection->ct == Output && _hover->ct == Input) { _actor = _hover; }
1273 _selection = _hover;
1274 start_drag (_selection, ev->x, ev->y);
1276 darea.queue_draw ();
1278 } else if (_hover) {
1279 _selection = _hover;
1281 start_drag (_selection, ev->x, ev->y);
1286 if (_selection != _hover) {
1287 _selection = _hover;
1288 darea.queue_draw ();
1300 PluginPinWidget::darea_button_release_event (GdkEventButton* ev)
1302 if (_dragging && _selection && _drag_dst && _drag_dst == _hover) {
1303 // select click. (or re-connect same)
1304 assert (_selection != _hover);
1309 darea.queue_draw ();
1313 if (_dragging && _hover && _hover != _selection) {
1317 if (_hover == _actor && _actor && ev->button == 1) {
1318 assert (_selection);
1319 assert (_selection->dt == _actor->dt);
1321 assert (_dragging && _selection != _drag_dst);
1322 handle_disconnect (_drag_dst, true);
1324 if (_selection->ct == Input && _actor->ct == Sink) {
1325 handle_input_action (_actor, _selection);
1327 else if (_selection->ct == Sink && _actor->ct == Input) {
1328 handle_input_action (_selection, _actor);
1330 else if (_selection->ct == Output && _actor->ct == Source) {
1331 handle_output_action (_actor, _selection);
1333 else if (_selection->ct == Source && _actor->ct == Output) {
1334 handle_output_action (_selection, _actor);
1336 else if (_selection->ct == Input && _actor->ct == Output) {
1337 handle_thru_action (_actor, _selection);
1339 else if (_selection->ct == Output && _actor->ct == Input) {
1340 handle_thru_action (_selection, _actor);
1342 _selection.reset ();
1343 } else if (_hover == _selection && _selection && ev->button == 3) {
1344 handle_disconnect (_selection);
1345 } else if (!_hover && ev->button == 3) {
1346 reset_menu.popup (1, ev->time);
1349 if (_dragging && _hover != _selection) {
1350 _selection.reset ();
1355 darea.queue_draw ();
1360 PluginPinWidget::handle_input_action (const CtrlElem &s, const CtrlElem &i)
1362 const int pc = s->ip;
1364 ChanMapping in_map (_pi->input_map (pc));
1365 uint32_t idx = in_map.get (s->dt, s->id, &valid);
1367 if (valid && idx == i->id) {
1370 in_map.unset (s->dt, s->id);
1371 _pi->set_input_map (pc, in_map);
1373 plugin_reconfigured ();
1378 in_map.set (s->dt, s->id, i->id);
1379 _pi->set_input_map (pc, in_map);
1383 in_map.unset (s->dt, s->id);
1384 in_map.set (s->dt, s->id, i->id);
1385 _pi->set_input_map (pc, in_map);
1390 PluginPinWidget::disconnect_other_outputs (uint32_t skip_pc, DataType dt, uint32_t id)
1392 _ignore_updates = true;
1393 for (uint32_t n = 0; n < _n_plugins; ++n) {
1398 ChanMapping n_out_map (_pi->output_map (n));
1399 uint32_t idx = n_out_map.get_src (dt, id, &valid);
1401 n_out_map.unset (dt, idx);
1402 _pi->set_output_map (n, n_out_map);
1405 _ignore_updates = false;
1409 PluginPinWidget::disconnect_other_thru (DataType dt, uint32_t id)
1411 _ignore_updates = true;
1413 ChanMapping n_thru_map (_pi->thru_map ());
1414 n_thru_map.get (dt, id, &valid);
1416 n_thru_map.unset (dt, id);
1417 _pi->set_thru_map (n_thru_map);
1419 _ignore_updates = false;
1423 PluginPinWidget::handle_output_action (const CtrlElem &s, const CtrlElem &o)
1425 const uint32_t pc = s->ip;
1427 ChanMapping out_map (_pi->output_map (pc));
1428 uint32_t idx = out_map.get (s->dt, s->id, &valid);
1430 if (valid && idx == o->id) {
1433 out_map.unset (s->dt, s->id);
1434 _pi->set_output_map (pc, out_map);
1436 plugin_reconfigured ();
1440 // disconnect source
1441 disconnect_other_outputs (pc, s->dt, o->id);
1442 disconnect_other_thru (s->dt, o->id);
1443 out_map = _pi->output_map (pc); // re-read map
1445 out_map.unset (s->dt, s->id);
1447 idx = out_map.get_src (s->dt, o->id, &valid);
1449 out_map.unset (s->dt, idx);
1452 out_map.set (s->dt, s->id, o->id);
1453 _pi->set_output_map (pc, out_map);
1458 PluginPinWidget::handle_thru_action (const CtrlElem &o, const CtrlElem &i)
1461 ChanMapping thru_map (_pi->thru_map ());
1462 uint32_t idx = thru_map.get (o->dt, o->id, &valid);
1464 if (valid && idx == i->id) {
1466 thru_map.unset (o->dt, o->id);
1469 // disconnect other outputs first
1470 disconnect_other_outputs (UINT32_MAX, o->dt, o->id);
1471 disconnect_other_thru (o->dt, o->id);
1472 thru_map = _pi->thru_map (); // re-read map
1474 thru_map.set (o->dt, o->id, i->id);
1476 _pi->set_thru_map (thru_map);
1480 PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal)
1482 _ignore_updates = true;
1483 bool changed = false;
1489 ChanMapping n_thru_map (_pi->thru_map ());
1490 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1491 uint32_t idx = n_thru_map.get (e->dt, i, &valid);
1492 if (valid && idx == e->id) {
1493 n_thru_map.unset (e->dt, i);
1498 _pi->set_thru_map (n_thru_map);
1501 for (uint32_t n = 0; n < _n_plugins; ++n) {
1502 ChanMapping map (_pi->input_map (n));
1503 for (uint32_t i = 0; i < _sinks.n_total (); ++i) {
1504 uint32_t idx = map.get (e->dt, i, &valid);
1505 if (valid && idx == e->id) {
1506 map.unset (e->dt, i);
1510 _pi->set_input_map (n, map);
1515 ChanMapping map (_pi->input_map (e->ip));
1516 map.get (e->dt, e->id, &valid);
1518 map.unset (e->dt, e->id);
1519 _pi->set_input_map (e->ip, map);
1526 ChanMapping map (_pi->output_map (e->ip));
1527 map.get (e->dt, e->id, &valid);
1529 map.unset (e->dt, e->id);
1530 _pi->set_output_map (e->ip, map);
1536 for (uint32_t n = 0; n < _n_plugins; ++n) {
1537 ChanMapping map (_pi->output_map (n));
1538 for (uint32_t i = 0; i < _sources.n_total (); ++i) {
1539 uint32_t idx = map.get (e->dt, i, &valid);
1540 if (valid && idx == e->id) {
1541 map.unset (e->dt, i);
1546 _pi->set_output_map (n, map);
1550 ChanMapping n_thru_map (_pi->thru_map ());
1551 n_thru_map.get (e->dt, e->id, &valid);
1553 n_thru_map.unset (e->dt, e->id);
1555 _pi->set_thru_map (n_thru_map);
1560 _ignore_updates = false;
1561 if (changed && !no_signal) {
1562 plugin_reconfigured ();
1568 PluginPinWidget::toggle_sidechain ()
1570 if (!_route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ())) {
1571 error_message_dialog (_("Failed to toggle sidechain."));
1576 PluginPinWidget::connect_sidechain ()
1580 if (_sidechain_selector == 0) {
1581 _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
1584 if (_sidechain_selector->is_visible ()) {
1585 _sidechain_selector->get_toplevel ()->get_window ()->raise ();
1587 _sidechain_selector->present ();
1592 PluginPinWidget::reset_configuration ()
1595 if (_set_config.get_active ()) {
1596 rv = _route ()->reset_plugin_insert (_pi);
1598 rv = _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
1601 error_message_dialog (_("Failed to reset plugin configuration."));
1606 PluginPinWidget::reset_mapping ()
1612 PluginPinWidget::select_output_preset (uint32_t n_audio)
1614 ChanCount out (DataType::AUDIO, n_audio);
1615 if (!_route ()->plugin_preset_output (_pi, out)) {
1616 error_message_dialog (_("Failed to change channel preset."));
1621 PluginPinWidget::add_remove_plugin_clicked (bool add)
1623 ChanCount out = _out;
1624 ChanCount sinks = _sinks;
1625 assert (add || _n_plugins > 0);
1626 if (!_route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks)) {
1627 error_message_dialog (_("Failed to change instance count"));
1632 PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
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 if (!_route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks)) {
1639 error_message_dialog (_("Failed to alter plugin output configuration."));
1644 PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
1646 ChanCount out = _out;
1647 ChanCount sinks = _sinks;
1648 assert (add || sinks.get (dt) > 0);
1649 sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
1650 if (!_route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks)) {
1651 error_message_dialog (_("Failed to alter plugin input configuration."));
1656 PluginPinWidget::add_sidechain_port (DataType dt)
1659 if (_session->actively_recording ()) {
1660 error_message_dialog (/* unused */ "");
1664 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1669 // this triggers a PluginIoReConfigure with process and processor write lock held
1670 // from /this/ thread.
1671 io->add_port ("", this, dt);
1675 PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
1678 if (_session->actively_recording ()) {
1679 error_message_dialog (/* unused */ "");
1682 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1683 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1687 io->remove_port (p, this);
1691 PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
1694 if (_session->actively_recording ()) {
1695 error_message_dialog (/* unused */ "");
1699 boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
1700 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1704 p->disconnect_all ();
1708 PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
1711 if (_session->actively_recording ()) {
1712 error_message_dialog (/* unused */ "");
1716 boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
1717 boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
1718 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1719 if (!io || !p0 || !p1) {
1722 _ignore_updates = true;
1723 p0->disconnect_all ();
1724 _ignore_updates = false;
1725 p0->connect (p1->name ());
1729 PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
1732 if (_session->actively_recording ()) {
1733 error_message_dialog (/* unused */ "");
1737 boost::shared_ptr<Port> p = wp.lock ();
1738 boost::shared_ptr<Route> r = wr.lock ();
1739 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1740 if (!p || !r || !io) {
1744 boost::shared_ptr<Pannable> sendpan (new Pannable (*_session));
1745 boost::shared_ptr<Send> send (new Send (*_session, r->pannable (), r->mute_master ()));
1746 const ChanCount& outs (r->amp ()->input_streams ());
1748 Glib::Threads::Mutex::Lock lm (AudioEngine::instance ()->process_lock ());
1749 send->output()->ensure_io (outs, false, this);
1750 } catch (AudioEngine::PortRegistrationFailure& err) {
1751 error << string_compose (_("Cannot set up new send: %1"), err.what ()) << endmsg;
1755 std::string sendname = send->name ();
1756 string::size_type last_letter = sendname.find_last_not_of ("0123456789");
1757 if (last_letter != string::npos) {
1758 send->output ()->set_pretty_name (string_compose (_("SC %1 (%2)"),
1760 sendname.substr (last_letter + 1)));
1763 _ignore_updates = true;
1764 p->disconnect_all ();
1766 DataType dt = p->type ();
1767 PortSet& ps (send->output ()->ports ());
1768 for (PortSet::iterator i = ps.begin (dt); i != ps.end (dt); ++i) {
1769 p->connect (&(**i));
1772 send->set_remove_on_disconnect (true);
1773 r->add_processor (send, PreFader);
1774 _ignore_updates = false;
1775 queue_idle_update ();
1779 PluginPinWidget::sc_input_release (GdkEventButton *ev)
1782 if (_session->actively_recording ()) {
1783 error_message_dialog (/* unused */ "");
1787 if (ev->button == 3) {
1788 connect_sidechain ();
1794 PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
1796 using namespace Menu_Helpers;
1798 if (!ARDOUR_UI_UTILS::engine_is_running ()) {
1801 if (_session->actively_recording ()) {
1802 error_message_dialog (/* unused */ "");
1806 if (ev->button == 1) {
1807 MenuList& citems = input_menu.items ();
1808 input_menu.set_name ("ArdourContextMenu");
1811 boost::shared_ptr<Port> p = wp.lock ();
1812 if (p && p->connected ()) {
1813 citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::disconnect_port), wp)));
1814 citems.push_back (SeparatorElem ());
1818 // TODO add system inputs, too ?!
1819 boost::shared_ptr<ARDOUR::BundleList> b = _session->bundles ();
1820 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1821 for (uint32_t j = 0; j < i->nchannels ().n_total (); ++j) {
1823 //maybe_add_bundle_to_input_menu (*i, current);
1827 RouteList copy = _session->get_routelist ();
1828 copy.sort (Stripable::Sorter(true));
1830 for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
1831 added += maybe_add_route_to_input_menu (*i, p->type (), wp);
1835 citems.push_back (SeparatorElem ());
1837 citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinWidget::connect_sidechain)));
1838 input_menu.popup (1, ev->time);
1844 PluginPinWidget::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, DataType dt, boost::weak_ptr<Port> wp)
1847 using namespace Menu_Helpers;
1848 if (r->output () == _route ()->output ()) {
1852 if (_route ()->feeds_according_to_graph (r)) {
1856 MenuList& citems = input_menu.items ();
1858 /*check if there's already a send.. */
1859 bool already_present = false;
1861 boost::shared_ptr<Processor> proc;
1862 /* Note: nth_send () takes a processor read-lock */
1863 while ((proc = r->nth_send (nth))) {
1864 boost::shared_ptr<IOProcessor> send = boost::dynamic_pointer_cast<IOProcessor> (proc);
1865 if (!send || !send->output ()) {
1869 if (send->output ()->connected_to (_pi->sidechain_input ())) {
1870 // only if (send->remove_on_disconnect ()) ??
1871 already_present = true;
1876 /* we're going to create the new send pre-fader, so check the route amp's data type. */
1877 const ChanCount& rc (r->amp ()->input_streams ());
1878 if (!already_present && rc.get (dt) > 0) {
1879 citems.push_back (MenuElemNoMnemonic (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr<Route> (r))));
1886 PluginPinWidget::port_connected_or_disconnected (boost::weak_ptr<ARDOUR::Port> w0, boost::weak_ptr<ARDOUR::Port> w1)
1888 boost::shared_ptr<Port> p0 = w0.lock ();
1889 boost::shared_ptr<Port> p1 = w1.lock ();
1891 boost::shared_ptr<IO> io = _pi->sidechain_input ();
1892 if (!io) { return; }
1894 if (p0 && io->has_port (p0)) {
1895 queue_idle_update ();
1897 else if (p1 && io->has_port (p1)) {
1898 queue_idle_update ();
1902 /* lifted from ProcessorEntry::Control */
1903 PluginPinWidget::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
1905 , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain ()), 0, 1, 0.01, 0.1)
1906 , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable> (), 0, max (13.f, rintf (13.f * UIConfiguration::instance ().get_ui_scale ())))
1907 , _slider_persistant_tooltip (&_slider)
1908 , _ignore_ui_adjustment (false)
1911 _slider.set_controllable (c);
1912 box.set_padding (0, 0, 4, 4);
1914 _slider.set_name ("ProcessorControlSlider");
1915 _slider.set_text (_name);
1920 const ARDOUR::ParameterDescriptor& desc = c->desc ();
1921 double const lo = c->internal_to_interface (desc.lower);
1922 double const up = c->internal_to_interface (desc.upper);
1923 double const normal = c->internal_to_interface (desc.normal);
1924 double const smallstep = c->internal_to_interface (desc.lower + desc.smallstep);
1925 double const largestep = c->internal_to_interface (desc.lower + desc.largestep);
1927 _adjustment.set_lower (lo);
1928 _adjustment.set_upper (up);
1929 _adjustment.set_step_increment (smallstep);
1930 _adjustment.set_page_increment (largestep);
1931 _slider.set_default_value (normal);
1933 _adjustment.signal_value_changed ().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
1934 // dup. currently timers are used :(
1935 //c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
1937 // yuck, do we really need to do this?
1938 // according to c404374 this is only needed for send automation
1939 timer_connection = Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
1944 /* We're providing our own PersistentTooltip */
1945 set_no_tooltip_whatsoever (_slider);
1948 PluginPinWidget::Control::~Control ()
1950 timer_connection.disconnect ();
1954 PluginPinWidget::Control::set_tooltip ()
1956 boost::shared_ptr<AutomationControl> c = _control.lock ();
1960 std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ());
1961 string sm = Gtkmm2ext::markup_escape_text (tt);
1962 _slider_persistant_tooltip.set_tip (sm);
1966 PluginPinWidget::Control::slider_adjusted ()
1968 if (_ignore_ui_adjustment) {
1971 boost::shared_ptr<AutomationControl> c = _control.lock ();
1975 c->set_value ( c->interface_to_internal (_adjustment.get_value ()) , Controllable::NoGroup);
1981 PluginPinWidget::Control::control_changed ()
1983 boost::shared_ptr<AutomationControl> c = _control.lock ();
1988 _ignore_ui_adjustment = true;
1990 // as long as rapid timers are used, only update the tooltip
1991 // if the value has changed.
1992 const double nval = c->internal_to_interface (c->get_value ());
1993 if (_adjustment.get_value () != nval) {
1994 _adjustment.set_value (nval);
1998 _ignore_ui_adjustment = false;
2003 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
2004 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
2006 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
2011 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
2012 : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
2014 , _height_mapped (false)
2016 vbox = manage (new VBox ());
2017 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
2018 scroller = manage (new ScrolledWindow);
2019 scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
2020 scroller->set_shadow_type (Gtk::SHADOW_NONE);
2023 scroller->add (*vbox);
2027 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2029 _route->processors_changed.connect (
2030 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context()
2033 _route->DropReferences.connect (
2034 _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context()
2038 PluginPinDialog::set_session (ARDOUR::Session *s)
2040 SessionHandlePtr::set_session (s);
2041 for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) {
2042 (*i)->set_session (s);
2047 PluginPinDialog::map_height (Gtk::Allocation&)
2049 if (!_height_mapped) {
2050 scroller->set_size_request (-1, std::min (600, 2 + vbox->get_height()));
2051 _height_mapped = true;
2056 PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
2059 _height_mapped = false;
2060 scroller->remove ();
2061 vbox = manage (new VBox ());
2062 vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
2063 scroller->add (*vbox);
2064 _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
2069 PluginPinDialog::route_going_away ()
2077 PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
2079 boost::shared_ptr<Processor> proc = p.lock ();
2080 if (!proc || !proc->display_to_user ()) {
2083 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
2085 if (pi && pi->is_channelstrip ()) {
2090 ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
2091 ppw.back()->set_session (_session);
2092 vbox->pack_start (*ppw.back());
2094 HBox* hbox = manage (new HBox ());
2095 hbox->pack_start (*manage (new HSeparator ()));
2096 hbox->pack_start (*manage (new Label (proc->display_name ())));
2097 hbox->pack_start (*manage (new HSeparator ()));
2098 vbox->pack_start (*hbox, false, false);