add PortManager::port_name_prefix_is_unique()
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 10 Sep 2015 20:26:48 +0000 (16:26 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 10 Sep 2015 20:41:34 +0000 (16:41 -0400)
libs/ardour/ardour/port_manager.h
libs/ardour/port_manager.cc

index 71b18f2f785cf6e5800e2d111c23728a82c5e201..390369fefdca7ec4b7932a56cef6ac5e56aaa6c0 100644 (file)
@@ -81,7 +81,8 @@ class LIBARDOUR_API PortManager
     std::string             make_port_name_non_relative (const std::string& name) const;
     std::string             get_pretty_name_by_name (const std::string& portname) const;
     bool                    port_is_mine (const std::string& fullname) const;
-
+    bool                    port_name_prefix_is_unique (const std::string& first_part_of_port_name) const;
+    
     /* other Port management */
     
     bool      port_is_physical (const std::string&) const;
index a1a4397551be76e88f3dd58252793b531c570db8..02e7719cc4c9bd6009f9357bb14df23a2e831763 100644 (file)
@@ -17,6 +17,7 @@
 
 */
 
+#include "pbd/convert.h"
 #include "pbd/error.h"
 
 #include "ardour/async_midi_port.h"
@@ -197,6 +198,28 @@ PortManager::n_physical_inputs () const
        return _backend->n_physical_inputs ();
 }
 
+bool
+PortManager::port_name_prefix_is_unique (const string& first_part_of_port_name) const
+{
+       if (!_backend) {
+               return boost::shared_ptr<Port>();
+       }
+
+       boost::shared_ptr<const Ports> pr = ports.reader();
+       const string::size_type len = first_part_of_port_name.length();
+       
+       for (Ports::const_iterator x = pr->begin(); x != pr->end(); ++x) {
+
+               string prefix = x->first.substr (0, len); 
+
+               if (strings_equal_ignore_case (prefix, first_part_of_port_name)) {
+                       return false;
+               }
+       }
+
+       return true;
+}
+
 /** @param name Full or short name of port
  *  @return Corresponding Port or 0.
  */