From 36ed5bbf37c4ab9979fad9c42711dbbb1f84b72f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 21 Sep 2025 17:52:49 +0200 Subject: [PATCH] Fix edge case when region start is after the source' end This fixes an edge case where an audio-region was split near its end using music-time. see also 7ded62c37f0 --- libs/ardour/region.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index d394a1fd0a..e7e5904fdc 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -1574,8 +1574,14 @@ Region::_set_state (const XMLNode& node, int version, PropertyChange& what_chang non-silently just force the region length to the correct value. */ - error << "Correcting length of region " << _name << " to match it's (first) source's length of " << _sources.front()->length().str() << endmsg; - _length = timecnt_t (start().distance (_sources.front()->length()), _length.val().position()); + error << "Correcting region " << _name << " with start offset " << start() << " length " << _length << " to match it's (first) source's length of " << _sources.front()->length().str() << endmsg; + if (start() >= _sources.front()->length()) { + _length = timecnt_t (0, _length.val().position()); + error << "Truncated region " << _name << " length to " << _length << endmsg; + } else { + _length = timecnt_t (start().distance (_sources.front()->length()), _length.val().position()); + error << "Corrected region " << _name << " length to " << _length << endmsg; + } } }