Make sure buses and tracks have unique names.
authorSampo Savolainen <v2@iki.fi>
Sat, 9 Feb 2008 10:32:45 +0000 (10:32 +0000)
committerSampo Savolainen <v2@iki.fi>
Sat, 9 Feb 2008 10:32:45 +0000 (10:32 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3033 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/playlist.h
libs/ardour/ardour/route.h
libs/ardour/ardour/utils.h
libs/ardour/io.cc
libs/ardour/playlist.cc
libs/ardour/route.cc
libs/ardour/utils.cc

index c80330c04af66bdc236268fecdbee5d3e3bd8a7d..0e7bf4eff91e6a4c6bb08a739ee19045a87b67dd 100644 (file)
@@ -124,7 +124,6 @@ class Playlist : public PBD::StatefulDestructible, public boost::enable_shared_f
        sigc::signal<void>      LayeringChanged;
 
        static string bump_name (string old_name, Session&);
-       static string bump_name_once (string old_name);
 
        void freeze ();
        void thaw ();
index 5b927d255fa7eb3a79b3ef31583a11a754e521aa..e4fb003e09d4f357450a14d7d93fa0e121d0c14c 100644 (file)
@@ -74,6 +74,8 @@ class Route : public IO
        Route (Session&, const XMLNode&, DataType default_type = DataType::AUDIO);
        virtual ~Route();
 
+       static std::string ensure_track_or_route_name(std::string, Session &);
+
        std::string comment() { return _comment; }
        void set_comment (std::string str, void *src);
 
index 0d4ce08adce2b46a8056305e9802b34c37bf2997..5f392ca5b4abad5898df915a9dfaee58138dc943 100644 (file)
@@ -46,6 +46,8 @@ static inline float f_max(float x, float a) {
        return (x);
 }
 
+std::string bump_name_once(std::string s);
+
 int cmp_nocase (const std::string& s, const std::string& s2);
 
 int tokenize_fullpath (std::string fullpath, std::string& path, std::string& name);
index b3bfd82271711a75400c67d1c8063537580d6551..4f74b70e576086d486a125dbc9b4983ec8a20dcd 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <ardour/audioengine.h>
 #include <ardour/io.h>
+#include <ardour/route.h>
 #include <ardour/port.h>
 #include <ardour/connection.h>
 #include <ardour/session.h>
@@ -2056,12 +2057,21 @@ IO::parse_gain_string (const string& str, vector<string>& ports)
 }
 
 int
-IO::set_name (string name, void* src)
+IO::set_name (string requested_name, void* src)
 {
-       if (name == _name) {
+       if (requested_name == _name) {
                return 0;
        }
 
+       string name;
+       Route *rt;
+       if ( (rt = dynamic_cast<Route *>(this))) {
+               name = Route::ensure_track_or_route_name(requested_name, _session);
+       } else {
+               name = requested_name;
+       }
+
+
        /* replace all colons in the name. i wish we didn't have to do this */
 
        if (replace_all (name, ":", "-")) {
index aa79812f9896fb5e264548ea494a5f639dd89db8..3aa14a055850f42ec09c6494881b502a569133bc 100644 (file)
@@ -1796,50 +1796,12 @@ Playlist::bump_name (string name, Session &session)
        string newname = name;
 
        do {
-               newname = Playlist::bump_name_once (newname);
+               newname = bump_name_once (newname);
        } while (session.playlist_by_name (newname)!=NULL);
 
        return newname;
 }
 
-string
-Playlist::bump_name_once (string name)
-{
-       string::size_type period;
-       string newname;
-
-       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;
-                       }
-               }
-
-               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 newname;
-}
 
 layer_t
 Playlist::top_layer() const
index f1953af38646b6de83d0e52ae93acccea434fe53..95571bd3dab2f48254876fbcb8486547d7f8b479 100644 (file)
@@ -184,6 +184,20 @@ Route::sync_order_keys ()
        }
 }
 
+string
+Route::ensure_track_or_route_name(string name, Session &session)
+{
+       string newname = name;
+
+       while (session.route_by_name (newname)!=NULL)
+       {
+               newname = bump_name_once (newname);
+       }
+
+       return newname;
+}
+
+
 void
 Route::inc_gain (gain_t fraction, void *src)
 {
index e34fdd75a112fadd0732c5eb44c87c95dd5e8d43..948b4099869fe804ebf9064129b028ce644477cb 100644 (file)
@@ -125,6 +125,45 @@ legalize_for_path (string str)
 }
 #endif
 
+string bump_name_once(std::string name)
+{
+       string::size_type period;
+       string newname;
+
+       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;
+                       }
+               }
+
+               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 newname;
+
+}
+
 ostream&
 operator<< (ostream& o, const BBT_Time& bbt)
 {