don't display internal returns to user
[ardour.git] / libs / ardour / port_set.cc
index b96e45662b945da03a9e513ddb6a4e3e6c02ca81..35c8d9f410dcc33cf9839d36ea8e23472aa1a0f9 100644 (file)
     675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <string>
+
 #include "ardour/port_set.h"
 #include "ardour/midi_port.h"
 #include "ardour/audio_port.h"
 
+using std::string;
+
 namespace ARDOUR {
 
 PortSet::PortSet()
@@ -30,7 +34,41 @@ PortSet::PortSet()
 
 static bool sort_ports_by_name (Port* a, Port* b)
 {
-       return (a->name() < b->name());
+        string aname (a->name());
+        string bname (b->name());
+        
+        string::size_type last_digit_position_a = aname.size();
+        string::reverse_iterator r_iterator = aname.rbegin();
+        
+        while (r_iterator!= aname.rend() && Glib::Unicode::isdigit(*r_iterator)) {
+                r_iterator++; 
+                last_digit_position_a--;
+        }
+        
+        string::size_type last_digit_position_b = bname.size();
+        r_iterator = bname.rbegin();
+        
+        while (r_iterator != bname.rend() && Glib::Unicode::isdigit(*r_iterator)) {
+                r_iterator++; 
+                last_digit_position_b--;
+        }
+        
+        // if some of the names don't have a number as posfix, compare as strings
+
+        if (last_digit_position_a == aname.size() or last_digit_position_b == bname.size()) {
+                return aname < bname;
+        }
+        
+        const std::string       prefix_a = aname.substr(0, last_digit_position_a - 1);
+        const unsigned int      posfix_a = std::atoi(aname.substr(last_digit_position_a, aname.size() - last_digit_position_a).c_str());
+        const std::string       prefix_b = bname.substr(0, last_digit_position_b - 1);
+        const unsigned int      posfix_b = std::atoi(bname.substr(last_digit_position_b, bname.size() - last_digit_position_b).c_str());
+        
+        if (prefix_a != prefix_b) {
+                return aname < bname;
+        } else {
+                return posfix_a < posfix_b;
+        }
 }
 
 void