From 342422203d11f89d574bf38fd9c8221de3489970 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 6 Apr 2016 02:31:36 +0200 Subject: [PATCH] Populate Sidechain connection menu with non-feeback sources. --- gtk2_ardour/plugin_pin_dialog.cc | 103 ++++++++++++++++++++++++++----- gtk2_ardour/plugin_pin_dialog.h | 3 + 2 files changed, 91 insertions(+), 15 deletions(-) diff --git a/gtk2_ardour/plugin_pin_dialog.cc b/gtk2_ardour/plugin_pin_dialog.cc index eab3d9e6bb..f25dd6497b 100644 --- a/gtk2_ardour/plugin_pin_dialog.cc +++ b/gtk2_ardour/plugin_pin_dialog.cc @@ -21,6 +21,8 @@ #include #include +#include "pbd/replace_all.h" + #include "gtkmm2ext/utils.h" #include "gtkmm2ext/rgb_macros.h" @@ -330,10 +332,6 @@ PluginPinDialog::refill_sidechain_table () return; } - io->changed.connect ( - _io_connection, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context () - ); - uint32_t r = 0; PortSet& p (io->ports ()); bool can_remove = p.num_ports () > 1; @@ -344,6 +342,10 @@ PluginPinDialog::refill_sidechain_table () add_port_to_table (*i, r, can_remove); } _sidechain_tbl->show_all (); + + io->changed.connect ( + _io_connection, invalidator (*this), boost::bind (&PluginPinDialog::io_changed_proxy, this), gui_context () + ); } void @@ -359,10 +361,10 @@ PluginPinDialog::add_port_to_table (boost::shared_ptr p, uint32_t r, bool lbl = "-"; } else if (cns.size () > 1) { lbl = "..."; - tip += " >- "; + tip += " <- "; } else { lbl = cns[0]; - tip += " >- "; + tip += " <- "; if (lbl.find ("system:") == 0) { lbl = AudioEngine::instance ()->get_pretty_name_by_name (lbl); if (lbl.empty ()) { @@ -958,7 +960,6 @@ PluginPinDialog::handle_disconnect (const CtrlElem &e) _ignore_updates = true; bool changed = false; bool valid; - //ChanMapping out_map (_pi->output_map (pc)); switch (e->ct) { case Input: @@ -1102,9 +1103,39 @@ PluginPinDialog::disconnect_port (boost::weak_ptr wp) if (!io || !p) { return; } - io->disconnect (this); + p->disconnect_all (); + io_changed_proxy (); } +void +PluginPinDialog::connect_port (boost::weak_ptr wp0, boost::weak_ptr wp1) +{ + if (_session && _session->actively_recording()) { return; } + boost::shared_ptr p0 = wp0.lock (); + boost::shared_ptr p1 = wp1.lock (); + boost::shared_ptr io = _pi->sidechain_input (); + if (!io || !p0 || !p1) { + return; + } + p0->connect (p1->name ()); + io_changed_proxy (); +} + +bool +PluginPinDialog::sc_input_release (GdkEventButton *ev) +{ + if (_session && _session->actively_recording()) { return false; } + if (ev->button == 3) { + connect_sidechain (); + } + return false; +} + +struct RouteCompareByName { + bool operator() (boost::shared_ptr a, boost::shared_ptr b) { + return a->name().compare (b->name()) < 0; + } +}; bool PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr wp) @@ -1117,24 +1148,66 @@ PluginPinDialog::sc_input_press (GdkEventButton *ev, boost::weak_ptr p = wp.lock (); if (p && p->connected ()) { citems.push_back (MenuElem (_("Disconnect"), sigc::bind (sigc::mem_fun (*this, &PluginPinDialog::disconnect_port), wp))); citems.push_back (SeparatorElem()); } + + // TODO add system inputs, too ?! + + boost::shared_ptr routes = _session->get_routes (); + RouteList copy = *routes; + copy.sort (RouteCompareByName ()); + uint32_t added = 0; + for (ARDOUR::RouteList::const_iterator i = copy.begin(); i != copy.end(); ++i) { + added += maybe_add_route_to_input_menu (*i, p->type (), wp); + } + + if (added > 0) { + citems.push_back (SeparatorElem()); + } citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*this, &PluginPinDialog::connect_sidechain))); input_menu.popup (1, ev->time); } return false; } -bool -PluginPinDialog::sc_input_release (GdkEventButton *ev) +uint32_t +PluginPinDialog::maybe_add_route_to_input_menu (boost::shared_ptr r, DataType dt, boost::weak_ptr wp) { - if (_session && _session->actively_recording()) { return false; } - if (ev->button == 3) { - connect_sidechain (); + uint32_t added = 0; + using namespace Menu_Helpers; + if (r->output () == _route()->output()) { + return added; } - return false; + + if (_route ()->feeds_according_to_graph (r)) { + return added; + } + + MenuList& citems = input_menu.items(); + const IOVector& iov (r->all_outputs()); + + for (IOVector::const_iterator o = iov.begin(); o != iov.end(); ++o) { + boost::shared_ptr op = o->lock(); + if (!op) { + continue; + } + PortSet& p (op->ports ()); + for (PortSet::iterator i = p.begin (dt); i != p.end (dt); ++i) { + std::string n = i->name (); + replace_all (n, "_", " "); + citems.push_back (MenuElem (n, sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::connect_port), wp, boost::weak_ptr (*i)))); + ++added; + } + } + return added; +} + +void +PluginPinDialog::io_changed_proxy () +{ + Glib::signal_idle().connect_once (sigc::mem_fun (*this, &PluginPinDialog::plugin_reconfigured)); } diff --git a/gtk2_ardour/plugin_pin_dialog.h b/gtk2_ardour/plugin_pin_dialog.h index f99fc10f1c..64cda8cdf1 100644 --- a/gtk2_ardour/plugin_pin_dialog.h +++ b/gtk2_ardour/plugin_pin_dialog.h @@ -129,6 +129,9 @@ private: void add_port_to_table (boost::shared_ptr, uint32_t, bool); void remove_port (boost::weak_ptr); void disconnect_port (boost::weak_ptr); + void connect_port (boost::weak_ptr, boost::weak_ptr); + uint32_t maybe_add_route_to_input_menu (boost::shared_ptr, ARDOUR::DataType, boost::weak_ptr); + void io_changed_proxy (); bool sc_input_press (GdkEventButton *, boost::weak_ptr); bool sc_input_release (GdkEventButton *);