13
0

Merge branch 'ardour'

This commit is contained in:
Robin Gareus 2024-05-21 18:23:56 +02:00
commit d631a6562f
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 41 additions and 2 deletions

View File

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

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