From 6e0062d5498f90c52d6aeb87e63bc846d2922020 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 2 Mar 2020 17:43:10 +0100 Subject: Refactor send naming (#7905) This allows users to rename sends without enforcing a numeric bitslot number. However this prevents a user to to use "send" names that are potentially used for new sends or inserts. --- libs/ardour/ardour/io_processor.h | 8 ++++- libs/ardour/ardour/port_insert.h | 3 -- libs/ardour/ardour/return.h | 4 --- libs/ardour/ardour/send.h | 5 +-- libs/ardour/delivery.cc | 4 +-- libs/ardour/internal_send.cc | 2 +- libs/ardour/io_processor.cc | 67 ++++++++++++++++++++++++++++++++++++++- libs/ardour/port_insert.cc | 12 ++++--- libs/ardour/return.cc | 2 +- libs/ardour/send.cc | 17 ++-------- 10 files changed, 88 insertions(+), 36 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/ardour/io_processor.h b/libs/ardour/ardour/io_processor.h index 8707c16bf4..5e10e501e1 100644 --- a/libs/ardour/ardour/io_processor.h +++ b/libs/ardour/ardour/io_processor.h @@ -49,7 +49,7 @@ public: ARDOUR::DataType default_type = DataType::AUDIO, bool sendish=false); IOProcessor (Session&, boost::shared_ptr input, boost::shared_ptr output, - const std::string& proc_name, ARDOUR::DataType default_type = DataType::AUDIO); + const std::string& proc_name, bool sendish=false); virtual ~IOProcessor (); @@ -81,10 +81,16 @@ public: static void prepare_for_reset (XMLNode& state, const std::string& name); + uint32_t bit_slot() const { return _bitslot; } + protected: boost::shared_ptr _input; boost::shared_ptr _output; + /* used by PortInsert, Send & Return*/ + std::string validate_name (std::string const& new_name, std::string const& canonical_name) const; + uint32_t _bitslot; + private: /* disallow copy construction */ IOProcessor (const IOProcessor&); diff --git a/libs/ardour/ardour/port_insert.h b/libs/ardour/ardour/port_insert.h index 2b0f5ee27a..c5ad6cb5a7 100644 --- a/libs/ardour/ardour/port_insert.h +++ b/libs/ardour/ardour/port_insert.h @@ -71,8 +71,6 @@ public: void set_pre_fader (bool); - uint32_t bit_slot() const { return _bitslot; } - void start_latency_detection (); void stop_latency_detection (); @@ -90,7 +88,6 @@ private: boost::shared_ptr _out; - uint32_t _bitslot; MTDM* _mtdm; bool _latency_detect; samplecnt_t _latency_flush_samples; diff --git a/libs/ardour/ardour/return.h b/libs/ardour/ardour/return.h index 94c53aa44a..ec32270889 100644 --- a/libs/ardour/ardour/return.h +++ b/libs/ardour/ardour/return.h @@ -41,8 +41,6 @@ public: Return (Session&, bool internal = false); virtual ~Return (); - uint32_t bit_slot() const { return _bitslot; } - void run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool); boost::shared_ptr amp() const { return _amp; } @@ -74,8 +72,6 @@ private: /* disallow copy construction */ Return (const Return&); - uint32_t _bitslot; - void collect_input (BufferSet& bufs, pframes_t nframes, ChanCount offset = ChanCount::ZERO); }; diff --git a/libs/ardour/ardour/send.h b/libs/ardour/ardour/send.h index e711e68685..fe66053c02 100644 --- a/libs/ardour/ardour/send.h +++ b/libs/ardour/ardour/send.h @@ -68,8 +68,6 @@ public: Send (Session&, boost::shared_ptr pannable, boost::shared_ptr, Delivery::Role r = Delivery::Send, bool ignore_bitslot = false); virtual ~Send (); - uint32_t bit_slot() const { return _bitslot; } - bool display_to_user() const; bool is_foldback () const { return _role == Foldback; } @@ -128,8 +126,7 @@ private: int set_state_2X (XMLNode const &, int); - uint32_t _bitslot; - bool _remove_on_disconnect; + bool _remove_on_disconnect; }; } // namespace ARDOUR diff --git a/libs/ardour/delivery.cc b/libs/ardour/delivery.cc index b278b04c8b..54a2c9f03d 100644 --- a/libs/ardour/delivery.cc +++ b/libs/ardour/delivery.cc @@ -57,7 +57,7 @@ bool Delivery::panners_legal = false; Delivery::Delivery (Session& s, boost::shared_ptr io, boost::shared_ptr pannable, boost::shared_ptr mm, const string& name, Role r) - : IOProcessor(s, boost::shared_ptr(), (role_requires_output_ports (r) ? io : boost::shared_ptr()), name) + : IOProcessor(s, boost::shared_ptr(), (role_requires_output_ports (r) ? io : boost::shared_ptr()), name, (r == Send || r == Aux || r == Foldback)) , _role (r) , _output_buffers (new BufferSet()) , _current_gain (GAIN_COEFF_ZERO) @@ -81,7 +81,7 @@ Delivery::Delivery (Session& s, boost::shared_ptr io, boost::shared_ptr pannable, boost::shared_ptr mm, const string& name, Role r) - : IOProcessor(s, false, (role_requires_output_ports (r) ? true : false), name, "", DataType::AUDIO, (r == Send)) + : IOProcessor(s, false, (role_requires_output_ports (r) ? true : false), name, "", DataType::AUDIO, (r == Send || r == Aux || r == Foldback)) , _role (r) , _output_buffers (new BufferSet()) , _current_gain (GAIN_COEFF_ZERO) diff --git a/libs/ardour/internal_send.cc b/libs/ardour/internal_send.cc index 16a144ca6e..f7b38e1104 100644 --- a/libs/ardour/internal_send.cc +++ b/libs/ardour/internal_send.cc @@ -398,7 +398,7 @@ bool InternalSend::set_name (const string& str) { /* rules for external sends don't apply to us */ - return IOProcessor::set_name (str); + return Delivery::set_name (str); } string diff --git a/libs/ardour/io_processor.cc b/libs/ardour/io_processor.cc index 0bdb812b87..3dc6cf0c8d 100644 --- a/libs/ardour/io_processor.cc +++ b/libs/ardour/io_processor.cc @@ -31,6 +31,7 @@ #include "ardour/io_processor.h" #include "ardour/processor.h" #include "ardour/route.h" +#include "ardour/session.h" #include "ardour/session_object.h" #include "ardour/types.h" @@ -62,12 +63,15 @@ IOProcessor::IOProcessor (Session& s, bool with_input, bool with_output, if (with_output) { _output.reset (new IO(s, io_name.empty() ? proc_name : io_name, IO::Output, dtype, sendish)); } + if (!sendish) { + _bitslot = 0; + } } /* create an IOProcessor that proxies to an existing IO object */ IOProcessor::IOProcessor (Session& s, boost::shared_ptr in, boost::shared_ptr out, - const string& proc_name, DataType /*dtype*/) + const string& proc_name, bool sendish) : Processor(s, proc_name) , _input (in) , _output (out) @@ -83,6 +87,10 @@ IOProcessor::IOProcessor (Session& s, boost::shared_ptr in, boost::shared_pt } else { _own_output = true; } + + if (!sendish) { + _bitslot = 0; + } } IOProcessor::~IOProcessor () @@ -244,6 +252,63 @@ IOProcessor::natural_input_streams () const return _input ? _input->n_ports() : ChanCount::ZERO; } +std::string +IOProcessor::validate_name (std::string const& new_name, std::string const& canonical_name) const +{ + /* For use by Send::set_name() and PortInsert::set_name() + * + * allow canonical name e.g. + * _("insert %1"), bitslot) // PortInsert::name_and_id_new_insert + * _("send %1"), bitslot) // Send::name_and_id_new_send + * do *not* allow to use use potential canonical names with different + * bitslot id. + * + * Next, ensure that port-name is unique. Since ::set_name() is used + * when converting old sessions, a unique name has to be generated + */ + + bool ok = new_name == canonical_name; + + if (!ok) { + string unique_base; + /* strip existing numeric part (bitslot) of the name */ + string::size_type last_letter = new_name.find_last_not_of ("0123456789"); + if (last_letter != string::npos) { + unique_base = new_name.substr (0, last_letter + 1); + } + ok = unique_base != _("send ") && unique_base != _("insert ") && unique_base != _("return "); + } + + if (!ok || !_session.io_name_is_legal (new_name)) { + /* rip any existing numeric part of the name, and append the bitslot */ + string unique_base; + string::size_type last_letter = new_name.find_last_not_of ("0123456789-"); + if (last_letter != string::npos) { + unique_base = new_name.substr (0, last_letter + 1); + } else { + unique_base = new_name; + } + + int tries = 0; + std::string unique_name; + do { + unique_name = unique_base; + char buf[32]; + if (tries > 0 || !ok) { + snprintf (buf, sizeof (buf), "%u-%u", _bitslot, tries + (ok ? 0 : 1)); + } else { + snprintf (buf, sizeof (buf), "%u", _bitslot); + } + unique_name += buf; + if (25 == ++tries) { + return ""; + } + } while (!_session.io_name_is_legal (unique_name)); + return unique_name; + } + return new_name; +} + bool IOProcessor::set_name (const std::string& new_name) { diff --git a/libs/ardour/port_insert.cc b/libs/ardour/port_insert.cc index 49fe4ad385..46f9f686ab 100644 --- a/libs/ardour/port_insert.cc +++ b/libs/ardour/port_insert.cc @@ -42,7 +42,7 @@ string PortInsert::name_and_id_new_insert (Session& s, uint32_t& bitslot) { bitslot = s.next_insert_id (); - return string_compose (_("insert %1"), bitslot+ 1); + return string_compose (_("insert %1"), bitslot); } PortInsert::PortInsert (Session& s, boost::shared_ptr pannable, boost::shared_ptr mm) @@ -272,13 +272,15 @@ PortInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out) } bool -PortInsert::set_name (const std::string& name) +PortInsert::set_name (const std::string& new_name) { - bool ret = Processor::set_name (name); + string unique_name = validate_name (new_name, string_compose (_("insert %1"), _bitslot)); - ret = (ret && _input->set_name (name) && _output->set_name (name)); + if (unique_name.empty ()) { + return false; + } - return ret; + return IOProcessor::set_name (unique_name); } void diff --git a/libs/ardour/return.cc b/libs/ardour/return.cc index ff5331b8a4..e22e479116 100644 --- a/libs/ardour/return.cc +++ b/libs/ardour/return.cc @@ -47,7 +47,7 @@ Return::name_and_id_new_return (Session& s, uint32_t& bitslot) Return::Return (Session& s, bool internal) : IOProcessor (s, (internal ? false : true), false, - name_and_id_new_return (s, _bitslot)) + name_and_id_new_return (s, _bitslot), "", DataType::AUDIO, true) , _metering (false) { /* never muted */ diff --git a/libs/ardour/send.cc b/libs/ardour/send.cc index 3f1750be22..7202924906 100644 --- a/libs/ardour/send.cc +++ b/libs/ardour/send.cc @@ -485,22 +485,11 @@ Send::set_name (const string& new_name) string unique_name; if (_role == Delivery::Send) { - char buf[32]; + unique_name = validate_name (new_name, string_compose (_("send %1"), _bitslot)); - /* rip any existing numeric part of the name, and append the bitslot - */ - - string::size_type last_letter = new_name.find_last_not_of ("0123456789"); - - if (last_letter != string::npos) { - unique_name = new_name.substr (0, last_letter + 1); - } else { - unique_name = new_name; + if (unique_name.empty ()) { + return false; } - - snprintf (buf, sizeof (buf), "%u", (_bitslot + 1)); - unique_name += buf; - } else { unique_name = new_name; } -- cgit v1.2.3