diff --git a/libs/ardour/ardour/route_group.h b/libs/ardour/ardour/route_group.h index be4369039b..7538e47e66 100644 --- a/libs/ardour/ardour/route_group.h +++ b/libs/ardour/ardour/route_group.h @@ -115,6 +115,7 @@ class LIBARDOUR_API RouteGroup : public SessionObject, public std::enable_shared int add (std::shared_ptr); int remove (std::shared_ptr); + void clear (); template void foreach_route (Function f) { for (auto & r : *routes) {f (r); } } @@ -126,11 +127,6 @@ class LIBARDOUR_API RouteGroup : public SessionObject, public std::enable_shared void audio_track_group (std::set >& at_set); - void clear () { - routes->clear (); - changed(); - } - bool has_subgroup() const; bool can_subgroup (bool, Placement) const; void make_subgroup (bool, Placement); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index b62c39c8e1..7b89352ceb 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1946,6 +1946,7 @@ private: int load_route_groups (const XMLNode&, int); RouteGroupList _route_groups; + void route_group_emptied (std::shared_ptr); /* routes stuff */ diff --git a/libs/ardour/route_group.cc b/libs/ardour/route_group.cc index 24b203c480..d8a4a9b2e7 100644 --- a/libs/ardour/route_group.cc +++ b/libs/ardour/route_group.cc @@ -244,6 +244,18 @@ RouteGroup::unset_subgroup_bus () _subgroup_bus.reset (); } +void +RouteGroup::clear () +{ + RouteList copy (*routes); + + for (auto & r : copy) { + remove (r); + } + + changed (); +} + int RouteGroup::remove (std::shared_ptr r) { diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 71602ab3b5..7cba822c41 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -6829,8 +6829,10 @@ Session::route_removed_from_route_group (std::shared_ptr rg, std::we update_route_record_state (); RouteRemovedFromRouteGroup (rg, r); /* EMIT SIGNAL */ + std::shared_ptr rr (r.lock()); + if (!rg->has_control_master () && !rg->has_subgroup () && rg->empty()) { - remove_route_group (rg); + route_group_emptied (rg); } } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 44667dd2ed..9e228b3684 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -3608,6 +3608,18 @@ Session::add_route_group (std::shared_ptr g) void Session::remove_route_group (std::shared_ptr rg) +{ + if (!rg) { + return; + } + + rg->clear (); + + /* by the magic of reference counting, rg will now be deleted */ +} + +void +Session::route_group_emptied (std::shared_ptr rg) { list>::iterator i;