-struct RouteSorter {
- /** @return true to run r1 before r2, otherwise false */
- bool sort_by_rec_enabled (const boost::shared_ptr<Route>& r1, const boost::shared_ptr<Route>& r2) {
- if (r1->record_enabled()) {
- if (r2->record_enabled()) {
- /* both rec-enabled, just use signal order */
- return r1->order_key(N_("signal")) < r2->order_key(N_("signal"));
- } else {
- /* r1 rec-enabled, r2 not rec-enabled, run r2 early */
- return false;
- }
- } else {
- if (r2->record_enabled()) {
- /* r2 rec-enabled, r1 not rec-enabled, run r1 early */
- return true;
- } else {
- /* neither rec-enabled, use signal order */
- return r1->order_key(N_("signal")) < r2->order_key(N_("signal"));
- }
- }
- }
-
- bool operator() (boost::shared_ptr<Route> r1, boost::shared_ptr<Route> r2) {
- if (r2->feeds (r1)) {
- /* r1 fed by r2; run r2 early */
- return false;
- } else if (r1->feeds (r2)) {
- /* r2 fed by r1; run r1 early */
- return true;
- } else {
- if (r1->not_fed ()) {
- if (r2->not_fed ()) {
- /* no ardour-based connections inbound to either route. */
- return sort_by_rec_enabled (r1, r2);
- } else {
- /* r2 has connections, r1 does not; run r1 early */
- return true;
- }
- } else {
- if (r2->not_fed()) {
- /* r1 has connections, r2 does not; run r2 early */
- return false;
- } else {
- /* both r1 and r2 have connections, but not to each other. just use signal order */
- return r1->order_key(N_("signal")) < r2->order_key(N_("signal"));
- }
- }
- }
- }
-};