diff --git a/src/NoteTrack.cpp b/src/NoteTrack.cpp index 914a8f6c5..2b78d28da 100644 --- a/src/NoteTrack.cpp +++ b/src/NoteTrack.cpp @@ -534,6 +534,18 @@ bool NoteTrack::Paste(double t, const Track *src) return true; } +bool NoteTrack::Silence(double, double) +{ + // to do + return false; +} + +bool NoteTrack::InsertSilence(double, double) +{ + // to do + return false; +} + // Call this function to manipulate the underlying sequence data. This is // NOT the function that handles horizontal dragging. bool NoteTrack::Shift(double t) // t is always seconds diff --git a/src/NoteTrack.h b/src/NoteTrack.h index a314db574..3a62c50e0 100644 --- a/src/NoteTrack.h +++ b/src/NoteTrack.h @@ -105,6 +105,8 @@ class AUDACITY_DLL_API NoteTrack final bool Trim (double t0, double t1) /* not override */; bool Clear(double t0, double t1) override; bool Paste(double t, const Track *src) override; + bool Silence(double t0, double t1) override; + bool InsertSilence(double t, double len) override; bool Shift(double t) /* not override */; #ifdef EXPERIMENTAL_MIDI_OUT diff --git a/src/TimeTrack.cpp b/src/TimeTrack.cpp index 6f47af6f3..a552a1bce 100644 --- a/src/TimeTrack.cpp +++ b/src/TimeTrack.cpp @@ -63,20 +63,24 @@ TimeTrack::TimeTrack(const std::shared_ptr &projDirManager, const Zo blankPen.SetColour(214, 214, 214); } -TimeTrack::TimeTrack(const TimeTrack &orig): - Track(orig) +TimeTrack::TimeTrack(const TimeTrack &orig, double *pT0, double *pT1) + : Track(orig) , mZoomInfo(orig.mZoomInfo) { Init(orig); // this copies the TimeTrack metadata (name, range, etc) ///@TODO: Give Envelope:: a copy-constructor instead of this? mEnvelope = std::make_unique(); + mEnvelope->Flatten(1.0); mEnvelope->SetTrackLen(DBL_MAX); SetInterpolateLog(orig.GetInterpolateLog()); // this calls Envelope::SetInterpolateDB - mEnvelope->Flatten(1.0); mEnvelope->SetOffset(0); mEnvelope->SetRange(orig.mEnvelope->GetMinValue(), orig.mEnvelope->GetMaxValue()); - mEnvelope->Paste(0.0, orig.mEnvelope.get()); + if ( pT0 && pT1 ) + // restricted copy + mEnvelope->CopyFrom(orig.mEnvelope.get(), *pT0, *pT1); + else + mEnvelope->Paste(0.0, orig.mEnvelope.get()); ///@TODO: Give Ruler:: a copy-constructor instead of this? mRuler = std::make_unique(); @@ -103,6 +107,45 @@ TimeTrack::~TimeTrack() { } +Track::Holder TimeTrack::Cut( double t0, double t1 ) +{ + auto result = Copy( t0, t1, false ); + Clear( t0, t1 ); + return result; +} + +Track::Holder TimeTrack::Copy( double t0, double t1, bool ) const +{ + auto result = std::make_unique( *this, &t0, &t1 ); + return Track::Holder{ std::move( result ) }; +} + +bool TimeTrack::Clear(double t0, double t1) +{ + mEnvelope->CollapseRegion(t0, t1); + return true; +} + +bool TimeTrack::Paste(double t, const Track * src) +{ + if (src->GetKind() != Track::Time) + return false; + + mEnvelope->Paste(t, static_cast(src)->mEnvelope.get()); + return true; +} + +bool TimeTrack::Silence(double t0, double t1) +{ + return true; +} + +bool TimeTrack::InsertSilence(double t, double len) +{ + mEnvelope->InsertSpace(t, len); + return true; +} + Track::Holder TimeTrack::Duplicate() const { return std::make_unique(*this); diff --git a/src/TimeTrack.h b/src/TimeTrack.h index 03aa29860..16e8743c7 100644 --- a/src/TimeTrack.h +++ b/src/TimeTrack.h @@ -34,11 +34,20 @@ class TimeTrack final : public Track { * Envelope:: and Ruler:: members in order to copy one to the other - unfortunately both lack a * copy-constructor to encapsulate this. * @param orig The original track to copy from + * @param pT0 if not null, then the start of the sub-range to copy + * @param pT1 if not null, then the end of the sub-range to copy */ - TimeTrack(const TimeTrack &orig); + TimeTrack(const TimeTrack &orig, double *pT0 = nullptr, double *pT1 = nullptr); virtual ~TimeTrack(); + Holder Cut( double t0, double t1 ) override; + Holder Copy( double t0, double t1, bool forClipboard ) const override; + bool Clear(double t0, double t1) override; + bool Paste(double t, const Track * src) override; + bool Silence(double t0, double t1) override; + bool InsertSilence(double t, double len) override; + // Identifying the type of track int GetKind() const override { return Time; } diff --git a/src/Track.h b/src/Track.h index 2b74e076d..334efeb41 100644 --- a/src/Track.h +++ b/src/Track.h @@ -206,28 +206,29 @@ class AUDACITY_DLL_API Track /* not final */ : public XMLTagHandler // separate from the Track. const std::shared_ptr &GetDirManager() const { return mDirManager; } - // Create a NEW track and modify this track (or return null for failure) - virtual Holder Cut(double WXUNUSED(t0), double WXUNUSED(t1)) { return{}; } + // Create a NEW track and modify this track + // Return non-NULL or else throw + virtual Holder Cut(double WXUNUSED(t0), double WXUNUSED(t1)) = 0; - // Create a NEW track and don't modify this track (or return null for failure) + // Create a NEW track and don't modify this track + // Return non-NULL or else throw // Note that subclasses may want to distinguish tracks stored in a clipboard // from those stored in a project virtual Holder Copy - (double WXUNUSED(t0), double WXUNUSED(t1), bool forClipboard = true) const - { return{}; } + (double WXUNUSED(t0), double WXUNUSED(t1), bool forClipboard = true) const = 0; // Return true for success - virtual bool Clear(double WXUNUSED(t0), double WXUNUSED(t1)) {return false;} + virtual bool Clear(double WXUNUSED(t0), double WXUNUSED(t1)) = 0; // Return true for success - virtual bool Paste(double WXUNUSED(t), const Track * WXUNUSED(src)) {return false;} + 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 // is replaced by one of a different length. virtual bool SyncLockAdjust(double oldT1, double newT1); - virtual bool Silence(double WXUNUSED(t0), double WXUNUSED(t1)) {return false;} - virtual bool InsertSilence(double WXUNUSED(t), double WXUNUSED(len)) {return false;} + virtual bool Silence(double WXUNUSED(t0), double WXUNUSED(t1)) = 0; + virtual bool InsertSilence(double WXUNUSED(t), double WXUNUSED(len)) = 0; virtual int GetKind() const { return None; }