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 with the Time Shift tool. 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< TrackInterval >
 

Public Member Functions

 TrackShifter ()
 
 TrackShifter (const TrackShifter &) PROHIBITED
 
TrackShifteroperator= (const TrackShifter &) PROHIBITED
 
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 TrackInterval &) > 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 TrackInterval &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)
 Whether intervals may migrate to the other track, not yet checking all placement constraints *‍/. More...
 
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)
 Test whether intervals can fit into another track, maybe adjusting the offset slightly. More...
 
virtual bool Attach (Intervals intervals)
 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 TrackInterval &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 with the Time Shift tool.

Definition at line 33 of file TimeShiftHandle.h.

Member Typedef Documentation

◆ Intervals

using TrackShifter::Intervals = std::vector<TrackInterval>

Definition at line 69 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 44 of file TimeShiftHandle.h.

44 {
45 Miss,
46 Selection,
47 Intervals,
48 Track
49 };
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
std::vector< TrackInterval > Intervals

Constructor & Destructor Documentation

◆ TrackShifter() [1/2]

TrackShifter::TrackShifter ( )
default

◆ TrackShifter() [2/2]

TrackShifter::TrackShifter ( const TrackShifter )

◆ ~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 224 of file TimeShiftHandle.cpp.

226{
227 return false;
228}

◆ 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 178 of file TimeShiftHandle.cpp.

179{
180 return desiredOffset;
181}

◆ AdjustT0()

double TrackShifter::AdjustT0 ( double  t0) const
virtual

Reimplemented in NoteTrackShifter, and WaveTrackShifter.

Definition at line 246 of file TimeShiftHandle.cpp.

247{
248 return t0;
249}

◆ AllFixed()

bool TrackShifter::AllFixed ( ) const
inlineprotected

Definition at line 170 of file TimeShiftHandle.h.

170 {
171 return mAllFixed && mMoving.empty();
172 }
Intervals mMoving

Referenced by DoHorizontalOffset().

Here is the caller graph for this function:

◆ Attach()

bool TrackShifter::Attach ( Intervals  intervals)
virtual

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

Returns
success

In case of failure, track states are unspecified

Default implementation does nothing and returns true

Reimplemented in LabelTrackShifter, and WaveTrackShifter.

Definition at line 230 of file TimeShiftHandle.cpp.

231{
232 return true;
233}

◆ 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 corresponding positions in their channel groups, which have same size

Definition at line 188 of file TimeShiftHandle.cpp.

189{
190 auto &track = GetTrack();
191
192 // Both tracks need to be owned to decide this
193 auto pMyList = track.GetOwner().get();
194 auto pOtherList = otherTrack.GetOwner().get();
195 if (pMyList && pOtherList) {
196
197 // Can migrate to another track of the same kind...
198 if ( otherTrack.SameKindAs( track ) ) {
199
200 // ... with the same number of channels ...
201 auto myChannels = TrackList::Channels( &track );
202 auto otherChannels = TrackList::Channels( &otherTrack );
203 if (myChannels.size() == otherChannels.size()) {
204
205 // ... and where this track and the other have corresponding
206 // positions
207 return myChannels.size() == 1 ||
208 std::distance(myChannels.first, pMyList->Find(&track)) ==
209 std::distance(otherChannels.first, pOtherList->Find(&otherTrack));
210
211 }
212
213 }
214
215 }
216 return false;
217}
bool SameKindAs(const Track &track) const
Definition: Track.h:534
std::shared_ptr< TrackList > GetOwner() const
Definition: Track.h:409
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1541
virtual Track & GetTrack() const =0
There is always an associated track.

References TrackList::Channels(), Track::GetOwner(), GetTrack(), 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 TrackInterval interval)
protected

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

Definition at line 160 of file TimeShiftHandle.cpp.

161{
162 UnfixIntervals( [&](auto &myInterval){
163 return !(interval.End() < myInterval.Start() ||
164 myInterval.End() < interval.Start());
165 });
166}
double Start() const
Definition: Track.h:192
double End() const
Definition: Track.h:193
void UnfixIntervals(std::function< bool(const TrackInterval &) > pred)
Change intervals satisfying a predicate from fixed to moving.

References ConstTrackInterval::End(), ConstTrackInterval::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 219 of file TimeShiftHandle.cpp.

220{
221 return {};
222}

◆ 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 240 of file TimeShiftHandle.cpp.

241{
242 if (!AllFixed())
243 GetTrack().Offset( offset );
244}
void Offset(double t)
Definition: Track.h:482
bool AllFixed() const

References AllFixed(), GetTrack(), and Track::Offset().

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 235 of file TimeShiftHandle.cpp.

236{
237 return true;
238}

◆ FixedIntervals()

const Intervals & TrackShifter::FixedIntervals ( ) const
inline

Return special intervals of the track that will not move.

Definition at line 72 of file TimeShiftHandle.h.

72{ return mFixed; }
Intervals mFixed

◆ GetTrack()

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

There is always an associated track.

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 168 of file TimeShiftHandle.cpp.

169{
170 return desiredOffset;
171}

◆ 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 251 of file TimeShiftHandle.cpp.

252{
253 mMoving.clear();
255}
virtual ConstIntervals GetIntervals() const
Report times on the track where important intervals begin and end, for UI to snap to.
Definition: Track.cpp:1263

References Track::GetIntervals(), 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 *‍/.

Default implementation returns false

Reimplemented in WaveTrackShifter, and LabelTrackShifter.

Definition at line 183 of file TimeShiftHandle.cpp.

184{
185 return false;
186}

◆ MovingIntervals()

const Intervals & TrackShifter::MovingIntervals ( ) const
inline

Return special intervals of the track that may move.

Definition at line 75 of file TimeShiftHandle.h.

75{ 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 )

◆ 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 173 of file TimeShiftHandle.cpp.

174{
175 return desiredOffset;
176}

◆ SelectInterval()

void TrackShifter::SelectInterval ( const TrackInterval 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 155 of file TimeShiftHandle.cpp.

156{
157 UnfixAll();
158}
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 148 of file TimeShiftHandle.cpp.

149{
150 std::move( mFixed.begin(), mFixed.end(), std::back_inserter(mMoving) );
151 mFixed = Intervals{};
152 mAllFixed = false;
153}

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 TrackInterval &) >  pred)

Change intervals satisfying a predicate from fixed to moving.

Definition at line 134 of file TimeShiftHandle.cpp.

136{
137 for ( auto iter = mFixed.begin(); iter != mFixed.end(); ) {
138 if ( pred( *iter) ) {
139 mMoving.push_back( std::move( *iter ) );
140 iter = mFixed.erase( iter );
141 mAllFixed = false;
142 }
143 else
144 ++iter;
145 }
146}

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 178 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: