13
0

Connect sidechain pins when adding sidechain [ports]

This is in preparation to allow to skip adding sidechain ports
by default. When a user later adds the SC input ports, it is
convenient to connect the pins just like they are when they
are connected when instantiating the plugin (via reset_map).
This commit is contained in:
Robin Gareus 2023-02-05 15:55:29 +01:00
parent 64ec70ec20
commit 55d1b66b72
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 54 additions and 1 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -2353,7 +2353,11 @@ Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
PBD::Unwinder<bool> 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<Processor> 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));
}