13
0

libardour: initial implementation of Playlist::remove_gaps()

This is probably a little naive and may need extending to cover cross-track scenarios
This commit is contained in:
Paul Davis 2021-05-28 12:35:30 -06:00
parent cd7c10c902
commit fecce7c333
2 changed files with 46 additions and 3 deletions

View File

@ -163,6 +163,7 @@ public:
void duplicate_ranges (std::list<AudioRange>&, float times);
void nudge_after (samplepos_t start, samplecnt_t distance, bool forwards);
void fade_range (std::list<AudioRange>&);
void remove_gaps (samplepos_t gap_threshold, samplepos_t leave_gap);
boost::shared_ptr<Region> combine (const RegionList&);
void uncombine (boost::shared_ptr<Region>);
@ -405,7 +406,7 @@ protected:
void splice_unlocked (samplepos_t at, samplecnt_t distance, boost::shared_ptr<Region> 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> /*region*/) {}
virtual void region_going_away (boost::weak_ptr<Region> /*region*/) {}

View File

@ -883,6 +883,45 @@ Playlist::remove_region_internal (boost::shared_ptr<Region> 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<Region> other, vector<boost::shared_ptr<Region> >& 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