1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-18 09:37:40 +02:00

Track duplication methods return unique_ptr, although some callers...

... simply release() them for now.
This commit is contained in:
Paul Licameli 2016-03-02 14:37:47 -05:00
parent 5162ab5c5b
commit f42a953752
14 changed files with 39 additions and 33 deletions

View File

@ -1136,9 +1136,9 @@ double LabelTrack::GetEndTime() const
return end;
}
Track *LabelTrack::Duplicate() const
Track::Holder LabelTrack::Duplicate() const
{
return new LabelTrack(*this);
return std::make_unique<LabelTrack>( *this );
}
void LabelTrack::SetSelected(bool s)

View File

@ -139,7 +139,8 @@ class AUDACITY_DLL_API LabelTrack final : public Track
double GetStartTime() const override;
double GetEndTime() const override;
Track *Duplicate() const override;
using Holder = std::unique_ptr<LabelTrack>;
Track::Holder Duplicate() const override;
void SetSelected(bool s) override;

View File

@ -135,9 +135,9 @@ NoteTrack::~NoteTrack()
}
}
Track *NoteTrack::Duplicate() const
Track::Holder NoteTrack::Duplicate() const
{
NoteTrack *duplicate = new NoteTrack(mDirManager);
auto duplicate = std::make_unique<NoteTrack>(mDirManager);
duplicate->Init(*this);
// Duplicate on NoteTrack moves data from mSeq to mSerializationBuffer
// and from mSerializationBuffer to mSeq on alternate calls. Duplicate
@ -169,7 +169,7 @@ Track *NoteTrack::Duplicate() const
#ifdef EXPERIMENTAL_MIDI_OUT
duplicate->SetGain(GetGain());
#endif
return duplicate;
return std::move(duplicate);
}
@ -196,10 +196,10 @@ void NoteTrack::WarpAndTransposeNotes(double t0, double t1,
// Since this is a duplicate and duplicates convert mSeq to
// a text string for saving as XML, we probably have to
// duplicate again to get back an mSeq
NoteTrack *nt = this;
double offset = nt->GetOffset(); // track is shifted this amount
double offset = this->GetOffset(); // track is shifted this amount
if (!mSeq) { // replace saveme with an (unserialized) duplicate
nt = (NoteTrack *) this->Duplicate();
Track::Holder unt{ Duplicate() };
const auto nt = static_cast<NoteTrack*>(unt.get());
wxASSERT(!mSeq && nt->mSeq && !nt->mSerializationBuffer);
// swap mSeq and Buffer between this and nt
nt->mSerializationBuffer = mSerializationBuffer;
@ -208,7 +208,6 @@ void NoteTrack::WarpAndTransposeNotes(double t0, double t1,
mSerializationLength = 0;
mSeq = nt->mSeq;
nt->mSeq = NULL;
delete nt; // delete the duplicate
}
mSeq->convert_to_seconds(); // make sure time units are right
t1 -= offset; // adjust time range to compensate for track offset
@ -821,9 +820,11 @@ void NoteTrack::WriteXML(XMLWriter &xmlFile)
// NoteTrack.) In this case, mSeq will be NULL. To avoid a crash
// and perform WriteXML, we may need to restore NoteTracks from binary
// blobs to regular data structures (with an Alg_seq member).
Track::Holder holder;
NoteTrack *saveme = this;
if (!mSeq) { // replace saveme with an (unserialized) duplicate
saveme = (NoteTrack *) this->Duplicate();
holder = Duplicate();
saveme = static_cast<NoteTrack*>(holder.get());
assert(saveme->mSeq);
}
saveme->mSeq->write(data, true);
@ -841,9 +842,6 @@ void NoteTrack::WriteXML(XMLWriter &xmlFile)
xmlFile.WriteAttr(wxT("bottomnote"), saveme->mBottomNote);
xmlFile.WriteAttr(wxT("data"), wxString(data.str().c_str(), wxConvUTF8));
xmlFile.EndTag(wxT("notetrack"));
if (this != saveme) {
delete saveme; // DELETE the duplicate
}
}
void NoteTrack::StartVScroll()

View File

@ -57,7 +57,8 @@ class AUDACITY_DLL_API NoteTrack final : public Track {
NoteTrack(DirManager * projDirManager);
virtual ~NoteTrack();
Track *Duplicate() const override;
using Holder = std::unique_ptr<NoteTrack>;
Track::Holder Duplicate() const override;
int GetKind() const override { return Note; }

View File

@ -2751,7 +2751,7 @@ void AudacityProject::OpenFile(const wxString &fileNameArg, bool addtohistory)
}
}
mLastSavedTracks->Add(t->Duplicate());
mLastSavedTracks->Add(t->Duplicate().release());
t = iter.Next();
}
@ -3549,7 +3549,7 @@ bool AudacityProject::Save(bool overwrite /* = true */ ,
Track *t = iter.First();
Track *dupT;
while (t) {
dupT = t->Duplicate();
dupT = t->Duplicate().release();
mLastSavedTracks->Add(dupT);
//only after the xml has been saved we can mark it saved.
@ -4066,8 +4066,7 @@ void AudacityProject::PopState(const UndoState &state)
while (t)
{
copyTrack=t->Duplicate();
mTracks->Add(copyTrack);
mTracks->Add(copyTrack = t->Duplicate().release());
//add the track to OD if the manager exists. later we might do a more rigorous check...
if (copyTrack->GetKind() == Track::Wave)

View File

@ -109,9 +109,9 @@ TimeTrack::~TimeTrack()
delete mRuler;
}
Track *TimeTrack::Duplicate() const
Track::Holder TimeTrack::Duplicate() const
{
return new TimeTrack(*this);
return std::make_unique<TimeTrack>(*this);
}
bool TimeTrack::GetInterpolateLog() const

View File

@ -132,7 +132,9 @@ class TimeTrack final : public Track {
* @param orig the TimeTrack to copy from
*/
void Init(const TimeTrack &orig);
Track *Duplicate() const override;
using Holder = std::unique_ptr<TimeTrack>;
Track::Holder Duplicate() const override;
friend class TrackFactory;

View File

@ -746,7 +746,7 @@ void TrackList::DoAssign(const TrackList &that)
mDestructorDeletesTracks = true;
TrackListConstIterator it(&that);
for (const Track *track = it.First(); track; track = it.Next())
Add(track->Duplicate());
Add(track->Duplicate().release());
}
void TrackList::Swap(TrackList &that)

View File

@ -165,7 +165,9 @@ class AUDACITY_DLL_API Track /* not final */ : public XMLTagHandler
virtual ~ Track();
void Init(const Track &orig);
virtual Track *Duplicate() const = 0;
using Holder = std::unique_ptr<Track>;
virtual Holder Duplicate() const = 0;
// Called when this track is merged to stereo with another, and should
// take on some paramaters of its partner.

View File

@ -214,7 +214,7 @@ void UndoManager::ModifyState(const TrackList * l,
TrackListConstIterator iter(l);
const Track *t = iter.First();
while (t) {
tracksCopy->Add(t->Duplicate());
tracksCopy->Add(t->Duplicate().release());
t = iter.Next();
}
@ -259,7 +259,7 @@ void UndoManager::PushState(const TrackList * l,
TrackListConstIterator iter(l);
const Track *t = iter.First();
while (t) {
tracksCopy->Add(t->Duplicate());
tracksCopy->Add(t->Duplicate().release());
t = iter.Next();
}

View File

@ -65,7 +65,7 @@ bool WaveTrack::mMonoAsVirtualStereo;
WaveTrack* TrackFactory::DuplicateWaveTrack(WaveTrack &orig)
{
return (WaveTrack*)(orig.Duplicate());
return (WaveTrack*)(orig.Duplicate().release());
}
@ -355,9 +355,9 @@ void WaveTrack::SetSpectrumBounds(float min, float max) const
mSpectrumMax = max;
}
Track *WaveTrack::Duplicate() const
Track::Holder WaveTrack::Duplicate() const
{
return new WaveTrack(*this);
return Track::Holder{ safenew WaveTrack{ *this } };
}
double WaveTrack::GetRate() const

View File

@ -75,7 +75,9 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
WaveTrack(const WaveTrack &orig);
void Init(const WaveTrack &orig);
virtual Track *Duplicate() const override;
Track::Holder Duplicate() const override;
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
void VirtualStereoInit();
#endif
@ -87,6 +89,7 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
#endif
typedef WaveTrackLocation Location;
using Holder = std::unique_ptr<WaveTrack>;
virtual ~WaveTrack();
double GetOffset() const override;

View File

@ -2117,7 +2117,7 @@ void Effect::CopyInputTracks(int trackType)
if (aTrack->GetSelected() ||
(trackType == Track::All && aTrack->IsSyncLockSelected()))
{
Track *o = aTrack->Duplicate();
Track *o = aTrack->Duplicate().release();
mOutputTracks->Add(o);
mIMap.Add(aTrack);
mOMap.Add(o);

View File

@ -1098,11 +1098,11 @@ void ControlToolBar::SetupCutPreviewTracks(double WXUNUSED(playStart), double cu
if (track1)
{
// Duplicate and change tracks
track1 = track1->Duplicate();
track1 = track1->Duplicate().release();
track1->Clear(cutStart, cutEnd);
if (track2)
{
track2 = track2->Duplicate();
track2 = track2->Duplicate().release();
track2->Clear(cutStart, cutEnd);
}