1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-22 23:30:07 +02:00

Sequence::SetSamples, ::SetSilence give strong guarantee

This commit is contained in:
Paul Licameli 2016-11-29 09:42:32 -05:00
parent 73e61592aa
commit 06f6953c91
3 changed files with 18 additions and 11 deletions

View File

@ -634,9 +634,10 @@ void Sequence::Paste(sampleCount s, const Sequence *src)
(newBlock, mNumSamples + addedLen, wxT("Paste branch three"));
}
bool Sequence::SetSilence(sampleCount s0, sampleCount len)
void Sequence::SetSilence(sampleCount s0, sampleCount len)
// STRONG-GUARANTEE
{
return Set(NULL, mSampleFormat, s0, len);
SetSamples(NULL, mSampleFormat, s0, len);
}
void Sequence::InsertSilence(sampleCount s0, sampleCount len)
@ -1169,12 +1170,14 @@ bool Sequence::Get(int b, samplePtr buffer, sampleFormat format,
}
// Pass NULL to set silence
bool Sequence::Set(samplePtr buffer, sampleFormat format,
void Sequence::SetSamples(samplePtr buffer, sampleFormat format,
sampleCount start, sampleCount len)
// STRONG-GUARANTEE
{
if (start < 0 || start >= mNumSamples ||
start+len > mNumSamples)
return false;
start + len > mNumSamples)
//THROW_INCONSISTENCY_EXCEPTION
;
SampleBuffer scratch(mMaxSamples, mSampleFormat);
@ -1185,9 +1188,12 @@ bool Sequence::Set(samplePtr buffer, sampleFormat format,
}
int b = FindBlock(start);
BlockArray newBlock;
std::copy( mBlock.begin(), mBlock.begin() + b, std::back_inserter(newBlock) );
while (len != 0) {
SeqBlock &block = mBlock[b];
newBlock.push_back( mBlock[b] );
SeqBlock &block = newBlock.back();
// start is within block
const auto bstart = ( start - block.start ).as_size_t();
const auto fileLength = block.f->GetLength();
@ -1242,8 +1248,9 @@ bool Sequence::Set(samplePtr buffer, sampleFormat format,
b++;
}
ConsistencyCheck(wxT("Set"));
return true;
std::copy( mBlock.begin() + b, mBlock.end(), std::back_inserter(newBlock) );
CommitChangesIfConsistent( newBlock, mNumSamples, wxT("SetSamples") );
}
namespace {

View File

@ -90,7 +90,7 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
// Note that len is not size_t, because nullptr may be passed for buffer, in
// which case, silence is inserted, possibly a large amount.
bool Set(samplePtr buffer, sampleFormat format,
void SetSamples(samplePtr buffer, sampleFormat format,
sampleCount start, sampleCount len);
// where is input, assumed to be nondecreasing, and its size is len + 1.
@ -128,7 +128,7 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
// loaded from an XML file via DirManager::HandleXMLTag
void AppendBlockFile(const BlockFilePtr &blockFile);
bool SetSilence(sampleCount s0, sampleCount len);
void SetSilence(sampleCount s0, sampleCount len);
void InsertSilence(sampleCount s0, sampleCount len);
const std::shared_ptr<DirManager> &GetDirManager() { return mDirManager; }

View File

@ -413,7 +413,7 @@ void WaveClip::SetSamples(samplePtr buffer, sampleFormat format,
// STRONG-GUARANTEE
{
// use STRONG-GUARANTEE
mSequence->Set(buffer, format, start, len);
mSequence->SetSamples(buffer, format, start, len);
// use NOFAIL-GUARANTEE
MarkChanged();