simplify PresentationInfo concept of order so that it is always global
[ardour.git] / libs / ardour / route_graph.cc
index 910141a44029c901343c43a8720d5f5d45d839d7..111033bf2319006eda0a3d40b0fd115ddde569e0 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "ardour/route.h"
 #include "ardour/route_graph.h"
+#include "ardour/track.h"
 
 #include "i18n.h"
 
@@ -195,21 +196,41 @@ struct RouteRecEnabledComparator
 {
        bool operator () (GraphVertex r1, GraphVertex r2) const
        {
-               if (r1->record_enabled()) {
-                       if (r2->record_enabled()) {
+               boost::shared_ptr<Track> t1 (boost::dynamic_pointer_cast<Track>(r1));
+               boost::shared_ptr<Track> t2 (boost::dynamic_pointer_cast<Track>(r2));
+               PresentationInfo::order_t r1o = r1->presentation_info().order();
+               PresentationInfo::order_t r2o = r2->presentation_info().order();
+
+               if (!t1) {
+                       if (!t2) {
+                               /* makes no difference which is first, use presentation order */
+                               return r1o < r2o;
+                       } else {
+                               /* r1 is not a track, r2 is, run it early */
+                               return false;
+                       }
+               }
+
+               if (!t2) {
+                       /* we already tested !t1, so just use presentation order */
+                       return r1o < r2o;
+               }
+
+               if (t1->rec_enable_control()->get_value()) {
+                       if (t2->rec_enable_control()->get_value()) {
                                /* both rec-enabled, just use signal order */
-                               return r1->order_key () < r2->order_key ();
+                               return r1o < r2o;
                        } else {
-                               /* r1 rec-enabled, r2 not rec-enabled, run r2 early */
+                               /* t1 rec-enabled, t2 not rec-enabled, run t2 early */
                                return false;
                        }
                } else {
-                       if (r2->record_enabled()) {
-                               /* r2 rec-enabled, r1 not rec-enabled, run r1 early */
+                       if (t2->rec_enable_control()->get_value()) {
+                               /* t2 rec-enabled, t1 not rec-enabled, run t1 early */
                                return true;
                        } else {
-                               /* neither rec-enabled, use signal order */
-                               return r1->order_key () < r2->order_key ();
+                               /* neither rec-enabled, use presentation order */
+                               return r1o < r2o;
                        }
                }
        }