From 710a22521f2cd7c1db401f2a882f5aa6dd89cfd0 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 21 May 2024 18:20:06 +0200 Subject: [PATCH 1/2] Add method to create an alphanumerical sequence This is intended for new group-names. This avoids ambiguity with track numbers when using defaults. --- libs/ardour/ardour/utils.h | 1 + libs/ardour/utils.cc | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h index 22a99c758f..32c27fc26a 100644 --- a/libs/ardour/ardour/utils.h +++ b/libs/ardour/ardour/utils.h @@ -70,6 +70,7 @@ static inline float f_max(float x, float a) { LIBARDOUR_API std::string bump_name_once(const std::string& s, char delimiter); LIBARDOUR_API std::string bump_name_number(const std::string& s); +LIBARDOUR_API std::string bump_name_abc(const std::string& s); LIBARDOUR_API int cmp_nocase (const std::string& s, const std::string& s2); LIBARDOUR_API int cmp_nocase_utf8 (const std::string& s1, const std::string& s2); diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index 25b31f4984..4ecdd22c8c 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -232,6 +232,44 @@ ARDOUR::bump_name_number (const std::string& name) return newname; } +string +ARDOUR::bump_name_abc (const std::string& name) +{ + /* A, B, C, .. Z, A1, B1, .. Z1, A2 .. Z2, A3 .. */ + static char const* abc = _("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + if (name.empty ()) { + return {abc[0]}; + } + + /* check first char */ + char first = toupper (name[0]); + + char const* end = abc + strlen (abc); + char const* pos = std::find (abc, end, first); + + /* first char is not in the given set. Start over */ + if (pos == end) { + return {abc[0]}; + } + + ++pos; + if (pos != end) { + string rv = name; + rv[0] = *pos; + return rv; + } + + /* find number */ + size_t num = 0; + if (name.length () > 1) { + num = strtol (name.c_str() + 1, (char **)NULL, 10); + } + ++num; + + return string_compose ("%1%2", abc[0], num); +} + + XMLNode * ARDOUR::find_named_node (const XMLNode& node, string name) { From 0929faf830b737e9f91b67f40d7013dc707ae2e3 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 21 May 2024 18:21:16 +0200 Subject: [PATCH 2/2] Use alphabet instead of numbers for new group names --- gtk2_ardour/route_group_dialog.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtk2_ardour/route_group_dialog.cc b/gtk2_ardour/route_group_dialog.cc index 2d3317f794..437ba71df5 100644 --- a/gtk2_ardour/route_group_dialog.cc +++ b/gtk2_ardour/route_group_dialog.cc @@ -115,9 +115,9 @@ RouteGroupDialog::RouteGroupDialog (RouteGroup* g, bool creating_new) _share_monitoring.set_active (_group->is_monitoring()); if (_group->name ().empty()) { - _initial_name = "1"; + _initial_name = bump_name_abc (""); while (!unique_name (_initial_name)) { - _initial_name = bump_name_number (_initial_name); + _initial_name = bump_name_abc (_initial_name); } _name.set_text (_initial_name); update();