mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-17 17:17:40 +02:00
Factory methods will return non-NULL or throw
This commit is contained in:
parent
f1b354b141
commit
6b84dc1c1d
@ -429,8 +429,11 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
|
|||||||
if (mEditDetail)
|
if (mEditDetail)
|
||||||
Printf(wxT("Cut: %d - %d \n"), x0 * chunkSize, (x0 + xlen) * chunkSize);
|
Printf(wxT("Cut: %d - %d \n"), x0 * chunkSize, (x0 + xlen) * chunkSize);
|
||||||
|
|
||||||
auto tmp = t->Cut(double (x0 * chunkSize), double ((x0 + xlen) * chunkSize));
|
Track::Holder tmp;
|
||||||
if (!tmp) {
|
try {
|
||||||
|
tmp = t->Cut(double (x0 * chunkSize), double ((x0 + xlen) * chunkSize));
|
||||||
|
}
|
||||||
|
catch (const AudacityException&) {
|
||||||
Printf(wxT("Trial %d\n"), z);
|
Printf(wxT("Trial %d\n"), z);
|
||||||
Printf(wxT("Cut (%d, %d) failed.\n"), (x0 * chunkSize),
|
Printf(wxT("Cut (%d, %d) failed.\n"), (x0 * chunkSize),
|
||||||
(x0 + xlen) * chunkSize);
|
(x0 + xlen) * chunkSize);
|
||||||
|
@ -2339,10 +2339,10 @@ bool LabelTrack::Save(wxTextFile * out, bool overwrite)
|
|||||||
Track::Holder LabelTrack::Cut(double t0, double t1)
|
Track::Holder LabelTrack::Cut(double t0, double t1)
|
||||||
{
|
{
|
||||||
auto tmp = Copy(t0, t1);
|
auto tmp = Copy(t0, t1);
|
||||||
if (!tmp)
|
|
||||||
return{};
|
|
||||||
if (!Clear(t0, t1))
|
if (!Clear(t0, t1))
|
||||||
return{};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
@ -2353,8 +2353,7 @@ Track::Holder LabelTrack::SplitCut(double t0, double t1)
|
|||||||
// SplitCut() == Copy() + SplitDelete()
|
// SplitCut() == Copy() + SplitDelete()
|
||||||
|
|
||||||
Track::Holder tmp = Copy(t0, t1);
|
Track::Holder tmp = Copy(t0, t1);
|
||||||
if (!tmp)
|
|
||||||
return {};
|
|
||||||
if (!SplitDelete(t0, t1))
|
if (!SplitDelete(t0, t1))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -4177,8 +4177,7 @@ void AudacityProject::OnCut()
|
|||||||
dest = n->Copy(mViewInfo.selectedRegion.t0(),
|
dest = n->Copy(mViewInfo.selectedRegion.t0(),
|
||||||
mViewInfo.selectedRegion.t1());
|
mViewInfo.selectedRegion.t1());
|
||||||
|
|
||||||
if (dest)
|
FinishCopy(n, std::move(dest), newClipboard);
|
||||||
FinishCopy(n, std::move(dest), newClipboard);
|
|
||||||
}
|
}
|
||||||
n = iter.Next();
|
n = iter.Next();
|
||||||
}
|
}
|
||||||
@ -4309,8 +4308,7 @@ void AudacityProject::OnCopy()
|
|||||||
if (n->GetSelected()) {
|
if (n->GetSelected()) {
|
||||||
auto dest = n->Copy(mViewInfo.selectedRegion.t0(),
|
auto dest = n->Copy(mViewInfo.selectedRegion.t0(),
|
||||||
mViewInfo.selectedRegion.t1());
|
mViewInfo.selectedRegion.t1());
|
||||||
if (dest)
|
FinishCopy(n, std::move(dest), newClipboard);
|
||||||
FinishCopy(n, std::move(dest), newClipboard);
|
|
||||||
}
|
}
|
||||||
n = iter.Next();
|
n = iter.Next();
|
||||||
}
|
}
|
||||||
@ -4914,11 +4912,9 @@ void AudacityProject::OnDuplicate()
|
|||||||
// Make copies not for clipboard but for direct addition to the project
|
// Make copies not for clipboard but for direct addition to the project
|
||||||
auto dest = n->Copy(mViewInfo.selectedRegion.t0(),
|
auto dest = n->Copy(mViewInfo.selectedRegion.t0(),
|
||||||
mViewInfo.selectedRegion.t1(), false);
|
mViewInfo.selectedRegion.t1(), false);
|
||||||
if (dest) {
|
dest->Init(*n);
|
||||||
dest->Init(*n);
|
dest->SetOffset(wxMax(mViewInfo.selectedRegion.t0(), n->GetOffset()));
|
||||||
dest->SetOffset(wxMax(mViewInfo.selectedRegion.t0(), n->GetOffset()));
|
mTracks->Add(std::move(dest));
|
||||||
mTracks->Add(std::move(dest));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == l) {
|
if (n == l) {
|
||||||
@ -5129,22 +5125,19 @@ void AudacityProject::OnSplit()
|
|||||||
double sel0 = mViewInfo.selectedRegion.t0();
|
double sel0 = mViewInfo.selectedRegion.t0();
|
||||||
double sel1 = mViewInfo.selectedRegion.t1();
|
double sel1 = mViewInfo.selectedRegion.t1();
|
||||||
|
|
||||||
dest = NULL;
|
dest = n->Copy(sel0, sel1);
|
||||||
n->Copy(sel0, sel1, &dest);
|
dest->Init(*n);
|
||||||
if (dest) {
|
dest->SetOffset(wxMax(sel0, n->GetOffset()));
|
||||||
dest->Init(*n);
|
|
||||||
dest->SetOffset(wxMax(sel0, n->GetOffset()));
|
|
||||||
|
|
||||||
if (sel1 >= n->GetEndTime())
|
if (sel1 >= n->GetEndTime())
|
||||||
n->Clear(sel0, sel1);
|
n->Clear(sel0, sel1);
|
||||||
else if (sel0 <= n->GetOffset()) {
|
else if (sel0 <= n->GetOffset()) {
|
||||||
n->Clear(sel0, sel1);
|
n->Clear(sel0, sel1);
|
||||||
n->SetOffset(sel1);
|
n->SetOffset(sel1);
|
||||||
} else
|
} else
|
||||||
n->Silence(sel0, sel1);
|
n->Silence(sel0, sel1);
|
||||||
|
|
||||||
newTracks.Add(dest);
|
newTracks.Add(dest);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
n = iter.Next();
|
n = iter.Next();
|
||||||
}
|
}
|
||||||
@ -5190,10 +5183,8 @@ void AudacityProject::OnSplitNew()
|
|||||||
mViewInfo.selectedRegion.t1());
|
mViewInfo.selectedRegion.t1());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (dest) {
|
dest->SetOffset(wxMax(newt0, offset));
|
||||||
dest->SetOffset(wxMax(newt0, offset));
|
FinishCopy(n, std::move(dest), *mTracks);
|
||||||
FinishCopy(n, std::move(dest), *mTracks);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == l) {
|
if (n == l) {
|
||||||
|
@ -435,7 +435,8 @@ int NoteTrack::GetVisibleChannels()
|
|||||||
Track::Holder NoteTrack::Cut(double t0, double t1)
|
Track::Holder NoteTrack::Cut(double t0, double t1)
|
||||||
{
|
{
|
||||||
if (t1 <= t0)
|
if (t1 <= t0)
|
||||||
return{};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
double len = t1-t0;
|
double len = t1-t0;
|
||||||
|
|
||||||
auto newTrack = std::make_unique<NoteTrack>(mDirManager);
|
auto newTrack = std::make_unique<NoteTrack>(mDirManager);
|
||||||
@ -457,7 +458,8 @@ Track::Holder NoteTrack::Cut(double t0, double t1)
|
|||||||
Track::Holder NoteTrack::Copy(double t0, double t1, bool) const
|
Track::Holder NoteTrack::Copy(double t0, double t1, bool) const
|
||||||
{
|
{
|
||||||
if (t1 <= t0)
|
if (t1 <= t0)
|
||||||
return{};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
double len = t1-t0;
|
double len = t1-t0;
|
||||||
|
|
||||||
auto newTrack = std::make_unique<NoteTrack>(mDirManager);
|
auto newTrack = std::make_unique<NoteTrack>(mDirManager);
|
||||||
|
@ -438,7 +438,8 @@ std::unique_ptr<Sequence> Sequence::Copy(sampleCount s0, sampleCount s1) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! ConsistencyCheck(wxT("Sequence::Copy()")))
|
if (! ConsistencyCheck(wxT("Sequence::Copy()")))
|
||||||
return {};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
@ -309,7 +309,6 @@ bool Track::SyncLockAdjust(double oldT1, double newT1)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
auto tmp = Cut(oldT1, GetEndTime());
|
auto tmp = Cut(oldT1, GetEndTime());
|
||||||
if (!tmp) return false;
|
|
||||||
|
|
||||||
bool ret = Paste(newT1, tmp.get());
|
bool ret = Paste(newT1, tmp.get());
|
||||||
wxASSERT(ret); // TODO: handle this.
|
wxASSERT(ret); // TODO: handle this.
|
||||||
|
@ -532,15 +532,14 @@ bool WaveTrack::IsEmpty(double t0, double t1) const
|
|||||||
Track::Holder WaveTrack::Cut(double t0, double t1)
|
Track::Holder WaveTrack::Cut(double t0, double t1)
|
||||||
{
|
{
|
||||||
if (t1 < t0)
|
if (t1 < t0)
|
||||||
return{};
|
// THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
auto tmp = Copy(t0, t1);
|
auto tmp = Copy(t0, t1);
|
||||||
|
|
||||||
if (!tmp)
|
|
||||||
return{};
|
|
||||||
|
|
||||||
if (!Clear(t0, t1))
|
if (!Clear(t0, t1))
|
||||||
return{};
|
// THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
@ -548,14 +547,15 @@ Track::Holder WaveTrack::Cut(double t0, double t1)
|
|||||||
Track::Holder WaveTrack::SplitCut(double t0, double t1)
|
Track::Holder WaveTrack::SplitCut(double t0, double t1)
|
||||||
{
|
{
|
||||||
if (t1 < t0)
|
if (t1 < t0)
|
||||||
return{};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
// SplitCut is the same as 'Copy', then 'SplitDelete'
|
// SplitCut is the same as 'Copy', then 'SplitDelete'
|
||||||
auto tmp = Copy(t0, t1);
|
auto tmp = Copy(t0, t1);
|
||||||
if (!tmp)
|
|
||||||
return{};
|
|
||||||
if (!SplitDelete(t0, t1))
|
if (!SplitDelete(t0, t1))
|
||||||
return{};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
@ -564,14 +564,15 @@ Track::Holder WaveTrack::SplitCut(double t0, double t1)
|
|||||||
Track::Holder WaveTrack::CutAndAddCutLine(double t0, double t1)
|
Track::Holder WaveTrack::CutAndAddCutLine(double t0, double t1)
|
||||||
{
|
{
|
||||||
if (t1 < t0)
|
if (t1 < t0)
|
||||||
return {};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
// Cut is the same as 'Copy', then 'Delete'
|
// Cut is the same as 'Copy', then 'Delete'
|
||||||
auto tmp = Copy(t0, t1);
|
auto tmp = Copy(t0, t1);
|
||||||
if (!tmp)
|
|
||||||
return {};
|
|
||||||
if (!ClearAndAddCutLine(t0, t1))
|
if (!ClearAndAddCutLine(t0, t1))
|
||||||
return {};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
@ -636,7 +637,8 @@ bool WaveTrack::Trim (double t0, double t1)
|
|||||||
Track::Holder WaveTrack::Copy(double t0, double t1, bool forClipboard) const
|
Track::Holder WaveTrack::Copy(double t0, double t1, bool forClipboard) const
|
||||||
{
|
{
|
||||||
if (t1 <= t0)
|
if (t1 <= t0)
|
||||||
return{};
|
//THROW_INCONSISTENCY_EXCEPTION
|
||||||
|
;
|
||||||
|
|
||||||
WaveTrack *newTrack;
|
WaveTrack *newTrack;
|
||||||
Track::Holder result
|
Track::Holder result
|
||||||
@ -1166,8 +1168,6 @@ bool WaveTrack::SyncLockAdjust(double oldT1, double newT1)
|
|||||||
gPrefs->Read(wxT("/GUI/EditClipCanMove"), &clipsCanMove);
|
gPrefs->Read(wxT("/GUI/EditClipCanMove"), &clipsCanMove);
|
||||||
if (clipsCanMove) {
|
if (clipsCanMove) {
|
||||||
auto tmp = Cut (oldT1, GetEndTime() + 1.0/GetRate());
|
auto tmp = Cut (oldT1, GetEndTime() + 1.0/GetRate());
|
||||||
if (!tmp)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ret = Paste(newT1, tmp.get());
|
ret = Paste(newT1, tmp.get());
|
||||||
wxASSERT(ret);
|
wxASSERT(ret);
|
||||||
|
@ -1173,20 +1173,17 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
|
|||||||
//remove the old audio and get the NEW
|
//remove the old audio and get the NEW
|
||||||
t->Clear(clipStartEndTimes[i].first,clipStartEndTimes[i].second);
|
t->Clear(clipStartEndTimes[i].first,clipStartEndTimes[i].second);
|
||||||
auto toClipOutput = output->Copy(clipStartEndTimes[i].first-startT+offsetT0,clipStartEndTimes[i].second-startT+offsetT0);
|
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());
|
||||||
//put the processed audio in
|
wxASSERT(bResult); // TO DO: Actually handle this.
|
||||||
bool bResult = t->Paste(clipStartEndTimes[i].first, toClipOutput.get());
|
wxUnusedVar(bResult);
|
||||||
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
|
||||||
wxUnusedVar(bResult);
|
//This is not true when the selection is fully contained within one clip (second half of conditional)
|
||||||
//if the clip was only partially selected, the Paste will have created a split line. Join is needed to take care of this
|
if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first ||
|
||||||
//This is not true when the selection is fully contained within one clip (second half of conditional)
|
clipRealStartEndTimes[i].second != clipStartEndTimes[i].second) &&
|
||||||
if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first ||
|
!(clipRealStartEndTimes[i].first <= startT &&
|
||||||
clipRealStartEndTimes[i].second != clipStartEndTimes[i].second) &&
|
clipRealStartEndTimes[i].second >= startT+lenT) )
|
||||||
!(clipRealStartEndTimes[i].first <= startT &&
|
t->Join(clipRealStartEndTimes[i].first,clipRealStartEndTimes[i].second);
|
||||||
clipRealStartEndTimes[i].second >= startT+lenT) )
|
|
||||||
t->Join(clipRealStartEndTimes[i].first,clipRealStartEndTimes[i].second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,19 +558,16 @@ bool EffectEqualization48x::ProcessTail(WaveTrack * t, WaveTrack * output, sampl
|
|||||||
t->Clear(clipStartEndTimes[i].first,clipStartEndTimes[i].second);
|
t->Clear(clipStartEndTimes[i].first,clipStartEndTimes[i].second);
|
||||||
// output->Copy(clipStartEndTimes[i].first-startT+offsetT0,clipStartEndTimes[i].second-startT+offsetT0, &toClipOutput);
|
// 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);
|
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());
|
||||||
//put the processed audio in
|
wxASSERT(bResult); // TO DO: Actually handle this.
|
||||||
bool bResult = t->Paste(clipStartEndTimes[i].first, toClipOutput.get());
|
//if the clip was only partially selected, the Paste will have created a split line. Join is needed to take care of this
|
||||||
wxASSERT(bResult); // TO DO: Actually handle this.
|
//This is not true when the selection is fully contained within one clip (second half of conditional)
|
||||||
//if the clip was only partially selected, the Paste will have created a split line. Join is needed to take care of this
|
if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first ||
|
||||||
//This is not true when the selection is fully contained within one clip (second half of conditional)
|
clipRealStartEndTimes[i].second != clipStartEndTimes[i].second) &&
|
||||||
if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first ||
|
!(clipRealStartEndTimes[i].first <= startT &&
|
||||||
clipRealStartEndTimes[i].second != clipStartEndTimes[i].second) &&
|
clipRealStartEndTimes[i].second >= startT+lenT) )
|
||||||
!(clipRealStartEndTimes[i].first <= startT &&
|
t->Join(clipRealStartEndTimes[i].first,clipRealStartEndTimes[i].second);
|
||||||
clipRealStartEndTimes[i].second >= startT+lenT) )
|
|
||||||
t->Join(clipRealStartEndTimes[i].first,clipRealStartEndTimes[i].second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user