diff --git a/libraries/lib-wave-track/WaveClip.h b/libraries/lib-wave-track/WaveClip.h index 910a0609abeb..f4228ac93377 100644 --- a/libraries/lib-wave-track/WaveClip.h +++ b/libraries/lib-wave-track/WaveClip.h @@ -515,8 +515,8 @@ class WAVE_TRACK_API WaveClip final : * in cutLineStart and cutLineEnd (if specified) if a cut line at this * position could be found. Return false otherwise. */ bool FindCutLine(double cutLinePosition, - double* cutLineStart = NULL, - double *cutLineEnd = NULL) const; + double* cutLineStart = nullptr, + double *cutLineEnd = nullptr) const; /** Expand cut line (that is, re-insert audio, then DELETE audio saved in * cut line). Returns true if a cut line could be found and successfully diff --git a/libraries/lib-wave-track/WaveTrack.cpp b/libraries/lib-wave-track/WaveTrack.cpp index e1f112c519f9..06dc98b7a542 100644 --- a/libraries/lib-wave-track/WaveTrack.cpp +++ b/libraries/lib-wave-track/WaveTrack.cpp @@ -485,6 +485,17 @@ const Envelope& WaveTrack::Interval::GetEnvelope() const return *mpClip->GetEnvelope(); } +bool WaveTrack::Interval::FindCutLine(double cutLinePosition, + double* cutLineStart, double *cutLineEnd) const +{ + return mpClip->FindCutLine(cutLinePosition, cutLineStart, cutLineEnd); +} + +void WaveTrack::Interval::ExpandCutLine(double cutlinePosition) +{ + ForEachClip([=](auto &clip){ clip.ExpandCutLine(cutlinePosition); }); +} + void WaveTrack::Interval::SetEnvelope(const Envelope& envelope) { mpClip->SetEnvelope(std::make_unique(envelope)); @@ -4009,39 +4020,26 @@ void WaveTrack::SplitAt(double t) } // Expand cut line (that is, re-insert audio, then DELETE audio saved in cut line) -// Can't promise strong exception safety for a pair of tracks together +// Can't yet promise strong exception safety for a pair of channels together void WaveTrack::ExpandCutLine(double cutLinePosition, double* cutlineStart, double* cutlineEnd) { assert(IsLeader()); - for (const auto pChannel : TrackList::Channels(this)) { - pChannel->ExpandOneCutLine(cutLinePosition, cutlineStart, cutlineEnd); - // Assign the out parameters at most once - cutlineStart = cutlineEnd = nullptr; - } -} - -/*! @excsafety{Strong} */ -void WaveTrack::ExpandOneCutLine(double cutLinePosition, - double* cutlineStart, double* cutlineEnd) -{ - bool editClipCanMove = GetEditClipsCanMove(); + const bool editClipCanMove = GetEditClipsCanMove(); // Find clip which contains this cut line double start = 0, end = 0; - auto pEnd = mClips.end(); - auto pClip = std::find_if( mClips.begin(), pEnd, - [&](const WaveClipHolder &clip) { - return clip->FindCutLine(cutLinePosition, &start, &end); } ); - if (pClip != pEnd) - { - auto &clip = *pClip; - if (!editClipCanMove) - { + const auto &clips = Intervals(); + const auto pEnd = clips.end(); + const auto pClip = std::find_if(clips.begin(), pEnd, + [&](const auto &clip) { + return clip->FindCutLine(cutLinePosition, &start, &end); }); + if (pClip != pEnd) { + auto clip = *pClip; + if (!editClipCanMove) { // We are not allowed to move the other clips, so see if there // is enough room to expand the cut line for (const auto &clip2: mClips) - { if (clip2->GetPlayStartTime() > clip->GetPlayStartTime() && clip->GetPlayEndTime() + end - start > clip2->GetPlayStartTime()) // Strong-guarantee in case of this path @@ -4051,7 +4049,6 @@ void WaveTrack::ExpandOneCutLine(double cutLinePosition, XO("Warning"), "Error:_Insufficient_space_in_track" }; - } } clip->ExpandCutLine(cutLinePosition); @@ -4065,13 +4062,9 @@ void WaveTrack::ExpandOneCutLine(double cutLinePosition, // Move clips which are to the right of the cut line if (editClipCanMove) - { for (const auto &clip2 : mClips) - { if (clip2->GetPlayStartTime() > clip->GetPlayStartTime()) clip2->ShiftBy(end - start); - } - } } } diff --git a/libraries/lib-wave-track/WaveTrack.h b/libraries/lib-wave-track/WaveTrack.h index b40ae6e6fa6f..546456d4e223 100644 --- a/libraries/lib-wave-track/WaveTrack.h +++ b/libraries/lib-wave-track/WaveTrack.h @@ -1032,6 +1032,15 @@ class WAVE_TRACK_API WaveTrack final const Envelope& GetEnvelope() const; + /** Find cut line at (approximately) this position. Returns true and fills + * in cutLineStart and cutLineEnd (if specified) if a cut line at this + * position could be found. Return false otherwise. */ + bool FindCutLine(double cutLinePosition, + double* cutLineStart = nullptr, + double *cutLineEnd = nullptr) const; + + void ExpandCutLine(double cutlinePosition); + private: void SetEnvelope(const Envelope& envelope);