save and restore clock modes
[ardour.git] / libs / ardour / location.cc
index 5a75c2bc16e06d6223f59e0f12d50a0f82d97c69..bec87e5dd6b6d41863304aa3e5e0183720bdde81 100644 (file)
@@ -36,6 +36,8 @@
 
 #include "i18n.h"
 
+#define SUFFIX_MAX 32
+
 using namespace std;
 using namespace ARDOUR;
 using namespace sigc;
@@ -401,6 +403,40 @@ Locations::set_current (Location *loc, bool want_lock)
        return ret;
 }
 
+int
+Locations::next_available_name(string& result,string base)
+{
+       LocationList::iterator i;
+       Location* location;
+       string temp;
+       string::size_type l;
+       int suffix;
+       char buf[32];
+       bool available[SUFFIX_MAX+1];
+
+       result = base;
+       for (int k=1; k<SUFFIX_MAX; k++) {
+               available[k] = true;
+       }
+       l = base.length();
+       for (i = locations.begin(); i != locations.end(); ++i) {
+               location =* i;
+               temp = location->name();
+               if (l && !temp.find(base,0)) {
+                       suffix = atoi(temp.substr(l,3));
+                       if (suffix) available[suffix] = false;
+               }
+       }
+       for (int k=1; k<=SUFFIX_MAX; k++) {
+               if (available[k]) { 
+                       snprintf (buf, 31, "%d", k);
+                       result += buf;
+                       return 1;
+               }
+       }
+       return 0;
+}
+
 int
 Locations::set_current_unlocked (Location *loc)
 {