summaryrefslogtreecommitdiff
path: root/libs/ardour/audioregion.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2012-05-10 12:14:26 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2012-05-10 12:14:26 +0000
commitda7215e1ad6ebcf99cf5874cf676c460dcbb7ee7 (patch)
tree1baf1513a7040706cebf8acd80a7d8dace35d0ff /libs/ardour/audioregion.cc
parentbed955b40935cf7765829e260b70258b79803890 (diff)
if an xfade involves only 2 regions, clamp its length to the overlap between them
git-svn-id: svn://localhost/ardour2/branches/3.0@12238 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/audioregion.cc')
-rw-r--r--libs/ardour/audioregion.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc
index e217783760..4ba383b37e 100644
--- a/libs/ardour/audioregion.cc
+++ b/libs/ardour/audioregion.cc
@@ -1801,6 +1801,59 @@ AudioRegion::set_fade_out_is_xfade (bool yn)
_fade_out_is_xfade = yn;
}
+framecnt_t
+AudioRegion::verify_xfade_bounds (framecnt_t len, bool start)
+{
+ boost::shared_ptr<Playlist> pl (playlist());
+
+ if (!pl) {
+ /* not currently in a playlist - xfade length is unbounded
+ (and irrelevant)
+ */
+ return len;
+ }
+
+ boost::shared_ptr<RegionList> rl;
+ framecnt_t maxlen;
+
+ if (start) {
+ rl = pl->regions_at (position());
+ } else {
+ rl = pl->regions_at (last_frame());
+ }
+
+ RegionList::iterator i;
+ boost::shared_ptr<Region> other;
+ uint32_t n = 0;
+
+ /* count and find the other region in a single pass through the list */
+
+ for (i = rl->begin(); i != rl->end(); ++i) {
+ if ((*i).get() != this) {
+ other = *i;
+ }
+ ++n;
+ }
+
+ if (n != 2) {
+ /* zero or multiple regions stacked here - don't care about xfades */
+ return len;
+ }
+
+ /* we overlap a single region. clamp the length of an xfade to
+ the duration of the overlap.
+ */
+
+ if (start) {
+ maxlen = other->last_frame() - position();
+ } else {
+ maxlen = last_frame() - other->position();
+ }
+
+ return min (maxlen, len);
+
+}
+
extern "C" {
int region_read_peaks_from_c (void *arg, uint32_t npeaks, uint32_t start, uint32_t cnt, intptr_t data, uint32_t n_chan, double samples_per_unit)