From b72268f6e106f61f73edb6b4fa252305fe60ee9f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 4 Jan 2022 01:22:34 +0100 Subject: [PATCH] triggerbox: rename sidechain port when track's name chanes Just like PluginInsert::update_sidechain_name, the name is implicitly set, using the owning route's name, suffixed with the [i18n localized] Processor name. This fixes an issue if a track is renamed and a new track with the old name is created. This commonly happens during File Import: For each ImportAsTrack a generic named track (e.g. "Audio") is created before it is renamed. Previously this lead to Failed to register port "Audio 1-trig/midi_in 1", reason is unknown from here --- libs/ardour/ardour/triggerbox.h | 3 ++- libs/ardour/route.cc | 7 +++++++ libs/ardour/session.cc | 2 +- libs/ardour/triggerbox.cc | 32 ++++++++++++++++++-------------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index a817438587..5070425dd0 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -541,7 +541,8 @@ class LIBARDOUR_API TriggerBox : public Processor TriggerPtr get_next_trigger (); TriggerPtr peek_next_trigger (); - void add_midi_sidechain (std::string const & name); + void add_midi_sidechain (); + void update_sidechain_name (); bool pass_thru() const { return _requests.pass_thru; } void set_pass_thru (bool yn); diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 547177e4b4..f4e9155cec 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -3160,8 +3160,11 @@ Route::set_processor_state (const XMLNode& node, int version) cerr << "Seen triggerbox!\n"; if (!_triggerbox) { _triggerbox.reset (new TriggerBox (_session, _default_type)); + _triggerbox->set_owner (this); } _triggerbox->set_state (**niter, version); + _triggerbox->update_sidechain_name (); + new_order.push_back (_triggerbox); } else { set_processor_state (**niter, version, prop, new_order, must_configure); @@ -4581,6 +4584,10 @@ Route::set_name (const string& str) pi->update_sidechain_name (); } + if (_triggerbox) { + _triggerbox->update_sidechain_name (); + } + bool ret = (_input->set_name(newname) && _output->set_name(newname)); if (ret) { diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index aea4582de1..cb5df9fede 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -2740,7 +2740,7 @@ Session::new_audio_track (int input_channels, int output_channels, RouteGroup* r * data type is AUDIO, the triggerbox will need * a sidehcain MIDI input to be able to be MIDI controlled */ - tb->add_midi_sidechain (track->name()); + tb->add_midi_sidechain (); track->presentation_info ().set_trigger_track (true); } diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 192e341371..e53760ccc0 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -2158,10 +2158,11 @@ TriggerBox::trigger (Triggers::size_type n) } void -TriggerBox::add_midi_sidechain (std::string const & name) +TriggerBox::add_midi_sidechain () { + assert (owner()); if (!_sidechain) { - _sidechain.reset (new SideChain (_session, name + "-trig")); + _sidechain.reset (new SideChain (_session, string_compose ("%1/%2", owner()->name(), name ()))); _sidechain->activate (); _sidechain->input()->add_port ("", owner(), DataType::MIDI); // add a port, don't connect. boost::shared_ptr p = _sidechain->input()->nth (0); @@ -2174,6 +2175,16 @@ TriggerBox::add_midi_sidechain (std::string const & name) } } +void +TriggerBox::update_sidechain_name () +{ + if (!_sidechain) { + return; + } + assert (owner()); + _sidechain->set_name (string_compose ("%1/%2", owner()->name(), name ())); +} + bool TriggerBox::can_support_io_configuration (const ChanCount& in, ChanCount& out) { @@ -2831,12 +2842,7 @@ TriggerBox::get_state (void) node.add_child_nocopy (*trigger_child); if (_sidechain) { - XMLNode* scnode = new XMLNode (X_("Sidechain")); - std::string port_name = _sidechain->input()->nth (0)->name(); - port_name = port_name.substr (0, port_name.find ('-')); - scnode->set_property (X_("name"), port_name); - scnode->add_child_nocopy (_sidechain->get_state()); - node.add_child_nocopy (*scnode); + node.add_child_nocopy (_sidechain->get_state ()); } return node; @@ -2881,14 +2887,12 @@ TriggerBox::set_state (const XMLNode& node, int version) } } - XMLNode* scnode = node.child (X_("Sidechain")); - + /* sidechain is a Processor (IO) */ + XMLNode* scnode = node.child (Processor::state_node_name.c_str ()); if (scnode) { - std::string name; - scnode->get_property (X_("name"), name); - add_midi_sidechain (name); + add_midi_sidechain (); assert (_sidechain); - _sidechain->set_state (*scnode->children().front(), version); + _sidechain->set_state (*scnode, version); } return 0;