1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-24 23:33:50 +02:00

Changes in WaveClip construction...

... Eliminate CreateFromCopy, add new one-step constructor instead.
It was wasteful to create a copy only to re-create the Sequence at once.

Sequence::Copy is a factory returning a unique_ptr.

Some error checks are removed, but there will be exceptions instead later.
This commit is contained in:
Paul Licameli
2016-11-26 11:47:45 -05:00
parent 25619fb46e
commit 934a505e1a
5 changed files with 70 additions and 88 deletions

View File

@@ -385,12 +385,10 @@ bool Sequence::GetRMS(sampleCount start, sampleCount len,
return true;
}
bool Sequence::Copy(sampleCount s0, sampleCount s1, std::unique_ptr<Sequence> &dest) const
std::unique_ptr<Sequence> Sequence::Copy(sampleCount s0, sampleCount s1) const
{
dest.reset();
if (s0 >= s1 || s0 >= mNumSamples || s1 < 0)
return false;
return {};
int numBlocks = mBlock.size();
@@ -402,7 +400,7 @@ bool Sequence::Copy(sampleCount s0, sampleCount s1, std::unique_ptr<Sequence> &d
wxUnusedVar(numBlocks);
wxASSERT(b0 <= b1);
dest = std::make_unique<Sequence>(mDirManager, mSampleFormat);
auto dest = std::make_unique<Sequence>(mDirManager, mSampleFormat);
dest->mBlock.reserve(b1 - b0 + 1);
SampleBuffer buffer(mMaxSamples, mSampleFormat);
@@ -445,7 +443,10 @@ bool Sequence::Copy(sampleCount s0, sampleCount s1, std::unique_ptr<Sequence> &d
dest->AppendBlock(block); // Increase ref count or duplicate file
}
return ConsistencyCheck(wxT("Sequence::Copy()"));
if (! ConsistencyCheck(wxT("Sequence::Copy()")))
return {};
return dest;
}
namespace {