X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Futils.cc;h=98b51cb5786be34d9922d65ef1ea4a724c69d9ac;hb=5a3a2fad4fd1c217a5771caa64efe92a0b305275;hp=e34fdd75a112fadd0732c5eb44c87c95dd5e8d43;hpb=40bc1c239eef8edfe08a456c189aff2cef3c6ee8;p=ardour.git diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index e34fdd75a1..98b51cb578 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -20,7 +20,7 @@ #include /* for sprintf */ #include #include -#include +#include #include #include #include @@ -94,7 +94,7 @@ legalize_for_path (ustring str) ustring::size_type pos; ustring legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=: "; ustring legal; - + legal = str; pos = 0; @@ -105,25 +105,45 @@ legalize_for_path (ustring str) return legal; } -#if 0 -string -legalize_for_path (string str) + +string bump_name_once(std::string name) { - string::size_type pos; - string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=: "; - string legal; + string::size_type period; + string newname; - legal = str; - pos = 0; + if ((period = name.find_last_of ('.')) == string::npos) { + newname = name; + newname += ".1"; + } else { + int isnumber = 1; + const char *last_element = name.c_str() + period + 1; + for (size_t i = 0; i < strlen(last_element); i++) { + if (!isdigit(last_element[i])) { + isnumber = 0; + break; + } + } - while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) { - legal.replace (pos, 1, "_"); - pos += 1; + errno = 0; + long int version = strtol (name.c_str()+period+1, (char **)NULL, 10); + + if (isnumber == 0 || errno != 0) { + // last_element is not a number, or is too large + newname = name; + newname += ".1"; + } else { + char buf[32]; + + snprintf (buf, sizeof(buf), "%ld", version+1); + + newname = name.substr (0, period+1); + newname += buf; + } } - return legal; + return newname; + } -#endif ostream& operator<< (ostream& o, const BBT_Time& bbt) @@ -320,7 +340,7 @@ compute_equal_power_fades (nframes_t nframes, float* in, float* out) { double step; - step = 1.0/nframes; + step = 1.0/(nframes-1); in[0] = 0.0f; @@ -348,6 +368,8 @@ string_to_edit_mode (string str) return Splice; } else if (str == _("Slide Edit")) { return Slide; + } else if (str == _("Lock Edit")) { + return Lock; } fatal << string_compose (_("programming error: unknown edit mode string \"%1\""), str) << endmsg; /*NOTREACHED*/ @@ -361,6 +383,9 @@ edit_mode_to_string (EditMode mode) case Slide: return _("Slide Edit"); + case Lock: + return _("Lock Edit"); + default: case Splice: return _("Splice Edit"); @@ -557,6 +582,14 @@ ARDOUR::auto_style_to_string (AutoStyle as) return ""; } +bool +string_is_affirmative (const std::string& str) +{ + /* to be used only with XML data - not intended to handle user input */ + + return str == "1" || str == "y" || str == "Y" || (!g_strncasecmp(str.c_str(), "yes", str.length())); +} + extern "C" { void c_stacktrace() { stacktrace (cerr); } }