Work around cleanup unused regions removing trigger-regions

This workaround bypasses RegionMap and SessionPlaylist APIs
(region_use_count, destroy_region) which are not directly
applicable to Triggerboxes. There are likely various edge
cases until TriggerBoxes integrate with Session Playlist.

e.g. whole file regions generated for regions/source used by
triggerboxes are cleaned up.
This commit is contained in:
Robin Gareus 2022-08-01 20:48:02 +02:00
parent bd6df4a40d
commit e04311b647
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 33 additions and 0 deletions

View File

@ -730,6 +730,7 @@ class LIBARDOUR_API TriggerBox : public Processor
int set_state (const XMLNode&, int version);
void deep_sources (std::set<boost::shared_ptr<Source>>&);
void used_regions (std::set<boost::shared_ptr<Region>>&);
void set_from_path (uint32_t slot, std::string const & path);
void set_from_selection (uint32_t slot, boost::shared_ptr<Region>);

View File

@ -3500,10 +3500,26 @@ Session::cleanup_regions ()
bool removed = false;
const RegionFactory::RegionMap& regions (RegionFactory::regions());
/* collect Regions used by Triggers */
std::set<boost::shared_ptr<Region>> tr;
{
boost::shared_ptr<RouteList> rl = routes.reader();
for (auto const& r : *rl) {
boost::shared_ptr<TriggerBox> 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<Region> w = i->second;
++i;

View File

@ -3340,6 +3340,8 @@ TriggerBox::trigger_by_id (PBD::ID check)
void
TriggerBox::deep_sources (std::set<boost::shared_ptr<Source> >& sources)
{
Glib::Threads::RWLock::ReaderLock lm (trigger_lock);
for (uint64_t n = 0; n < all_triggers.size(); ++n) {
boost::shared_ptr<Region> r (trigger(n)->region ());
if (r) {
@ -3348,6 +3350,20 @@ TriggerBox::deep_sources (std::set<boost::shared_ptr<Source> >& sources)
}
}
void
TriggerBox::used_regions (std::set<boost::shared_ptr<Region> >& regions)
{
Glib::Threads::RWLock::ReaderLock lm (trigger_lock);
for (uint64_t n = 0; n < all_triggers.size(); ++n) {
boost::shared_ptr<Region> r (trigger(n)->region ());
if (r) {
regions.insert (r);
}
}
}
void
TriggerBox::enqueue_trigger_state_for_region (boost::shared_ptr<Region> region, boost::shared_ptr<Trigger::UIState> state)
{