diff --git a/libs/ardour/ardour/plugin_insert.h b/libs/ardour/ardour/plugin_insert.h index 2ba4c10b02..3893cbc57a 100644 --- a/libs/ardour/ardour/plugin_insert.h +++ b/libs/ardour/ardour/plugin_insert.h @@ -135,6 +135,7 @@ public: void set_output_map (uint32_t, ChanMapping); void set_thru_map (ChanMapping); bool reset_map (bool emit = true); + bool reset_sidechain_map (); bool configured () const { return _configured; } // these are ports visible on the outside diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index 786f283e96..8d27e8704e 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -1968,6 +1968,53 @@ PluginInsert::reset_map (bool emit) return true; } +bool +PluginInsert::reset_sidechain_map () +{ + /* intended to be called from Route::add_remove_sidechain after + * adding a SC. This connects the SC ports like reset_map() above. + */ + + if (!has_sidechain () || sidechain_input_pins ().n_total () == 0) { + return false; + } + if (_custom_cfg) { + return false; + } + + const PinMappings old_in (_in_map); + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + uint32_t sc = 0; // side-chain round-robin (all instances) + uint32_t pc = 0; + for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) { + const uint32_t nis = natural_input_streams ().get(*t); + + /* SC inputs are last in the plugin-insert.. */ + const uint32_t sc_start = _configured_in.get (*t); + const uint32_t sc_len = _configured_internal.get (*t) - sc_start; + + for (uint32_t in = 0; in < nis; ++in) { + const Plugin::IOPortDescription& iod (_plugins[pc]->describe_io_port (*t, true, in)); + if (iod.is_sidechain) { + /* connect sidechain sinks to sidechain inputs in round-robin fashion */ + if (sc_len > 0) {// side-chain may be hidden + _in_map[pc].set (*t, in, sc_start + sc); + sc = (sc + 1) % sc_len; + } + } + } + } + } + + sanitize_maps (); + if (old_in == _in_map) { + return false; + } + + mapping_changed (); + return true; +} + bool PluginInsert::configure_io (ChanCount in, ChanCount out) { diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 09d20e4612..5e14f6dd54 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -2353,7 +2353,11 @@ Route::add_remove_sidechain (boost::shared_ptr proc, bool add) PBD::Unwinder uw (_in_sidechain_setup, true); if (add) { - if (!pi->add_sidechain ()) { + ChanCount sc (pi->sidechain_input_pins ()); + if (sc.n_audio () == 0 && sc.n_midi () == 0) { + sc.set (DataType::AUDIO, 1); + } + if (!pi->add_sidechain (sc.n_audio (), sc.n_midi ())) { return false; } } else { @@ -2384,6 +2388,7 @@ Route::add_remove_sidechain (boost::shared_ptr proc, bool add) } if (pi->has_sidechain ()) { + pi->reset_sidechain_map (); pi->sidechain_input ()->changed.connect_same_thread (*pi, boost::bind (&Route::sidechain_change_handler, this, _1, _2)); }