diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index 0c119fd251..43975b73e2 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -730,6 +730,7 @@ class LIBARDOUR_API TriggerBox : public Processor int set_state (const XMLNode&, int version); void deep_sources (std::set>&); + void used_regions (std::set>&); void set_from_path (uint32_t slot, std::string const & path); void set_from_selection (uint32_t slot, boost::shared_ptr); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 99adb50162..4c3b8d8785 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -3500,10 +3500,26 @@ Session::cleanup_regions () bool removed = false; const RegionFactory::RegionMap& regions (RegionFactory::regions()); + /* collect Regions used by Triggers */ + std::set> tr; + { + boost::shared_ptr rl = routes.reader(); + for (auto const& r : *rl) { + boost::shared_ptr tb = r->triggerbox (); + if (tb) { + tb->used_regions (tr); + } + } + } + for (RegionFactory::RegionMap::const_iterator i = regions.begin(); i != regions.end();) { uint32_t used = _playlists->region_use_count (i->second); + if (tr.find (i->second) != tr.end()) { + ++used; + } + if (used == 0 && !i->second->automatic ()) { boost::weak_ptr w = i->second; ++i; diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index ba4755f82f..302cfb7cb6 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -3340,6 +3340,8 @@ TriggerBox::trigger_by_id (PBD::ID check) void TriggerBox::deep_sources (std::set >& sources) { + Glib::Threads::RWLock::ReaderLock lm (trigger_lock); + for (uint64_t n = 0; n < all_triggers.size(); ++n) { boost::shared_ptr r (trigger(n)->region ()); if (r) { @@ -3348,6 +3350,20 @@ TriggerBox::deep_sources (std::set >& sources) } } +void +TriggerBox::used_regions (std::set >& regions) +{ + Glib::Threads::RWLock::ReaderLock lm (trigger_lock); + + for (uint64_t n = 0; n < all_triggers.size(); ++n) { + boost::shared_ptr r (trigger(n)->region ()); + if (r) { + regions.insert (r); + } + } +} + + void TriggerBox::enqueue_trigger_state_for_region (boost::shared_ptr region, boost::shared_ptr state) {