Compatibility sanity check for inserting clips into a WaveTrack...

... And don't move from the shared pointer argument
This commit is contained in:
Paul Licameli 2020-09-16 02:01:48 -04:00
parent 1a11b81deb
commit d3ab8b7f76
4 changed files with 15 additions and 8 deletions

View File

@ -979,11 +979,16 @@ std::shared_ptr<WaveClip> WaveTrack::RemoveAndReturnClip(WaveClip* clip)
return {};
}
void WaveTrack::AddClip(std::shared_ptr<WaveClip> &&clip)
bool WaveTrack::AddClip(const std::shared_ptr<WaveClip> &clip)
{
if (clip->GetSequence()->GetFactory() != this->mpFactory)
return false;
// Uncomment the following line after we correct the problem of zero-length clips
//if (CanInsertClip(clip))
mClips.push_back(std::move(clip)); // transfer ownership
mClips.push_back(clip); // transfer ownership
return true;
}
/*! @excsafety{Strong} */

View File

@ -480,8 +480,8 @@ private:
// You assume responsibility for its memory!
std::shared_ptr<WaveClip> RemoveAndReturnClip(WaveClip* clip);
// Append a clip to the track
void AddClip(std::shared_ptr<WaveClip> &&clip); // Call using std::move
//! Append a clip to the track; which must have the same block factory as this track; return success
bool AddClip(const std::shared_ptr<WaveClip> &clip);
// Merge two clips, that is append data from clip2 to clip1,
// then remove clip2 from track.

View File

@ -201,12 +201,13 @@ bool EffectReverse::ProcessOneWave(int count, WaveTrack * track, sampleCount sta
// PRL: I don't think that matters, the sequence of storage of clips in the track
// is not elsewhere assumed to be by time
{
for (auto it = revClips.rbegin(), revEnd = revClips.rend(); it != revEnd; ++it)
track->AddClip(std::move(*it));
for (auto it = revClips.rbegin(), revEnd = revClips.rend(); rValue && it != revEnd; ++it)
rValue = track->AddClip(*it);
}
for (auto &clip : otherClips)
track->AddClip(std::move(clip));
if (!(rValue = track->AddClip(clip)))
break;
return rValue;
}

View File

@ -825,7 +825,8 @@ namespace {
WaveClip *const pSrcClip = trackClip.clip;
if (pSrcClip) {
const auto dstTrack = trackClip.dstTrack;
dstTrack->AddClip(std::move(trackClip.holder));
// To do: check and propagate the error! Can't from a dtor
(void) dstTrack->AddClip(trackClip.holder);
trackClip.track = dstTrack;
}
}