diff --git a/src/Benchmark.cpp b/src/Benchmark.cpp index 8e2a3e553..e333b046e 100644 --- a/src/Benchmark.cpp +++ b/src/Benchmark.cpp @@ -429,8 +429,11 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event)) if (mEditDetail) Printf(wxT("Cut: %d - %d \n"), x0 * chunkSize, (x0 + xlen) * chunkSize); - auto tmp = t->Cut(double (x0 * chunkSize), double ((x0 + xlen) * chunkSize)); - if (!tmp) { + Track::Holder tmp; + try { + tmp = t->Cut(double (x0 * chunkSize), double ((x0 + xlen) * chunkSize)); + } + catch (const AudacityException&) { Printf(wxT("Trial %d\n"), z); Printf(wxT("Cut (%d, %d) failed.\n"), (x0 * chunkSize), (x0 + xlen) * chunkSize); diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index e3cfd720f..a01cfdd2d 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -2339,10 +2339,10 @@ bool LabelTrack::Save(wxTextFile * out, bool overwrite) Track::Holder LabelTrack::Cut(double t0, double t1) { auto tmp = Copy(t0, t1); - if (!tmp) - return{}; + if (!Clear(t0, t1)) - return{}; + //THROW_INCONSISTENCY_EXCEPTION + ; return tmp; } @@ -2353,8 +2353,7 @@ Track::Holder LabelTrack::SplitCut(double t0, double t1) // SplitCut() == Copy() + SplitDelete() Track::Holder tmp = Copy(t0, t1); - if (!tmp) - return {}; + if (!SplitDelete(t0, t1)) return {}; diff --git a/src/Menus.cpp b/src/Menus.cpp index 4f9a345a3..9d7a4178d 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -4177,8 +4177,7 @@ void AudacityProject::OnCut() dest = n->Copy(mViewInfo.selectedRegion.t0(), mViewInfo.selectedRegion.t1()); - if (dest) - FinishCopy(n, std::move(dest), newClipboard); + FinishCopy(n, std::move(dest), newClipboard); } n = iter.Next(); } @@ -4309,8 +4308,7 @@ void AudacityProject::OnCopy() if (n->GetSelected()) { auto dest = n->Copy(mViewInfo.selectedRegion.t0(), mViewInfo.selectedRegion.t1()); - if (dest) - FinishCopy(n, std::move(dest), newClipboard); + FinishCopy(n, std::move(dest), newClipboard); } n = iter.Next(); } @@ -4914,11 +4912,9 @@ void AudacityProject::OnDuplicate() // Make copies not for clipboard but for direct addition to the project auto dest = n->Copy(mViewInfo.selectedRegion.t0(), mViewInfo.selectedRegion.t1(), false); - if (dest) { - dest->Init(*n); - dest->SetOffset(wxMax(mViewInfo.selectedRegion.t0(), n->GetOffset())); - mTracks->Add(std::move(dest)); - } + dest->Init(*n); + dest->SetOffset(wxMax(mViewInfo.selectedRegion.t0(), n->GetOffset())); + mTracks->Add(std::move(dest)); } if (n == l) { @@ -5129,22 +5125,19 @@ void AudacityProject::OnSplit() double sel0 = mViewInfo.selectedRegion.t0(); double sel1 = mViewInfo.selectedRegion.t1(); - dest = NULL; - n->Copy(sel0, sel1, &dest); - if (dest) { - dest->Init(*n); - dest->SetOffset(wxMax(sel0, n->GetOffset())); + dest = n->Copy(sel0, sel1); + dest->Init(*n); + dest->SetOffset(wxMax(sel0, n->GetOffset())); - if (sel1 >= n->GetEndTime()) - n->Clear(sel0, sel1); - else if (sel0 <= n->GetOffset()) { - n->Clear(sel0, sel1); - n->SetOffset(sel1); - } else - n->Silence(sel0, sel1); + if (sel1 >= n->GetEndTime()) + n->Clear(sel0, sel1); + else if (sel0 <= n->GetOffset()) { + n->Clear(sel0, sel1); + n->SetOffset(sel1); + } else + n->Silence(sel0, sel1); - newTracks.Add(dest); - } + newTracks.Add(dest); } n = iter.Next(); } @@ -5190,10 +5183,8 @@ void AudacityProject::OnSplitNew() mViewInfo.selectedRegion.t1()); } #endif - if (dest) { - dest->SetOffset(wxMax(newt0, offset)); - FinishCopy(n, std::move(dest), *mTracks); - } + dest->SetOffset(wxMax(newt0, offset)); + FinishCopy(n, std::move(dest), *mTracks); } if (n == l) { diff --git a/src/NoteTrack.cpp b/src/NoteTrack.cpp index 2b78d28da..637a614be 100644 --- a/src/NoteTrack.cpp +++ b/src/NoteTrack.cpp @@ -435,7 +435,8 @@ int NoteTrack::GetVisibleChannels() Track::Holder NoteTrack::Cut(double t0, double t1) { if (t1 <= t0) - return{}; + //THROW_INCONSISTENCY_EXCEPTION + ; double len = t1-t0; auto newTrack = std::make_unique(mDirManager); @@ -457,7 +458,8 @@ Track::Holder NoteTrack::Cut(double t0, double t1) Track::Holder NoteTrack::Copy(double t0, double t1, bool) const { if (t1 <= t0) - return{}; + //THROW_INCONSISTENCY_EXCEPTION + ; double len = t1-t0; auto newTrack = std::make_unique(mDirManager); diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 34ced8a4b..5058573ed 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -438,7 +438,8 @@ std::unique_ptr Sequence::Copy(sampleCount s0, sampleCount s1) const } if (! ConsistencyCheck(wxT("Sequence::Copy()"))) - return {}; + //THROW_INCONSISTENCY_EXCEPTION + ; return dest; } diff --git a/src/Track.cpp b/src/Track.cpp index 2978489c0..7b0e5512a 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -309,7 +309,6 @@ bool Track::SyncLockAdjust(double oldT1, double newT1) return true; auto tmp = Cut(oldT1, GetEndTime()); - if (!tmp) return false; bool ret = Paste(newT1, tmp.get()); wxASSERT(ret); // TODO: handle this. diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index 76463ca6f..040c14ca8 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -532,15 +532,14 @@ bool WaveTrack::IsEmpty(double t0, double t1) const Track::Holder WaveTrack::Cut(double t0, double t1) { if (t1 < t0) - return{}; + // THROW_INCONSISTENCY_EXCEPTION + ; auto tmp = Copy(t0, t1); - if (!tmp) - return{}; - if (!Clear(t0, t1)) - return{}; + // THROW_INCONSISTENCY_EXCEPTION + ; return tmp; } @@ -548,14 +547,15 @@ Track::Holder WaveTrack::Cut(double t0, double t1) Track::Holder WaveTrack::SplitCut(double t0, double t1) { if (t1 < t0) - return{}; + //THROW_INCONSISTENCY_EXCEPTION + ; // SplitCut is the same as 'Copy', then 'SplitDelete' auto tmp = Copy(t0, t1); - if (!tmp) - return{}; + if (!SplitDelete(t0, t1)) - return{}; + //THROW_INCONSISTENCY_EXCEPTION + ; return tmp; } @@ -564,14 +564,15 @@ Track::Holder WaveTrack::SplitCut(double t0, double t1) Track::Holder WaveTrack::CutAndAddCutLine(double t0, double t1) { if (t1 < t0) - return {}; + //THROW_INCONSISTENCY_EXCEPTION + ; // Cut is the same as 'Copy', then 'Delete' auto tmp = Copy(t0, t1); - if (!tmp) - return {}; + if (!ClearAndAddCutLine(t0, t1)) - return {}; + //THROW_INCONSISTENCY_EXCEPTION + ; return tmp; } @@ -636,7 +637,8 @@ bool WaveTrack::Trim (double t0, double t1) Track::Holder WaveTrack::Copy(double t0, double t1, bool forClipboard) const { if (t1 <= t0) - return{}; + //THROW_INCONSISTENCY_EXCEPTION + ; WaveTrack *newTrack; Track::Holder result @@ -1166,8 +1168,6 @@ bool WaveTrack::SyncLockAdjust(double oldT1, double newT1) gPrefs->Read(wxT("/GUI/EditClipCanMove"), &clipsCanMove); if (clipsCanMove) { auto tmp = Cut (oldT1, GetEndTime() + 1.0/GetRate()); - if (!tmp) - return false; ret = Paste(newT1, tmp.get()); wxASSERT(ret); diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index 954f733fb..6adc84ebf 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -1173,20 +1173,17 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t, //remove the old audio and get the NEW t->Clear(clipStartEndTimes[i].first,clipStartEndTimes[i].second); auto toClipOutput = output->Copy(clipStartEndTimes[i].first-startT+offsetT0,clipStartEndTimes[i].second-startT+offsetT0); - if(toClipOutput) - { - //put the processed audio in - bool bResult = t->Paste(clipStartEndTimes[i].first, toClipOutput.get()); - wxASSERT(bResult); // TO DO: Actually handle this. - wxUnusedVar(bResult); - //if the clip was only partially selected, the Paste will have created a split line. Join is needed to take care of this - //This is not true when the selection is fully contained within one clip (second half of conditional) - if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first || - clipRealStartEndTimes[i].second != clipStartEndTimes[i].second) && - !(clipRealStartEndTimes[i].first <= startT && - clipRealStartEndTimes[i].second >= startT+lenT) ) - t->Join(clipRealStartEndTimes[i].first,clipRealStartEndTimes[i].second); - } + //put the processed audio in + bool bResult = t->Paste(clipStartEndTimes[i].first, toClipOutput.get()); + wxASSERT(bResult); // TO DO: Actually handle this. + wxUnusedVar(bResult); + //if the clip was only partially selected, the Paste will have created a split line. Join is needed to take care of this + //This is not true when the selection is fully contained within one clip (second half of conditional) + if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first || + clipRealStartEndTimes[i].second != clipStartEndTimes[i].second) && + !(clipRealStartEndTimes[i].first <= startT && + clipRealStartEndTimes[i].second >= startT+lenT) ) + t->Join(clipRealStartEndTimes[i].first,clipRealStartEndTimes[i].second); } } diff --git a/src/effects/Equalization48x.cpp b/src/effects/Equalization48x.cpp index 0a6c2170c..6e5ced834 100644 --- a/src/effects/Equalization48x.cpp +++ b/src/effects/Equalization48x.cpp @@ -558,19 +558,16 @@ bool EffectEqualization48x::ProcessTail(WaveTrack * t, WaveTrack * output, sampl t->Clear(clipStartEndTimes[i].first,clipStartEndTimes[i].second); // output->Copy(clipStartEndTimes[i].first-startT+offsetT0,clipStartEndTimes[i].second-startT+offsetT0, &toClipOutput); auto toClipOutput = output->Copy(clipStartEndTimes[i].first-startT, clipStartEndTimes[i].second-startT); - if(toClipOutput) - { - //put the processed audio in - bool bResult = t->Paste(clipStartEndTimes[i].first, toClipOutput.get()); - wxASSERT(bResult); // TO DO: Actually handle this. - //if the clip was only partially selected, the Paste will have created a split line. Join is needed to take care of this - //This is not true when the selection is fully contained within one clip (second half of conditional) - if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first || - clipRealStartEndTimes[i].second != clipStartEndTimes[i].second) && - !(clipRealStartEndTimes[i].first <= startT && - clipRealStartEndTimes[i].second >= startT+lenT) ) - t->Join(clipRealStartEndTimes[i].first,clipRealStartEndTimes[i].second); - } + //put the processed audio in + bool bResult = t->Paste(clipStartEndTimes[i].first, toClipOutput.get()); + wxASSERT(bResult); // TO DO: Actually handle this. + //if the clip was only partially selected, the Paste will have created a split line. Join is needed to take care of this + //This is not true when the selection is fully contained within one clip (second half of conditional) + if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first || + clipRealStartEndTimes[i].second != clipStartEndTimes[i].second) && + !(clipRealStartEndTimes[i].first <= startT && + clipRealStartEndTimes[i].second >= startT+lenT) ) + t->Join(clipRealStartEndTimes[i].first,clipRealStartEndTimes[i].second); } return true; }