Audacity 3.2.0
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
TrackShifter Class Referenceabstract

Abstract base class for policies to manipulate a track type for Time Shift. More...

#include <TimeShiftHandle.h>

Inheritance diagram for TrackShifter:
[legend]
Collaboration diagram for TrackShifter:
[legend]

Classes

struct  HitTestParams
 Optional, more complete information for hit testing. More...
 

Public Types

enum class  HitTestResult { Miss , Selection , Intervals , Track }
 Possibilities for HitTest on the clicked track. More...
 
using Intervals = std::vector< std::shared_ptr< ChannelGroupInterval > >
 

Public Member Functions

 TrackShifter ()
 
 TrackShifter (const TrackShifter &)=delete
 
TrackShifteroperator= (const TrackShifter &)=delete
 
virtual ~TrackShifter ()=0
 
virtual TrackGetTrack () const =0
 There is always an associated track. More...
 
virtual HitTestResult HitTest (double time, const ViewInfo &viewInfo, HitTestParams *pParams=nullptr)=0
 Decide how shift behaves, based on the track that is clicked in. More...
 
const IntervalsFixedIntervals () const
 Return special intervals of the track that will not move. More...
 
const IntervalsMovingIntervals () const
 Return special intervals of the track that may move. More...
 
void UnfixIntervals (std::function< bool(const ChannelGroupInterval &)> pred)
 Change intervals satisfying a predicate from fixed to moving. More...
 
void UnfixAll ()
 Change all intervals from fixed to moving. More...
 
virtual void SelectInterval (const ChannelGroupInterval &interval)
 Notifies the shifter that a region is selected, so it may update its fixed and moving intervals. More...
 
virtual bool SyncLocks ()=0
 Whether unfixing of an interval should propagate to all overlapping intervals in the sync lock group. More...
 
virtual double HintOffsetLarger (double desiredOffset)
 Given amount to shift by horizontally, maybe adjust it from zero to suggest minimum distance. More...
 
virtual double QuantizeOffset (double desiredOffset)
 Given amount to shift by horizontally, do any preferred rounding, before placement constraint checks. More...
 
virtual double AdjustOffsetSmaller (double desiredOffset)
 Given amount to shift by horizontally, maybe adjust it toward zero to meet placement constraints. More...
 
virtual bool MayMigrateTo (Track &otherTrack)
 
virtual Intervals Detach ()
 Remove all moving intervals from the track, if possible. More...
 
virtual bool AdjustFit (const Track &otherTrack, const Intervals &intervals, double &desiredOffset, double tolerance)
 
virtual bool Attach (Intervals intervals, double offset)
 Put moving intervals into the track, which may have migrated from another. More...
 
virtual bool FinishMigration ()
 When dragging is done, do (once) the final steps of migration (which may be expensive) More...
 
virtual void DoHorizontalOffset (double offset)
 
virtual double AdjustT0 (double t0) const
 

Protected Member Functions

void CommonSelectInterval (const ChannelGroupInterval &interval)
 
bool CommonMayMigrateTo (Track &otherTrack)
 
void InitIntervals ()
 Derived class constructor can initialize all intervals reported by the track as fixed, none moving. More...
 
bool AllFixed () const
 

Protected Attributes

Intervals mFixed
 
Intervals mMoving
 

Private Attributes

bool mAllFixed = true
 

Detailed Description

Abstract base class for policies to manipulate a track type for Time Shift.

Definition at line 33 of file TimeShiftHandle.h.

Member Typedef Documentation

◆ Intervals

using TrackShifter::Intervals = std::vector<std::shared_ptr<ChannelGroupInterval> >

Definition at line 72 of file TimeShiftHandle.h.

Member Enumeration Documentation

◆ HitTestResult

enum class TrackShifter::HitTestResult
strong

Possibilities for HitTest on the clicked track.

Enumerator
Miss 

Don't shift anything.

Selection 

Shift chosen intervals of this track; may shift other tracks' intervals.

Intervals 

Shift intervals only of selected track and sister channels.

Track 

Shift selected track and sister channels only, as a whole.

Definition at line 47 of file TimeShiftHandle.h.

47 {
48 Miss,
49 Selection,
50 Intervals,
51 Track
52 };
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
std::vector< std::shared_ptr< ChannelGroupInterval > > Intervals

Constructor & Destructor Documentation

◆ TrackShifter() [1/2]

TrackShifter::TrackShifter ( )
default

◆ TrackShifter() [2/2]

TrackShifter::TrackShifter ( const TrackShifter )
delete

◆ ~TrackShifter()

TrackShifter::~TrackShifter ( )
pure virtualdefault

Member Function Documentation

◆ AdjustFit()

bool TrackShifter::AdjustFit ( const Track otherTrack,
const Intervals intervals,
double &  desiredOffset,
double  tolerance 
)
virtual

Test whether intervals can fit into another track, maybe adjusting the offset slightly

Default implementation does nothing and returns false

Parameters
intervalsAssume these came from Detach() and only after MayMigrateTo returned true for otherTrack
[in,out]desiredOffset
toleranceNonnegative ceiling for allowed changes in fabs(desiredOffset)

Reimplemented in LabelTrackShifter, and WaveTrackShifter.

Definition at line 219 of file TimeShiftHandle.cpp.

221{
222 return false;
223}

◆ AdjustOffsetSmaller()

double TrackShifter::AdjustOffsetSmaller ( double  desiredOffset)
virtual

Given amount to shift by horizontally, maybe adjust it toward zero to meet placement constraints.

Default implementation returns the argument

Postcondition
fabs(r) <= fabs(desiredOffset)
r * desiredOffset >= 0 (i.e. signs are not opposite)
(where r is return value)

Reimplemented in WaveTrackShifter.

Definition at line 185 of file TimeShiftHandle.cpp.

186{
187 return desiredOffset;
188}

◆ AdjustT0()

double TrackShifter::AdjustT0 ( double  t0) const
virtual

Reimplemented in NoteTrackShifter, and WaveTrackShifter.

Definition at line 241 of file TimeShiftHandle.cpp.

242{
243 return t0;
244}

◆ AllFixed()

bool TrackShifter::AllFixed ( ) const
inlineprotected

Definition at line 188 of file TimeShiftHandle.h.

188 {
189 return mAllFixed && mMoving.empty();
190 }
Intervals mMoving

Referenced by DoHorizontalOffset().

Here is the caller graph for this function:

◆ Attach()

bool TrackShifter::Attach ( Intervals  intervals,
double  offset 
)
virtual

Put moving intervals into the track, which may have migrated from another.

The ChannelGroupInterval objects pointed to by intervals will not be used again. The shifter should repopupate mMoving with new ChannelGroupInterval objects to reflect the new state of the track. In case of failure, track states are unspecified

Returns
success Default implementation does nothing and returns true

Reimplemented in LabelTrackShifter, and WaveTrackShifter.

Definition at line 225 of file TimeShiftHandle.cpp.

226{
227 return true;
228}

◆ CommonMayMigrateTo()

bool TrackShifter::CommonMayMigrateTo ( Track otherTrack)
protected

May be useful to override MayMigrateTo(), if certain other needed overrides are given. Returns true, iff: tracks have same type, and their channel groups have same width

Precondition
otherTrack.IsLeader()

Definition at line 195 of file TimeShiftHandle.cpp.

196{
197 assert(otherTrack.IsLeader());
198 auto &track = GetTrack();
199 // Both tracks need to be owned to decide this
200 auto pMyList = track.GetOwner().get();
201 auto pOtherList = otherTrack.GetOwner().get();
202 if (pMyList && pOtherList) {
203 // Can migrate to another track of the same kind...
204 if (otherTrack.SameKindAs(track)) {
205 // ... with the same number of channels
206 auto myChannels = track.Channels();
207 auto otherChannels = otherTrack.Channels();
208 return (myChannels.size() == otherChannels.size());
209 }
210 }
211 return false;
212}
IteratorRange< ChannelIterator< ChannelType > > Channels()
Get range of channels with mutative access.
Definition: Channel.h:408
bool SameKindAs(const Track &track) const
Definition: Track.h:428
std::shared_ptr< TrackList > GetOwner() const
Definition: Track.h:254
bool IsLeader() const override
Definition: Track.cpp:291
virtual Track & GetTrack() const =0
There is always an associated track.

References ChannelGroup::Channels(), Track::GetOwner(), GetTrack(), Track::IsLeader(), and Track::SameKindAs().

Referenced by WaveTrackShifter::MayMigrateTo(), and LabelTrackShifter::MayMigrateTo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CommonSelectInterval()

void TrackShifter::CommonSelectInterval ( const ChannelGroupInterval interval)
protected

Unfix any of the intervals that intersect the given one; may be useful to override SelectInterval()

Definition at line 167 of file TimeShiftHandle.cpp.

168{
169 UnfixIntervals( [&](auto &myInterval){
170 return !(interval.End() < myInterval.Start() ||
171 myInterval.End() < interval.Start());
172 });
173}
double End() const
Definition: Channel.h:42
double Start() const
Definition: Channel.h:41
void UnfixIntervals(std::function< bool(const ChannelGroupInterval &)> pred)
Change intervals satisfying a predicate from fixed to moving.

References ChannelGroupInterval::End(), ChannelGroupInterval::Start(), and UnfixIntervals().

Referenced by LabelTrackShifter::SelectInterval(), and NoteTrackShifter::SelectInterval().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Detach()

auto TrackShifter::Detach ( )
virtual

Remove all moving intervals from the track, if possible.

Default implementation does nothing

Reimplemented in LabelTrackShifter, and WaveTrackShifter.

Definition at line 214 of file TimeShiftHandle.cpp.

215{
216 return {};
217}

◆ DoHorizontalOffset()

void TrackShifter::DoHorizontalOffset ( double  offset)
virtual

Shift all moving intervals horizontally Default moves the whole track, provided !AllFixed(); else does nothing

Reimplemented in LabelTrackShifter, and WaveTrackShifter.

Definition at line 235 of file TimeShiftHandle.cpp.

236{
237 if (!AllFixed())
238 GetTrack().ShiftBy(offset);
239}
void ShiftBy(double t)
Change start time by given duration.
Definition: Channel.h:317
bool AllFixed() const

References AllFixed(), GetTrack(), and ChannelGroup::ShiftBy().

Here is the call graph for this function:

◆ FinishMigration()

bool TrackShifter::FinishMigration ( )
virtual

When dragging is done, do (once) the final steps of migration (which may be expensive)

Returns
success

In case of failure, track states are unspecified

Default implementation does nothing and returns true

Reimplemented in WaveTrackShifter.

Definition at line 230 of file TimeShiftHandle.cpp.

231{
232 return true;
233}

◆ FixedIntervals()

const Intervals & TrackShifter::FixedIntervals ( ) const
inline

Return special intervals of the track that will not move.

Definition at line 75 of file TimeShiftHandle.h.

75{ return mFixed; }
Intervals mFixed

◆ GetTrack()

virtual Track & TrackShifter::GetTrack ( ) const
pure virtual

There is always an associated track.

Postcondition
result: result.IsLeader()

Implemented in LabelTrackShifter, NoteTrackShifter, WaveTrackShifter, and CoarseTrackShifter.

Referenced by CommonMayMigrateTo(), DoHorizontalOffset(), and InitIntervals().

Here is the caller graph for this function:

◆ HintOffsetLarger()

double TrackShifter::HintOffsetLarger ( double  desiredOffset)
virtual

Given amount to shift by horizontally, maybe adjust it from zero to suggest minimum distance.

Any interval placement constraints, not necessarily met at the suggested offset Default implementation returns the argument

Postcondition
fabs(r) >= fabs(desiredOffset)
r * desiredOffset >= 0 (i.e. signs are not opposite)
(where r is return value)

Reimplemented in WaveTrackShifter.

Definition at line 175 of file TimeShiftHandle.cpp.

176{
177 return desiredOffset;
178}

◆ HitTest()

virtual HitTestResult TrackShifter::HitTest ( double  time,
const ViewInfo viewInfo,
HitTestParams pParams = nullptr 
)
pure virtual

Decide how shift behaves, based on the track that is clicked in.

If the return value is Intervals or Selection, then some intervals may be marked moving as a side effect

Precondition
!pParams || (time == pParams->viewInfo.PositionToTime(pParams->xx, pParams->rect.x))
Parameters
timeA time value to test
pParamsOptional extra information

Implemented in NoteTrackShifter, WaveTrackShifter, LabelTrackShifter, and CoarseTrackShifter.

◆ InitIntervals()

void TrackShifter::InitIntervals ( )
protected

Derived class constructor can initialize all intervals reported by the track as fixed, none moving.

This can't be called by the base class constructor, when GetTrack() isn't yet callable

Definition at line 246 of file TimeShiftHandle.cpp.

247{
248 auto &track = GetTrack();
249 assert(track.IsLeader()); // postcondition
250 mMoving.clear();
251 auto range = track.Intervals();
252 std::copy(range.begin(), range.end(), back_inserter(mFixed));
253}
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy(), GetTrack(), mFixed, and mMoving.

Referenced by CoarseTrackShifter::CoarseTrackShifter(), LabelTrackShifter::LabelTrackShifter(), NoteTrackShifter::NoteTrackShifter(), and WaveTrackShifter::WaveTrackShifter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MayMigrateTo()

bool TrackShifter::MayMigrateTo ( Track otherTrack)
virtual

Whether intervals may migrate to the other track, not yet checking all placement constraints

Precondition
otherTrack.IsLeader() Default implementation returns false

Reimplemented in WaveTrackShifter, and LabelTrackShifter.

Definition at line 190 of file TimeShiftHandle.cpp.

191{
192 return false;
193}

◆ MovingIntervals()

const Intervals & TrackShifter::MovingIntervals ( ) const
inline

Return special intervals of the track that may move.

Definition at line 78 of file TimeShiftHandle.h.

78{ return mMoving; }

Referenced by WaveTrackShifter::AdjustOffsetSmaller(), WaveTrackShifter::AdjustT0(), LabelTrackShifter::DoHorizontalOffset(), and WaveTrackShifter::DoHorizontalOffset().

Here is the caller graph for this function:

◆ operator=()

TrackShifter & TrackShifter::operator= ( const TrackShifter )
delete

◆ QuantizeOffset()

double TrackShifter::QuantizeOffset ( double  desiredOffset)
virtual

Given amount to shift by horizontally, do any preferred rounding, before placement constraint checks.

Default implementation returns argument

Reimplemented in WaveTrackShifter.

Definition at line 180 of file TimeShiftHandle.cpp.

181{
182 return desiredOffset;
183}

◆ SelectInterval()

void TrackShifter::SelectInterval ( const ChannelGroupInterval interval)
virtual

Notifies the shifter that a region is selected, so it may update its fixed and moving intervals.

Default behavior: if any part of the track is selected, unfix all parts of it.

Reimplemented in LabelTrackShifter, NoteTrackShifter, and WaveTrackShifter.

Definition at line 162 of file TimeShiftHandle.cpp.

163{
164 UnfixAll();
165}
void UnfixAll()
Change all intervals from fixed to moving.

References UnfixAll().

Here is the call graph for this function:

◆ SyncLocks()

virtual bool TrackShifter::SyncLocks ( )
pure virtual

Whether unfixing of an interval should propagate to all overlapping intervals in the sync lock group.

Implemented in LabelTrackShifter, NoteTrackShifter, WaveTrackShifter, and CoarseTrackShifter.

◆ UnfixAll()

void TrackShifter::UnfixAll ( )

Change all intervals from fixed to moving.

Definition at line 155 of file TimeShiftHandle.cpp.

156{
157 std::move(mFixed.begin(), mFixed.end(), std::back_inserter(mMoving));
158 mFixed = Intervals{};
159 mAllFixed = false;
160}

References mAllFixed, mFixed, and mMoving.

Referenced by NoteTrackShifter::HitTest(), and SelectInterval().

Here is the caller graph for this function:

◆ UnfixIntervals()

void TrackShifter::UnfixIntervals ( std::function< bool(const ChannelGroupInterval &)>  pred)

Change intervals satisfying a predicate from fixed to moving.

Definition at line 141 of file TimeShiftHandle.cpp.

143{
144 for (auto iter = mFixed.begin(); iter != mFixed.end();) {
145 if (pred(**iter)) {
146 mMoving.push_back(std::move(*iter));
147 iter = mFixed.erase(iter);
148 mAllFixed = false;
149 }
150 else
151 ++iter;
152 }
153}

References mAllFixed, mFixed, and mMoving.

Referenced by CommonSelectInterval(), WaveTrackShifter::HitTest(), LabelTrackShifter::HitTest(), and WaveTrackShifter::SelectInterval().

Here is the caller graph for this function:

Member Data Documentation

◆ mAllFixed

bool TrackShifter::mAllFixed = true
private

Becomes false after UnfixAll(), even if there are no intervals, or if any one interval was unfixed

Definition at line 196 of file TimeShiftHandle.h.

Referenced by UnfixAll(), and UnfixIntervals().

◆ mFixed

Intervals TrackShifter::mFixed
protected

◆ mMoving

Intervals TrackShifter::mMoving
protected

The documentation for this class was generated from the following files: