use PortManager::port_name_prefix_is_unique to check for new route names
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 10 Sep 2015 20:27:14 +0000 (16:27 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 10 Sep 2015 20:41:34 +0000 (16:41 -0400)
libs/ardour/session.cc

index c3eca166df072c708b9f9c1156a81f1f731d4533..99e3bdd958cd44cd34ef9738a2f181cbe1a0f08c 100644 (file)
@@ -2198,14 +2198,37 @@ Session::resort_routes_using (boost::shared_ptr<RouteList> r)
 bool
 Session::find_route_name (string const & base, uint32_t& id, string& name, bool definitely_add_number)
 {
-       if (!definitely_add_number && route_by_name (base) == 0) {
+       string el_base = base;
+       
+       /* the base may conflict with ports that do not belong to existing
+          routes, but hidden objects like the click track. So check port names
+          before anything else.
+       */
+
+       
+       if (!_engine.port_name_prefix_is_unique (base)) {
+               uint32_t unique_port_suffix = 1;
+
+               do {
+                       string possible = string_compose (X_("%1-%2"), base, unique_port_suffix);
+                       if (_engine.port_name_prefix_is_unique (possible)) {
+                               el_base = possible;
+                               break;
+                       }
+
+                       unique_port_suffix++;
+
+               } while (unique_port_suffix < UINT_MAX);
+       }
+
+       if (!definitely_add_number && route_by_name (el_base) == 0) {
                /* juse use the base */
-               name = base;
+               name = el_base;
                return true;
        }
 
        do {
-               name = string_compose ("%1 %2", base, id);
+               name = string_compose ("%1 %2", el_base, id);
 
                if (route_by_name (name) == 0) {
                        return true;