Add method to create an alphanumerical sequence

This is intended for new group-names. This avoids ambiguity
with track numbers when using defaults.
This commit is contained in:
Robin Gareus 2024-05-21 18:20:06 +02:00
parent 2d5884ccb1
commit 710a22521f
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 39 additions and 0 deletions

View File

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

View File

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