summaryrefslogtreecommitdiff
path: root/libs/ardour/port_set.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-03-16 15:33:04 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-03-16 15:33:04 +0000
commit6ef5d85ae1f2c500c4163cd1df580b3f26991c1e (patch)
tree15194a52bb72f036117fc4c87c193a4cbb64be8b /libs/ardour/port_set.cc
parent830911f6f9451d83a58043b3f9084d3caa164b7b (diff)
changes from 2.X starting in march 2009 through oct 20 2009 (5826 inclusive)
git-svn-id: svn://localhost/ardour2/branches/3.0@6761 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/port_set.cc')
-rw-r--r--libs/ardour/port_set.cc38
1 files changed, 37 insertions, 1 deletions
diff --git a/libs/ardour/port_set.cc b/libs/ardour/port_set.cc
index b96e45662b..7648db00cb 100644
--- a/libs/ardour/port_set.cc
+++ b/libs/ardour/port_set.cc
@@ -16,6 +16,8 @@
675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <glibmm/ustring.h>
+
#include "ardour/port_set.h"
#include "ardour/midi_port.h"
#include "ardour/audio_port.h"
@@ -30,7 +32,41 @@ PortSet::PortSet()
static bool sort_ports_by_name (Port* a, Port* b)
{
- return (a->name() < b->name());
+ Glib::ustring aname (a->name());
+ Glib::ustring bname (b->name());
+
+ Glib::ustring::size_type last_digit_position_a = aname.size();
+ Glib::ustring::const_reverse_iterator r_iterator = aname.rbegin();
+
+ while (r_iterator!= aname.rend() && Glib::Unicode::isdigit(*r_iterator)) {
+ r_iterator++;
+ last_digit_position_a--;
+ }
+
+ Glib::ustring::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