diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index f2a58eaa78..44667dd2ed 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1339,6 +1339,9 @@ Session::import_route_state (const string& path, std::map cons } XMLNode* xroutes = tree.root()->child ("Routes"); + + std::vector> new_track_order; + if (xroutes) { /* foreach route .. */ for (auto const rxml : xroutes->children()) { @@ -1374,6 +1377,7 @@ Session::import_route_state (const string& path, std::map cons assert (rl.size () < 2); if (rl.size () > 0) { r = rl.front (); + new_track_order.push_back (make_pair (r->id(), pi.order())); } } @@ -1394,6 +1398,7 @@ Session::import_route_state (const string& path, std::map cons assert (rl.size () < 2); if (rl.size () > 0) { r = rl.front (); + new_track_order.push_back (make_pair (r->id(), pi.order())); } } /* set route-group */ @@ -1418,6 +1423,26 @@ Session::import_route_state (const string& path, std::map cons } } + if (!new_track_order.empty ()) { + std::sort (new_track_order.begin (), new_track_order.end (), [=] (auto& a, auto& b) { return a.second < b.second; }); + + /* sort all after the end, and then rely on + * ensure_stripable_sort_order () to pull them back. + * + * Otherwise two routes may temporarily have the same order-id + * and since signals are not blocked, the GUI may sync* callbacks + * may interfere. + */ + uint32_t n_routes = routes.reader()->size (); + uint32_t added = 0; + + for (auto const& [rid, _] : new_track_order) { + std::shared_ptr r = route_by_id (rid); + r->set_presentation_order (n_routes + added++); + } + ensure_stripable_sort_order (); + } + return 0; }