summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-03-02 17:43:10 +0100
committerRobin Gareus <robin@gareus.org>2020-03-02 20:07:52 +0100
commit6e0062d5498f90c52d6aeb87e63bc846d2922020 (patch)
tree8ad1c0227e87123cb022f6931b7ff927afb235d5 /libs
parent711f20a469e31ba8fe8d1474969855825dab834c (diff)
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.
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/io_processor.h8
-rw-r--r--libs/ardour/ardour/port_insert.h3
-rw-r--r--libs/ardour/ardour/return.h4
-rw-r--r--libs/ardour/ardour/send.h5
-rw-r--r--libs/ardour/delivery.cc4
-rw-r--r--libs/ardour/internal_send.cc2
-rw-r--r--libs/ardour/io_processor.cc67
-rw-r--r--libs/ardour/port_insert.cc12
-rw-r--r--libs/ardour/return.cc2
-rw-r--r--libs/ardour/send.cc17
10 files changed, 88 insertions, 36 deletions
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<IO> input, boost::shared_ptr<IO> 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<IO> _input;
boost::shared_ptr<IO> _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<Delivery> _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> 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> pannable, boost::shared_ptr<MuteMaster>, 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> io, boost::shared_ptr<Pannable> pannable,
boost::shared_ptr<MuteMaster> mm, const string& name, Role r)
- : IOProcessor(s, boost::shared_ptr<IO>(), (role_requires_output_ports (r) ? io : boost::shared_ptr<IO>()), name)
+ : IOProcessor(s, boost::shared_ptr<IO>(), (role_requires_output_ports (r) ? io : boost::shared_ptr<IO>()), 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> io, boost::shared_ptr<Pann
/* deliver to a new IO object */
Delivery::Delivery (Session& s, boost::shared_ptr<Pannable> pannable, boost::shared_ptr<MuteMaster> 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<IO> in, boost::shared_ptr<IO> 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<IO> 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> pannable, boost::shared_ptr<MuteMaster> 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;
}