From fecce7c33360d5e3dd0e788c587dde412bb20e3f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 28 May 2021 12:35:30 -0600 Subject: [PATCH] libardour: initial implementation of Playlist::remove_gaps() This is probably a little naive and may need extending to cover cross-track scenarios --- libs/ardour/ardour/playlist.h | 3 ++- libs/ardour/playlist.cc | 46 +++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h index 64b3576568..26a8a3523a 100644 --- a/libs/ardour/ardour/playlist.h +++ b/libs/ardour/ardour/playlist.h @@ -163,6 +163,7 @@ public: void duplicate_ranges (std::list&, float times); void nudge_after (samplepos_t start, samplecnt_t distance, bool forwards); void fade_range (std::list&); + void remove_gaps (samplepos_t gap_threshold, samplepos_t leave_gap); boost::shared_ptr combine (const RegionList&); void uncombine (boost::shared_ptr); @@ -405,7 +406,7 @@ protected: void splice_unlocked (samplepos_t at, samplecnt_t distance, boost::shared_ptr exclude, ThawList& thawlist); void ripple_locked (samplepos_t at, samplecnt_t distance, RegionList* exclude); - void ripple_unlocked (samplepos_t at, samplecnt_t distance, RegionList* exclude, ThawList& thawlist); + void ripple_unlocked (samplepos_t at, samplecnt_t distance, RegionList* exclude, ThawList& thawlist, bool notify = true); virtual void remove_dependents (boost::shared_ptr /*region*/) {} virtual void region_going_away (boost::weak_ptr /*region*/) {} diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index 7863b0df68..a6c5988d29 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -883,6 +883,45 @@ Playlist::remove_region_internal (boost::shared_ptr region, ThawList& th return -1; } +void +Playlist::remove_gaps (samplepos_t gap_threshold, samplepos_t leave_gap) +{ + RegionWriteLock rlock (this); + RegionList::iterator i; + RegionList::iterator nxt (regions.end()); + bool closed = false; + + if (regions.size() < 2) { + return; + } + + for (i = regions.begin(); i != regions.end(); ++i) { + + nxt = i; + ++nxt; + + if (nxt == regions.end()) { + break; + } + + const samplepos_t gap = (*nxt)->position() - ((*i)->position() + (*i)->length()); + + if (gap < gap_threshold) { + continue; + } + + const samplepos_t shift = gap - leave_gap; + + ripple_unlocked ((*nxt)->position(), -shift, 0, rlock.thawlist, false); + + closed = true; + } + + if (closed) { + notify_contents_changed (); + } +} + void Playlist::get_equivalent_regions (boost::shared_ptr other, vector >& results) { @@ -1645,7 +1684,7 @@ Playlist::ripple_locked (samplepos_t at, samplecnt_t distance, RegionList* exclu } void -Playlist::ripple_unlocked (samplepos_t at, samplecnt_t distance, RegionList* exclude, ThawList& thawlist) +Playlist::ripple_unlocked (samplepos_t at, samplecnt_t distance, RegionList* exclude, ThawList& thawlist, bool notify) { if (distance == 0) { return; @@ -1677,7 +1716,10 @@ Playlist::ripple_unlocked (samplepos_t at, samplecnt_t distance, RegionList* exc } _rippling = false; - notify_contents_changed (); + + if (notify) { + notify_contents_changed (); + } } void