1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 08:59:28 +02:00

void return, not boolean success, from some Track virtual functions...

... The return codes were mostly ignored anyway, and exceptions will be thrown
instead.

It seems there was also confusion whether the return values of Track::Paste
and Track::SyncLockAdjust were to indicate success or indicate whether there
was any change.  No matter now.
This commit is contained in:
Paul Licameli 2017-03-23 11:10:14 -04:00
parent a23d6e2368
commit e1473dfe76
22 changed files with 131 additions and 165 deletions

View File

@ -2474,13 +2474,10 @@ void AudioIO::StopStream()
} }
if( appendRecord ) if( appendRecord )
{ // append-recording { // append-recording
bool bResult;
if (recordingOffset < 0) if (recordingOffset < 0)
bResult = track->Clear(mT0, mT0 - recordingOffset); // cut the latency out track->Clear(mT0, mT0 - recordingOffset); // cut the latency out
else else
bResult = track->InsertSilence(mT0, recordingOffset); // put silence in track->InsertSilence(mT0, recordingOffset); // put silence in
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
} }
else else
{ // recording into a NEW track { // recording into a NEW track

View File

@ -449,8 +449,10 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
if (mEditDetail) if (mEditDetail)
Printf(wxT("Paste: %d\n"), y0 * chunkSize); Printf(wxT("Paste: %d\n"), y0 * chunkSize);
if (!t->Paste((double)(y0 * chunkSize), tmp.get())) try {
{ t->Paste((double)(y0 * chunkSize), tmp.get());
}
catch (const AudacityException&) {
Printf(wxT("Trial %d\nFailed on Paste.\n"), z); Printf(wxT("Trial %d\nFailed on Paste.\n"), z);
goto fail; goto fail;
} }

View File

@ -153,7 +153,7 @@ void LabelTrack::SetOffset(double dOffset)
labelStruct.selectedRegion.move(dOffset); labelStruct.selectedRegion.move(dOffset);
} }
bool LabelTrack::Clear(double b, double e) void LabelTrack::Clear(double b, double e)
{ {
// May DELETE labels, so use subscripts to iterate // May DELETE labels, so use subscripts to iterate
for (size_t i = 0; i < mLabels.size(); ++i) { for (size_t i = 0; i < mLabels.size(); ++i) {
@ -175,8 +175,6 @@ bool LabelTrack::Clear(double b, double e)
else if (relation == LabelStruct::WITHIN_LABEL) else if (relation == LabelStruct::WITHIN_LABEL)
labelStruct.selectedRegion.moveT1( - (e-b)); labelStruct.selectedRegion.moveT1( - (e-b));
} }
return true;
} }
#if 0 #if 0
@ -2340,9 +2338,7 @@ Track::Holder LabelTrack::Cut(double t0, double t1)
{ {
auto tmp = Copy(t0, t1); auto tmp = Copy(t0, t1);
if (!Clear(t0, t1)) Clear(t0, t1);
//THROW_INCONSISTENCY_EXCEPTION
;
return tmp; return tmp;
} }
@ -2416,6 +2412,7 @@ Track::Holder LabelTrack::Copy(double t0, double t1, bool) const
bool LabelTrack::PasteOver(double t, const Track * src) bool LabelTrack::PasteOver(double t, const Track * src)
{ {
if (src->GetKind() != Track::Label) if (src->GetKind() != Track::Label)
// THROW_INCONSISTENCY_EXCEPTION; // ?
return false; return false;
int len = mLabels.size(); int len = mLabels.size();
@ -2439,17 +2436,18 @@ bool LabelTrack::PasteOver(double t, const Track * src)
return true; return true;
} }
bool LabelTrack::Paste(double t, const Track *src) void LabelTrack::Paste(double t, const Track *src)
{ {
if (src->GetKind() != Track::Label) if (src->GetKind() != Track::Label)
return false; // THROW_INCONSISTENCY_EXCEPTION; // ?
return;
LabelTrack *lt = (LabelTrack *)src; LabelTrack *lt = (LabelTrack *)src;
double shiftAmt = lt->mClipLen > 0.0 ? lt->mClipLen : lt->GetEndTime(); double shiftAmt = lt->mClipLen > 0.0 ? lt->mClipLen : lt->GetEndTime();
ShiftLabelsOnInsert(shiftAmt, t); ShiftLabelsOnInsert(shiftAmt, t);
return PasteOver(t, src); PasteOver(t, src);
} }
// This repeats the labels in a time interval a specified number of times. // This repeats the labels in a time interval a specified number of times.
@ -2505,7 +2503,7 @@ bool LabelTrack::Repeat(double t0, double t1, int n)
return true; return true;
} }
bool LabelTrack::Silence(double t0, double t1) void LabelTrack::Silence(double t0, double t1)
{ {
int len = mLabels.size(); int len = mLabels.size();
@ -2549,11 +2547,9 @@ bool LabelTrack::Silence(double t0, double t1)
} }
SortLabels(); SortLabels();
return true;
} }
bool LabelTrack::InsertSilence(double t, double len) void LabelTrack::InsertSilence(double t, double len)
{ {
for (auto &labelStruct: mLabels) { for (auto &labelStruct: mLabels) {
double t0 = labelStruct.getT0(); double t0 = labelStruct.getT0();
@ -2565,8 +2561,6 @@ bool LabelTrack::InsertSilence(double t, double len)
t1 += len; t1 += len;
labelStruct.selectedRegion.setTimes(t0, t1); labelStruct.selectedRegion.setTimes(t0, t1);
} }
return true;
} }
int LabelTrack::GetNumLabels() const int LabelTrack::GetNumLabels() const

View File

@ -156,12 +156,12 @@ class AUDACITY_DLL_API LabelTrack final : public Track
Track::Holder Cut (double t0, double t1) override; Track::Holder Cut (double t0, double t1) override;
Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override; Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override;
bool Clear(double t0, double t1) override; void Clear(double t0, double t1) override;
bool Paste(double t, const Track * src) override; void Paste(double t, const Track * src) override;
bool Repeat(double t0, double t1, int n); bool Repeat(double t0, double t1, int n);
bool Silence(double t0, double t1) override; void Silence(double t0, double t1) override;
bool InsertSilence(double t, double len) override; void InsertSilence(double t, double len) override;
int OverGlyph(int x, int y); int OverGlyph(int x, int y);
static wxBitmap & GetGlyph( int i); static wxBitmap & GetGlyph( int i);

View File

@ -4384,7 +4384,11 @@ void AudacityProject::OnPaste()
{ {
// Must perform sync-lock adjustment before incrementing n // Must perform sync-lock adjustment before incrementing n
if (n->IsSyncLockSelected()) { if (n->IsSyncLockSelected()) {
bPastedSomething |= n->SyncLockAdjust(t1, t0+(msClipT1 - msClipT0)); auto newT1 = t0 + (msClipT1 - msClipT0);
if (t1 != newT1 && t1 <= n->GetEndTime()) {
n->SyncLockAdjust(t1, newT1);
bPastedSomething = true;
}
} }
n = iter.Next(); n = iter.Next();
} }
@ -4441,8 +4445,9 @@ void AudacityProject::OnPaste()
} }
else else
{ {
bPastedSomething = true;
n->Clear(t0, t1); n->Clear(t0, t1);
bPastedSomething |= n->Paste(t0, c); n->Paste(t0, c);
} }
// When copying from mono to stereo track, paste the wave form // When copying from mono to stereo track, paste the wave form
@ -4457,7 +4462,8 @@ void AudacityProject::OnPaste()
else else
{ {
n->Clear(t0, t1); n->Clear(t0, t1);
bPastedSomething |= n->Paste(t0, c); bPastedSomething = true;
n->Paste(t0, c);
} }
} }
@ -4468,7 +4474,11 @@ void AudacityProject::OnPaste()
} // if (n->GetSelected()) } // if (n->GetSelected())
else if (n->IsSyncLockSelected()) else if (n->IsSyncLockSelected())
{ {
bPastedSomething |= n->SyncLockAdjust(t1, t0 + msClipT1 - msClipT0); auto newT1 = t0 + (msClipT1 - msClipT0);
if (t1 != newT1 && t1 <= n->GetEndTime()) {
n->SyncLockAdjust(t1, newT1);
bPastedSomething = true;
}
} }
n = iter.Next(); n = iter.Next();
@ -4492,9 +4502,7 @@ void AudacityProject::OnPaste()
} }
else { else {
auto tmp = mTrackFactory->NewWaveTrack( ((WaveTrack*)n)->GetSampleFormat(), ((WaveTrack*)n)->GetRate()); auto tmp = mTrackFactory->NewWaveTrack( ((WaveTrack*)n)->GetSampleFormat(), ((WaveTrack*)n)->GetRate());
bool bResult = tmp->InsertSilence(0.0, msClipT1 - msClipT0); // MJS: Is this correct? tmp->InsertSilence(0.0, msClipT1 - msClipT0); // MJS: Is this correct?
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
tmp->Flush(); tmp->Flush();
bPastedSomething |= bPastedSomething |=
@ -4637,9 +4645,7 @@ bool AudacityProject::HandlePasteNothingSelected()
} }
wxASSERT(pClip); wxASSERT(pClip);
bool bResult = pNewTrack->Paste(0.0, pClip); pNewTrack->Paste(0.0, pClip);
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
if (!pFirstNewTrack) if (!pFirstNewTrack)
pFirstNewTrack = pNewTrack; pFirstNewTrack = pNewTrack;
@ -4941,7 +4947,7 @@ void AudacityProject::OnCutLabels()
if( gPrefs->Read( wxT( "/GUI/EnableCutLines" ), ( long )0 ) ) if( gPrefs->Read( wxT( "/GUI/EnableCutLines" ), ( long )0 ) )
EditByLabel( &WaveTrack::ClearAndAddCutLine, true ); EditByLabel( &WaveTrack::ClearAndAddCutLine, true );
else else
EditByLabel( &WaveTrack::Clear, true ); EditByLabel( &WaveTrack::Clear1, true );
msClipProject = this; msClipProject = this;
@ -4995,7 +5001,7 @@ void AudacityProject::OnDeleteLabels()
if( mViewInfo.selectedRegion.isPoint() ) if( mViewInfo.selectedRegion.isPoint() )
return; return;
EditByLabel( &WaveTrack::Clear, true ); EditByLabel( &WaveTrack::Clear1, true );
mViewInfo.selectedRegion.collapseToT0(); mViewInfo.selectedRegion.collapseToT0();
@ -5029,7 +5035,7 @@ void AudacityProject::OnSilenceLabels()
if( mViewInfo.selectedRegion.isPoint() ) if( mViewInfo.selectedRegion.isPoint() )
return; return;
EditByLabel( &WaveTrack::Silence, false ); EditByLabel( &WaveTrack::Silence1, false );
PushState( PushState(
/* i18n-hint: (verb)*/ /* i18n-hint: (verb)*/

View File

@ -492,20 +492,19 @@ bool NoteTrack::Trim(double t0, double t1)
return true; return true;
} }
bool NoteTrack::Clear(double t0, double t1) void NoteTrack::Clear(double t0, double t1)
{ {
// If t1 = t0, should Clear return true? // If t1 = t0, should Clear return true?
if (t1 <= t0) if (t1 <= t0)
return false; // THROW_INCONSISTENCY_EXCEPTION; ?
return;
double len = t1-t0; double len = t1-t0;
if (mSeq) if (mSeq)
mSeq->clear(t0 - GetOffset(), len, false); mSeq->clear(t0 - GetOffset(), len, false);
return true;
} }
bool NoteTrack::Paste(double t, const Track *src) void NoteTrack::Paste(double t, const Track *src)
{ {
// Paste inserts src at time t. If src has a positive offset, // Paste inserts src at time t. If src has a positive offset,
// the offset is treated as silence which is also inserted. If // the offset is treated as silence which is also inserted. If
@ -517,11 +516,13 @@ bool NoteTrack::Paste(double t, const Track *src)
//Check that src is a non-NULL NoteTrack //Check that src is a non-NULL NoteTrack
if (src == NULL || src->GetKind() != Track::Note) if (src == NULL || src->GetKind() != Track::Note)
return false; // THROW_INCONSISTENCY_EXCEPTION; // ?
return;
NoteTrack* other = (NoteTrack*)src; NoteTrack* other = (NoteTrack*)src;
if (other->mSeq == NULL) if (other->mSeq == NULL)
return false; // THROW_INCONSISTENCY_EXCEPTION; // ?
return;
if(!mSeq) if(!mSeq)
mSeq = std::make_unique<Alg_seq>(); mSeq = std::make_unique<Alg_seq>();
@ -532,20 +533,16 @@ bool NoteTrack::Paste(double t, const Track *src)
t += other->GetOffset(); t += other->GetOffset();
} }
mSeq->paste(t - GetOffset(), other->mSeq.get()); mSeq->paste(t - GetOffset(), other->mSeq.get());
return true;
} }
bool NoteTrack::Silence(double, double) void NoteTrack::Silence(double, double)
{ {
// to do // to do
return false;
} }
bool NoteTrack::InsertSilence(double, double) void NoteTrack::InsertSilence(double, double)
{ {
// to do // to do
return false;
} }
// Call this function to manipulate the underlying sequence data. This is // Call this function to manipulate the underlying sequence data. This is

View File

@ -103,10 +103,10 @@ class AUDACITY_DLL_API NoteTrack final
Track::Holder Cut (double t0, double t1) override; Track::Holder Cut (double t0, double t1) override;
Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override; Track::Holder Copy (double t0, double t1, bool forClipboard = true) const override;
bool Trim (double t0, double t1) /* not override */; bool Trim (double t0, double t1) /* not override */;
bool Clear(double t0, double t1) override; void Clear(double t0, double t1) override;
bool Paste(double t, const Track *src) override; void Paste(double t, const Track *src) override;
bool Silence(double t0, double t1) override; void Silence(double t0, double t1) override;
bool InsertSilence(double t, double len) override; void InsertSilence(double t, double len) override;
bool Shift(double t) /* not override */; bool Shift(double t) /* not override */;
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT

View File

@ -4993,9 +4993,7 @@ void AudacityProject::EditClipboardByLabel( EditDestFunction action )
// right to left. Any placeholder already in merged is kept. // right to left. Any placeholder already in merged is kept.
// Only the rightmost placeholder is important in the final // Only the rightmost placeholder is important in the final
// result. // result.
bool bResult = merged->Paste( 0.0 , dest.get() ); merged->Paste( 0.0 , dest.get() );
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
} }
} }
else // nothing copied but there is a 'region', so the 'region' must be a 'point label' so offset else // nothing copied but there is a 'region', so the 'region' must be a 'point label' so offset

View File

@ -120,30 +120,27 @@ Track::Holder TimeTrack::Copy( double t0, double t1, bool ) const
return Track::Holder{ std::move( result ) }; return Track::Holder{ std::move( result ) };
} }
bool TimeTrack::Clear(double t0, double t1) void TimeTrack::Clear(double t0, double t1)
{ {
mEnvelope->CollapseRegion(t0, t1); mEnvelope->CollapseRegion(t0, t1);
return true;
} }
bool TimeTrack::Paste(double t, const Track * src) void TimeTrack::Paste(double t, const Track * src)
{ {
if (src->GetKind() != Track::Time) if (src->GetKind() != Track::Time)
return false; // THROW_INCONSISTENCY_EXCEPTION; // ?
return;
mEnvelope->Paste(t, static_cast<const TimeTrack*>(src)->mEnvelope.get()); mEnvelope->Paste(t, static_cast<const TimeTrack*>(src)->mEnvelope.get());
return true;
} }
bool TimeTrack::Silence(double t0, double t1) void TimeTrack::Silence(double t0, double t1)
{ {
return true;
} }
bool TimeTrack::InsertSilence(double t, double len) void TimeTrack::InsertSilence(double t, double len)
{ {
mEnvelope->InsertSpace(t, len); mEnvelope->InsertSpace(t, len);
return true;
} }
Track::Holder TimeTrack::Duplicate() const Track::Holder TimeTrack::Duplicate() const

View File

@ -43,10 +43,10 @@ class TimeTrack final : public Track {
Holder Cut( double t0, double t1 ) override; Holder Cut( double t0, double t1 ) override;
Holder Copy( double t0, double t1, bool forClipboard ) const override; Holder Copy( double t0, double t1, bool forClipboard ) const override;
bool Clear(double t0, double t1) override; void Clear(double t0, double t1) override;
bool Paste(double t, const Track * src) override; void Paste(double t, const Track * src) override;
bool Silence(double t0, double t1) override; void Silence(double t0, double t1) override;
bool InsertSilence(double t, double len) override; void InsertSilence(double t, double len) override;
// Identifying the type of track // Identifying the type of track
int GetKind() const override { return Time; } int GetKind() const override { return Time; }

View File

@ -300,28 +300,22 @@ bool Track::IsSyncLockSelected() const
return false; return false;
} }
bool Track::SyncLockAdjust(double oldT1, double newT1) void Track::SyncLockAdjust(double oldT1, double newT1)
{ {
if (newT1 > oldT1) { if (newT1 > oldT1) {
// Insert space within the track // Insert space within the track
if (oldT1 > GetEndTime()) if (oldT1 > GetEndTime())
return true; return;
auto tmp = Cut(oldT1, GetEndTime()); auto tmp = Cut(oldT1, GetEndTime());
bool ret = Paste(newT1, tmp.get()); Paste(newT1, tmp.get());
wxASSERT(ret); // TODO: handle this.
return ret;
} }
else if (newT1 < oldT1) { else if (newT1 < oldT1) {
// Remove from the track // Remove from the track
return Clear(newT1, oldT1); Clear(newT1, oldT1);
} }
// fall-through: no change
return true;
} }
void PlayableTrack::Init( const PlayableTrack &orig ) void PlayableTrack::Init( const PlayableTrack &orig )

View File

@ -217,18 +217,16 @@ class AUDACITY_DLL_API Track /* not final */ : public XMLTagHandler
virtual Holder Copy virtual Holder Copy
(double WXUNUSED(t0), double WXUNUSED(t1), bool forClipboard = true) const = 0; (double WXUNUSED(t0), double WXUNUSED(t1), bool forClipboard = true) const = 0;
// Return true for success virtual void Clear(double WXUNUSED(t0), double WXUNUSED(t1)) = 0;
virtual bool Clear(double WXUNUSED(t0), double WXUNUSED(t1)) = 0;
// Return true for success virtual void Paste(double WXUNUSED(t), const Track * WXUNUSED(src)) = 0;
virtual bool Paste(double WXUNUSED(t), const Track * WXUNUSED(src)) = 0;
// This can be used to adjust a sync-lock selected track when the selection // This can be used to adjust a sync-lock selected track when the selection
// is replaced by one of a different length. // is replaced by one of a different length.
virtual bool SyncLockAdjust(double oldT1, double newT1); virtual void SyncLockAdjust(double oldT1, double newT1);
virtual bool Silence(double WXUNUSED(t0), double WXUNUSED(t1)) = 0; virtual void Silence(double WXUNUSED(t0), double WXUNUSED(t1)) = 0;
virtual bool InsertSilence(double WXUNUSED(t), double WXUNUSED(len)) = 0; virtual void InsertSilence(double WXUNUSED(t), double WXUNUSED(len)) = 0;
virtual int GetKind() const { return None; } virtual int GetKind() const { return None; }

View File

@ -537,9 +537,7 @@ Track::Holder WaveTrack::Cut(double t0, double t1)
auto tmp = Copy(t0, t1); auto tmp = Copy(t0, t1);
if (!Clear(t0, t1)) Clear(t0, t1);
// THROW_INCONSISTENCY_EXCEPTION
;
return tmp; return tmp;
} }
@ -617,10 +615,7 @@ bool WaveTrack::Trim (double t0, double t1)
//if inside0 is false, then the left selector was between //if inside0 is false, then the left selector was between
//clips, so DELETE everything to its left. //clips, so DELETE everything to its left.
if(false == inside1) if(false == inside1)
{ Clear(t1,GetEndTime());
if (!Clear(t1,GetEndTime()))
return false;
}
if(false == inside0) if(false == inside0)
{ {
@ -713,9 +708,9 @@ Track::Holder WaveTrack::CopyNonconst(double t0, double t1)
return Copy(t0, t1); return Copy(t0, t1);
} }
bool WaveTrack::Clear(double t0, double t1) void WaveTrack::Clear(double t0, double t1)
{ {
return HandleClear(t0, t1, false, false); HandleClear(t0, t1, false, false);
} }
bool WaveTrack::ClearAndAddCutLine(double t0, double t1) bool WaveTrack::ClearAndAddCutLine(double t0, double t1)
@ -812,7 +807,8 @@ bool WaveTrack::ClearAndPaste(double t0, // Start of time to clear
// If duration is 0, then it's just a plain paste // If duration is 0, then it's just a plain paste
if (dur == 0.0) { if (dur == 0.0) {
return Paste(t0, src); Paste(t0, src);
return true;
} }
// If provided time warper was NULL, use a default one that does nothing // If provided time warper was NULL, use a default one that does nothing
@ -867,7 +863,8 @@ bool WaveTrack::ClearAndPaste(double t0, // Start of time to clear
if (HandleClear(t0, t1, false, false)) { if (HandleClear(t0, t1, false, false)) {
// And paste in the NEW data // And paste in the NEW data
if (Paste(t0, src)) { Paste(t0, src);
{
// First, merge the NEW clip(s) in with the existing clips // First, merge the NEW clip(s) in with the existing clips
if (merge && splits.GetCount() > 0) if (merge && splits.GetCount() > 0)
{ {
@ -1147,7 +1144,7 @@ bool WaveTrack::HandleClear(double t0, double t1,
return true; return true;
} }
bool WaveTrack::SyncLockAdjust(double oldT1, double newT1) void WaveTrack::SyncLockAdjust(double oldT1, double newT1)
{ {
if (newT1 > oldT1) { if (newT1 > oldT1) {
// Insert space within the track // Insert space within the track
@ -1156,62 +1153,57 @@ bool WaveTrack::SyncLockAdjust(double oldT1, double newT1)
// GetEndTime() looks through the clips and may give us EXACTLY the same // GetEndTime() looks through the clips and may give us EXACTLY the same
// value as T1, when T1 was set to be at the end of one of those clips. // value as T1, when T1 was set to be at the end of one of those clips.
if (oldT1 >= GetEndTime()) if (oldT1 >= GetEndTime())
return true; return;
// If track is empty at oldT1 insert whitespace; otherwise, silence // If track is empty at oldT1 insert whitespace; otherwise, silence
if (IsEmpty(oldT1, oldT1)) if (IsEmpty(oldT1, oldT1))
{ {
bool ret = true;
// Check if clips can move // Check if clips can move
bool clipsCanMove = true; bool clipsCanMove = true;
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());
ret = Paste(newT1, tmp.get()); Paste(newT1, tmp.get());
wxASSERT(ret);
} }
return;
return ret;
} }
else { else {
// AWD: Could just use InsertSilence() on its own here, but it doesn't // AWD: Could just use InsertSilence() on its own here, but it doesn't
// follow EditClipCanMove rules (Paste() does it right) // follow EditClipCanMove rules (Paste() does it right)
AudacityProject *p = GetActiveProject(); AudacityProject *p = GetActiveProject();
if (!p) return false; if (!p)
// THROW_INCONSISTENCY_EXCEPTION
;
TrackFactory *f = p->GetTrackFactory(); TrackFactory *f = p->GetTrackFactory();
if (!f) return false; if (!f)
// THROW_INCONSISTENCY_EXCEPTION
;
auto tmp = f->NewWaveTrack(GetSampleFormat(), GetRate()); auto tmp = f->NewWaveTrack(GetSampleFormat(), GetRate());
bool bResult = tmp->InsertSilence(0.0, newT1 - oldT1); tmp->InsertSilence(0.0, newT1 - oldT1);
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
tmp->Flush(); tmp->Flush();
bResult = Paste(oldT1, tmp.get()); Paste(oldT1, tmp.get());
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
} }
} }
else if (newT1 < oldT1) { else if (newT1 < oldT1) {
return Clear(newT1, oldT1); Clear(newT1, oldT1);
} }
// fall-through: no change
return true;
} }
bool WaveTrack::Paste(double t0, const Track *src) void WaveTrack::Paste(double t0, const Track *src)
// WEAK-GUARANTEE // WEAK-GUARANTEE
{ {
bool editClipCanMove = true; bool editClipCanMove = true;
gPrefs->Read(wxT("/GUI/EditClipCanMove"), &editClipCanMove); gPrefs->Read(wxT("/GUI/EditClipCanMove"), &editClipCanMove);
if( src == NULL ) if( src == NULL )
return false; // THROW_INCONSISTENCY_EXCEPTION; // ?
return;
if (src->GetKind() != Track::Wave) if (src->GetKind() != Track::Wave)
return false; // THROW_INCONSISTENCY_EXCEPTION; // ?
return;
const WaveTrack* other = static_cast<const WaveTrack*>(src); const WaveTrack* other = static_cast<const WaveTrack*>(src);
@ -1237,7 +1229,7 @@ bool WaveTrack::Paste(double t0, const Track *src)
// //
if (other->GetNumClips() == 0) if (other->GetNumClips() == 0)
return false; return;
//printf("paste: we have at least one clip\n"); //printf("paste: we have at least one clip\n");
@ -1254,9 +1246,7 @@ bool WaveTrack::Paste(double t0, const Track *src)
// move everything to the right, then try to paste again // move everything to the right, then try to paste again
if (!IsEmpty(t0, GetEndTime())) { if (!IsEmpty(t0, GetEndTime())) {
auto tmp = Cut(t0, GetEndTime()+1.0/mRate); auto tmp = Cut(t0, GetEndTime()+1.0/mRate);
bool bResult = Paste(t0 + insertDuration, tmp.get()); Paste(t0 + insertDuration, tmp.get());
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
} }
} }
else { else {
@ -1351,13 +1341,13 @@ bool WaveTrack::Paste(double t0, const Track *src)
mClips.push_back(std::move(newClip)); // transfer ownership mClips.push_back(std::move(newClip)); // transfer ownership
} }
} }
return true;
} }
bool WaveTrack::Silence(double t0, double t1) void WaveTrack::Silence(double t0, double t1)
{ {
if (t1 < t0) if (t1 < t0)
return false; // THROW_INCONSISTENCY_EXCEPTION; // ?
return;
auto start = (sampleCount)floor(t0 * mRate + 0.5); auto start = (sampleCount)floor(t0 * mRate + 0.5);
auto len = (sampleCount)floor(t1 * mRate + 0.5) - start; auto len = (sampleCount)floor(t1 * mRate + 0.5) - start;
@ -1386,25 +1376,25 @@ bool WaveTrack::Silence(double t0, double t1)
if (!clip->GetSequence()->SetSilence(inclipDelta, samplesToCopy)) if (!clip->GetSequence()->SetSilence(inclipDelta, samplesToCopy))
{ {
wxASSERT(false); // should always work wxASSERT(false); // should always work
return false; return;
} }
clip->MarkChanged(); clip->MarkChanged();
} }
} }
return result;
} }
bool WaveTrack::InsertSilence(double t, double len) void WaveTrack::InsertSilence(double t, double len)
{ {
if (len <= 0) if (len <= 0)
return false; // THROW_INCONSISTENCY_EXCEPTION; // ?
return;
if (mClips.empty()) if (mClips.empty())
{ {
// Special case if there is no clip yet // Special case if there is no clip yet
WaveClip* clip = CreateClip(); WaveClip* clip = CreateClip();
return clip->InsertSilence(0, len); clip->InsertSilence(0, len);
return;
} }
for (const auto &clip : mClips) for (const auto &clip : mClips)
@ -1414,12 +1404,10 @@ bool WaveTrack::InsertSilence(double t, double len)
else if (clip->WithinClip(t)) else if (clip->WithinClip(t))
{ {
if (!clip->InsertSilence(t, len)) { if (!clip->InsertSilence(t, len)) {
return false; return;
} }
} }
} }
return true;
} }
//Performs the opposite of Join //Performs the opposite of Join

View File

@ -175,16 +175,18 @@ class AUDACITY_DLL_API WaveTrack final : public PlayableTrack {
Track::Holder Copy(double t0, double t1, bool forClipboard = true) const override; Track::Holder Copy(double t0, double t1, bool forClipboard = true) const override;
Track::Holder CopyNonconst(double t0, double t1) /* not override */; Track::Holder CopyNonconst(double t0, double t1) /* not override */;
bool Clear(double t0, double t1) override; void Clear(double t0, double t1) override;
bool Paste(double t0, const Track *src) override; bool Clear1(double t0, double t1) { Clear(t0, t1); return true; }
void Paste(double t0, const Track *src) override;
bool ClearAndPaste(double t0, double t1, bool ClearAndPaste(double t0, double t1,
const Track *src, const Track *src,
bool preserve = true, bool preserve = true,
bool merge = true, bool merge = true,
const TimeWarper *effectWarper = NULL) /* not override */; const TimeWarper *effectWarper = NULL) /* not override */;
bool Silence(double t0, double t1) override; void Silence(double t0, double t1) override;
bool InsertSilence(double t, double len) override; bool Silence1(double t0, double t1) { Silence(t0, t1); return true; }
void InsertSilence(double t, double len) override;
bool SplitAt(double t) /* not override */; bool SplitAt(double t) /* not override */;
bool Split(double t0, double t1) /* not override */; bool Split(double t0, double t1) /* not override */;
@ -200,7 +202,7 @@ class AUDACITY_DLL_API WaveTrack final : public PlayableTrack {
bool HandleClear(double t0, double t1, bool addCutLines, bool split); bool HandleClear(double t0, double t1, bool addCutLines, bool split);
bool SyncLockAdjust(double oldT1, double newT1) override; void SyncLockAdjust(double oldT1, double newT1) override;
/** @brief Returns true if there are no WaveClips in the specified region /** @brief Returns true if there are no WaveClips in the specified region
* *

View File

@ -1968,8 +1968,7 @@ void Effect::GetSamples(
t1 = t0 + mDuration; t1 = t0 + mDuration;
if (mT0 == mT1) { if (mT0 == mT1) {
// Not really part of the calculation, but convenient to put here // Not really part of the calculation, but convenient to put here
bool bResult = track->InsertSilence(t0, t1); track->InsertSilence(t0, t1);
wxASSERT(bResult); // TO DO: Actually handle this.
} }
} }
#endif #endif

View File

@ -1174,9 +1174,7 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
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);
//put the processed audio in //put the processed audio in
bool bResult = t->Paste(clipStartEndTimes[i].first, toClipOutput.get()); 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 //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) //This is not true when the selection is fully contained within one clip (second half of conditional)
if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first || if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first ||

View File

@ -559,8 +559,7 @@ bool EffectEqualization48x::ProcessTail(WaveTrack * t, WaveTrack * output, sampl
// 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);
//put the processed audio in //put the processed audio in
bool bResult = t->Paste(clipStartEndTimes[i].first, toClipOutput.get()); 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 //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) //This is not true when the selection is fully contained within one clip (second half of conditional)
if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first || if( (clipRealStartEndTimes[i].first != clipStartEndTimes[i].first ||

View File

@ -378,11 +378,11 @@ bool EffectPaulstretch::ProcessOne(WaveTrack *track,double t0,double t1,int coun
} }
} }
if (!cancelled){
outputTrack->Flush(); outputTrack->Flush();
track->Clear(t0,t1); track->Clear(t0,t1);
bool success = track->Paste(t0, outputTrack.get()); track->Paste(t0, outputTrack.get());
if (!cancelled && success){
m_t1 = mT0 + outputTrack->GetEndTime(); m_t1 = mT0 + outputTrack->GetEndTime();
} }

View File

@ -139,12 +139,12 @@ bool EffectRepeat::Process()
auto dest = track->Copy(mT0, mT1); auto dest = track->Copy(mT0, mT1);
for(int j=0; j<repeatCount; j++) for(int j=0; j<repeatCount; j++)
{ {
if (!track->Paste(tc, dest.get()) || if (TrackProgress(nTrack, j / repeatCount)) // TrackProgress returns true on Cancel.
TrackProgress(nTrack, j / repeatCount)) // TrackProgress returns true on Cancel.
{ {
bGoodResult = false; bGoodResult = false;
break; break;
} }
track->Paste(tc, dest.get());
tc += tLen; tc += tLen;
} }
if (tc > maxDestLen) if (tc > maxDestLen)

View File

@ -97,7 +97,6 @@ bool EffectSilence::GenerateTrack(WaveTrack *tmp,
const WaveTrack & WXUNUSED(track), const WaveTrack & WXUNUSED(track),
int WXUNUSED(ntrack)) int WXUNUSED(ntrack))
{ {
bool bResult = tmp->InsertSilence(0.0, GetDuration()); tmp->InsertSilence(0.0, GetDuration());
wxASSERT(bResult); return true;
return bResult;
} }

View File

@ -163,9 +163,9 @@ bool EffectStereoToMono::ProcessOne(int count)
} }
double minStart = wxMin(mLeftTrack->GetStartTime(), mRightTrack->GetStartTime()); double minStart = wxMin(mLeftTrack->GetStartTime(), mRightTrack->GetStartTime());
bResult &= mLeftTrack->Clear(mLeftTrack->GetStartTime(), mLeftTrack->GetEndTime()); mLeftTrack->Clear(mLeftTrack->GetStartTime(), mLeftTrack->GetEndTime());
bResult &= mOutTrack->Flush(); bResult &= mOutTrack->Flush();
bResult &= mLeftTrack->Paste(minStart, mOutTrack.get()); mLeftTrack->Paste(minStart, mOutTrack.get());
mLeftTrack->SetLinked(false); mLeftTrack->SetLinked(false);
mRightTrack->SetLinked(false); mRightTrack->SetLinked(false);
mLeftTrack->SetChannel(Track::MonoChannel); mLeftTrack->SetChannel(Track::MonoChannel);

View File

@ -1003,9 +1003,7 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
newTrack->InsertSilence(0.0, t0 - t1); newTrack->InsertSilence(0.0, t0 - t1);
newTrack->Flush(); newTrack->Flush();
wt->Clear(t1, t0); wt->Clear(t1, t0);
bool bResult = wt->Paste(t1, newTrack.get()); wt->Paste(t1, newTrack.get());
wxASSERT(bResult); // TO DO: Actually handle this.
wxUnusedVar(bResult);
} }
recordingTracks.push_back(wt); recordingTracks.push_back(wt);
// Don't record more channels than configured recording pref. // Don't record more channels than configured recording pref.