1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 00:20:06 +02:00

Separate Track::Clone (protected virtual) from Track::Duplicate

This commit is contained in:
Paul Licameli 2018-11-18 20:15:26 -05:00
parent b4c7a8ef2a
commit 79191d985d
10 changed files with 34 additions and 11 deletions

View File

@ -1171,7 +1171,7 @@ double LabelTrack::GetEndTime() const
return end;
}
Track::Holder LabelTrack::Duplicate() const
Track::Holder LabelTrack::Clone() const
{
return std::make_shared<LabelTrack>( *this );
}

View File

@ -156,8 +156,11 @@ class AUDACITY_DLL_API LabelTrack final : public Track
double GetEndTime() const override;
using Holder = std::shared_ptr<LabelTrack>;
Track::Holder Duplicate() const override;
private:
Track::Holder Clone() const override;
public:
void SetSelected(bool s) override;
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;

View File

@ -163,7 +163,7 @@ Alg_seq &NoteTrack::GetSeq() const
return *mSeq;
}
Track::Holder NoteTrack::Duplicate() const
Track::Holder NoteTrack::Clone() const
{
auto duplicate = std::make_shared<NoteTrack>(mDirManager);
duplicate->Init(*this);
@ -925,7 +925,7 @@ void NoteTrack::WriteXML(XMLWriter &xmlFile) const
if (!mSeq) {
// replace saveme with an (unserialized) duplicate, which is
// destroyed at end of function.
holder = Duplicate();
holder = Clone();
saveme = static_cast<NoteTrack*>(holder.get());
}
saveme->GetSeq().write(data, true);

View File

@ -67,7 +67,7 @@ class StretchHandle;
class AUDACITY_DLL_API NoteTrack final
: public NoteTrackBase
{
public:
public:
NoteTrack(const std::shared_ptr<DirManager> &projDirManager);
virtual ~NoteTrack();
@ -77,8 +77,11 @@ class AUDACITY_DLL_API NoteTrack final
override;
using Holder = std::shared_ptr<NoteTrack>;
Track::Holder Duplicate() const override;
private:
Track::Holder Clone() const override;
public:
double GetOffset() const override;
double GetStartTime() const override;
double GetEndTime() const override;

View File

@ -177,7 +177,7 @@ void TimeTrack::InsertSilence(double t, double len)
mEnvelope->InsertSpace(t, len);
}
Track::Holder TimeTrack::Duplicate() const
Track::Holder TimeTrack::Clone() const
{
return std::make_shared<TimeTrack>(*this);
}

View File

@ -118,7 +118,9 @@ class TimeTrack final : public Track {
void Init(const TimeTrack &orig);
using Holder = std::unique_ptr<TimeTrack>;
Track::Holder Duplicate() const override;
private:
Track::Holder Clone() const override;
friend class TrackFactory;

View File

@ -115,6 +115,16 @@ void Track::Merge(const Track &orig)
mSelected = orig.mSelected;
}
Track::Holder Track::Duplicate() const
{
// invoke "virtual constructor" to copy track object proper:
auto result = Clone();
// other steps to be added here
return result;
}
Track::~Track()
{
}

View File

@ -370,7 +370,8 @@ private:
void Init(const Track &orig);
using Holder = std::shared_ptr<Track>;
virtual Holder Duplicate() const = 0;
// public nonvirtual duplication function that invokes Clone():
virtual Holder Duplicate() const;
// Called when this track is merged to stereo with another, and should
// take on some paramaters of its partner.
@ -431,6 +432,10 @@ public:
virtual void InsertSilence(double WXUNUSED(t), double WXUNUSED(len)) = 0;
private:
// Subclass responsibility implements only a part of Duplicate(), copying
// the track data proper (not associated data such as for groups and views):
virtual Holder Clone() const = 0;
virtual TrackKind GetKind() const { return TrackKind::None; }
template<typename T>

View File

@ -401,7 +401,7 @@ int WaveTrack::ZeroLevelYCoordinate(wxRect rect) const
(int)((mDisplayMax / (mDisplayMax - mDisplayMin)) * rect.height);
}
Track::Holder WaveTrack::Duplicate() const
Track::Holder WaveTrack::Clone() const
{
return std::make_shared<WaveTrack>( *this );
}

View File

@ -95,7 +95,7 @@ public:
private:
void Init(const WaveTrack &orig);
Track::Holder Duplicate() const override;
Track::Holder Clone() const override;
friend class TrackFactory;