Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
WaveTrackShifter Class Referencefinal
Inheritance diagram for WaveTrackShifter:
[legend]
Collaboration diagram for WaveTrackShifter:
[legend]

Public Member Functions

 WaveTrackShifter (WaveTrack &track)
 
 ~WaveTrackShifter () override
 
TrackGetTrack () const override
 There is always an associated track. More...
 
HitTestResult HitTest (double time, const ViewInfo &viewInfo, HitTestParams *params) override
 Decide how shift behaves, based on the track that is clicked in. More...
 
void SelectInterval (const TrackInterval &interval) override
 Notifies the shifter that a region is selected, so it may update its fixed and moving intervals. More...
 
bool SyncLocks () override
 Whether unfixing of an interval should propagate to all overlapping intervals in the sync lock group. More...
 
bool MayMigrateTo (Track &other) override
 Whether intervals may migrate to the other track, not yet checking all placement constraints *‍/. More...
 
double HintOffsetLarger (double desiredOffset) override
 Given amount to shift by horizontally, maybe adjust it from zero to suggest minimum distance. More...
 
double QuantizeOffset (double desiredOffset) override
 Given amount to shift by horizontally, do any preferred rounding, before placement constraint checks. More...
 
double AdjustOffsetSmaller (double desiredOffset) override
 Given amount to shift by horizontally, maybe adjust it toward zero to meet placement constraints. More...
 
Intervals Detach () override
 Remove all moving intervals from the track, if possible. More...
 
bool AdjustFit (const Track &otherTrack, const Intervals &intervals, double &desiredOffset, double tolerance) override
 Test whether intervals can fit into another track, maybe adjusting the offset slightly. More...
 
bool Attach (Intervals intervals) override
 Put moving intervals into the track, which may have migrated from another. More...
 
bool FinishMigration () override
 When dragging is done, do (once) the final steps of migration (which may be expensive) More...
 
void DoHorizontalOffset (double offset) override
 
double AdjustT0 (double t0) const override
 
- Public Member Functions inherited from TrackShifter
 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
 

Private Attributes

std::shared_ptr< WaveTrackmpTrack
 
std::unordered_set< WaveClip * > mMigrated
 

Additional Inherited Members

- Public Types inherited from TrackShifter
enum class  HitTestResult { Miss , Selection , Intervals , Track }
 Possibilities for HitTest on the clicked track. More...
 
using Intervals = std::vector< TrackInterval >
 
- Protected Member Functions inherited from TrackShifter
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 inherited from TrackShifter
Intervals mFixed
 
Intervals mMoving
 

Detailed Description

Definition at line 12 of file WaveTrackShifter.cpp.

Constructor & Destructor Documentation

◆ WaveTrackShifter()

WaveTrackShifter::WaveTrackShifter ( WaveTrack track)
inline

Definition at line 14 of file WaveTrackShifter.cpp.

15 : mpTrack{ track.SharedPointer<WaveTrack>() }
16 {
18 }
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:298
void InitIntervals()
Derived class constructor can initialize all intervals reported by the track as fixed,...
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
std::shared_ptr< WaveTrack > mpTrack

References TrackShifter::InitIntervals().

Here is the call graph for this function:

◆ ~WaveTrackShifter()

WaveTrackShifter::~WaveTrackShifter ( )
inlineoverride

Definition at line 19 of file WaveTrackShifter.cpp.

19{}

Member Function Documentation

◆ AdjustFit()

bool WaveTrackShifter::AdjustFit ( const Track otherTrack,
const Intervals intervals,
double &  desiredOffset,
double  tolerance 
)
inlineoverridevirtual

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 from TrackShifter.

Definition at line 138 of file WaveTrackShifter.cpp.

141 {
142 bool ok = true;
143 auto pOtherWaveTrack = static_cast<const WaveTrack*>(&otherTrack);
144 for ( auto &interval: intervals ) {
145 auto pData =
146 static_cast<WaveTrack::IntervalData*>( interval.Extra() );
147 auto pClip = pData->GetClip().get();
148 ok = pOtherWaveTrack->CanInsertClip(
149 pClip, desiredOffset, tolerance );
150 if( !ok )
151 break;
152 }
153 return ok;
154 }
std::shared_ptr< const WaveClip > GetClip() const
Definition: WaveTrack.h:499

References WaveTrack::IntervalData::GetClip().

Here is the call graph for this function:

◆ AdjustOffsetSmaller()

double WaveTrackShifter::AdjustOffsetSmaller ( double  desiredOffset)
inlineoverridevirtual

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 from TrackShifter.

Definition at line 113 of file WaveTrackShifter.cpp.

114 {
115 std::vector< WaveClip * > movingClips;
116 for ( auto &interval : MovingIntervals() ) {
117 auto data =
118 static_cast<WaveTrack::IntervalData*>( interval.Extra() );
119 movingClips.push_back(data->GetClip().get());
120 }
121 double newAmount = 0;
122 (void) mpTrack->CanOffsetClips(movingClips, desiredOffset, &newAmount);
123 return newAmount;
124 }
const Intervals & MovingIntervals() const
Return special intervals of the track that may move.

References TrackShifter::MovingIntervals(), and mpTrack.

Here is the call graph for this function:

◆ AdjustT0()

double WaveTrackShifter::AdjustT0 ( double  t0) const
inlineoverridevirtual

Reimplemented from TrackShifter.

Definition at line 193 of file WaveTrackShifter.cpp.

194 {
195 if (MovingIntervals().empty())
196 return t0;
197 else {
198 auto data = static_cast<WaveTrack::IntervalData*>(MovingIntervals()[0].Extra());
199 auto& clip = data->GetClip();
200 if (t0 < clip->GetPlayStartTime())
201 t0 = clip->GetPlayStartTime();
202 if (t0 > clip->GetPlayEndTime())
203 t0 = clip->GetPlayEndTime();
204 }
205 return t0;
206 }

References WaveTrack::IntervalData::GetClip(), and TrackShifter::MovingIntervals().

Here is the call graph for this function:

◆ Attach()

bool WaveTrackShifter::Attach ( Intervals  intervals)
inlineoverridevirtual

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 from TrackShifter.

Definition at line 156 of file WaveTrackShifter.cpp.

157 {
158 for (auto &interval : intervals) {
159 auto pData = static_cast<WaveTrack::IntervalData*>( interval.Extra() );
160 auto pClip = pData->GetClip();
161 if ( !mpTrack->AddClip( pClip ) )
162 return false;
163 mMigrated.insert( pClip.get() );
164 mMoving.emplace_back( std::move( interval ) );
165 }
166 return true;
167 }
Intervals mMoving
std::unordered_set< WaveClip * > mMigrated

References WaveTrack::IntervalData::GetClip(), mMigrated, TrackShifter::mMoving, and mpTrack.

Here is the call graph for this function:

◆ Detach()

Intervals WaveTrackShifter::Detach ( )
inlineoverridevirtual

Remove all moving intervals from the track, if possible.

Default implementation does nothing

Reimplemented from TrackShifter.

Definition at line 126 of file WaveTrackShifter.cpp.

127 {
128 for ( auto &interval: mMoving ) {
129 auto pData = static_cast<WaveTrack::IntervalData*>( interval.Extra() );
130 auto pClip = pData->GetClip().get();
131 // interval will still hold the clip, so ignore the return:
132 (void) mpTrack->RemoveAndReturnClip(pClip);
133 mMigrated.erase(pClip);
134 }
135 return std::move( mMoving );
136 }

References WaveTrack::IntervalData::GetClip(), mMigrated, TrackShifter::mMoving, and mpTrack.

Here is the call graph for this function:

◆ DoHorizontalOffset()

void WaveTrackShifter::DoHorizontalOffset ( double  offset)
inlineoverridevirtual

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

Reimplemented from TrackShifter.

Definition at line 181 of file WaveTrackShifter.cpp.

182 {
183 for ( auto &interval : MovingIntervals() ) {
184 auto data =
185 static_cast<WaveTrack::IntervalData*>( interval.Extra() );
186 data->GetClip()->Offset( offset );
187 }
188 }

References WaveTrack::IntervalData::GetClip(), and TrackShifter::MovingIntervals().

Here is the call graph for this function:

◆ FinishMigration()

bool WaveTrackShifter::FinishMigration ( )
inlineoverridevirtual

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 from TrackShifter.

Definition at line 169 of file WaveTrackShifter.cpp.

170 {
171 auto rate = mpTrack->GetRate();
172 for (auto pClip : mMigrated) {
173 // Now that user has dropped the clip into a different track,
174 // make sure the sample rate matches the destination track.
175 pClip->Resample(rate);
176 pClip->MarkChanged();
177 }
178 return true;
179 }

References mMigrated, and mpTrack.

◆ GetTrack()

Track & WaveTrackShifter::GetTrack ( ) const
inlineoverridevirtual

There is always an associated track.

Implements TrackShifter.

Definition at line 20 of file WaveTrackShifter.cpp.

20{ return *mpTrack; }

References mpTrack.

◆ HintOffsetLarger()

double WaveTrackShifter::HintOffsetLarger ( double  desiredOffset)
inlineoverridevirtual

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 from TrackShifter.

Definition at line 92 of file WaveTrackShifter.cpp.

93 {
94 // set it to a sample point, and minimum of 1 sample point
95 bool positive = (desiredOffset > 0);
96 if (!positive)
97 desiredOffset *= -1;
98 double nSamples = rint(mpTrack->GetRate() * desiredOffset);
99 nSamples = std::max(nSamples, 1.0);
100 desiredOffset = nSamples / mpTrack->GetRate();
101 if (!positive)
102 desiredOffset *= -1;
103 return desiredOffset;
104 }

References mpTrack.

◆ HitTest()

HitTestResult WaveTrackShifter::HitTest ( double  time,
const ViewInfo viewInfo,
HitTestParams pParams 
)
inlineoverridevirtual

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

Implements TrackShifter.

Definition at line 22 of file WaveTrackShifter.cpp.

24 {
25 auto pClip = [&]() {
26 for (auto clip : mpTrack->GetClips())
27 {
28 if (params != nullptr)
29 {
31 *clip, viewInfo, params->rect,
32 { params->xx, params->yy }))
33 return clip;
34 }
35 else
36 {
37 // WithinPlayRegion misses first sample, which breaks moving
38 // "selected" clip. Probable WithinPlayRegion should be fixed
39 // instead?
40 if (clip->GetPlayStartTime() <= time && time < clip->GetPlayEndTime())
41 return clip;
42 }
43 }
44
45 return std::shared_ptr<WaveClip>{};
46 }();
47
48 if (!pClip)
50
51 auto t0 = viewInfo.selectedRegion.t0();
52 auto t1 = viewInfo.selectedRegion.t1();
53 if ( mpTrack->IsSelected() && time >= t0 && time < t1 ) {
54 // Unfix maybe many intervals (at least one because of test above)
55 SelectInterval({t0, t1});
57 }
58
59 // Select just one interval
60 UnfixIntervals( [&](const auto &interval){
61 return
62 static_cast<WaveTrack::IntervalData*>(interval.Extra())
63 ->GetClip() == pClip;
64 } );
65
67 }
EffectDistortionSettings params
Definition: Distortion.cpp:77
double t1() const
Definition: ViewInfo.h:36
double t0() const
Definition: ViewInfo.h:35
void UnfixIntervals(std::function< bool(const TrackInterval &) > pred)
Change intervals satisfying a predicate from fixed to moving.
@ Selection
Shift chosen intervals of this track; may shift other tracks' intervals.
@ Intervals
Shift intervals only of selected track and sister channels.
@ Miss
Don't shift anything.
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
void SelectInterval(const TrackInterval &interval) override
Notifies the shifter that a region is selected, so it may update its fixed and moving intervals.
static bool HitTest(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &rect, const wxPoint &pos)

References WaveTrack::IntervalData::GetClip(), WaveTrackView::HitTest(), TrackShifter::Intervals, TrackShifter::Miss, mpTrack, params, ViewInfo::selectedRegion, SelectInterval(), TrackShifter::Selection, NotifyingSelectedRegion::t0(), NotifyingSelectedRegion::t1(), and TrackShifter::UnfixIntervals().

Here is the call graph for this function:

◆ MayMigrateTo()

bool WaveTrackShifter::MayMigrateTo ( Track otherTrack)
inlineoverridevirtual

Whether intervals may migrate to the other track, not yet checking all placement constraints *‍/.

Default implementation returns false

Reimplemented from TrackShifter.

Definition at line 87 of file WaveTrackShifter.cpp.

88 {
90 }
bool CommonMayMigrateTo(Track &otherTrack)

References TrackShifter::CommonMayMigrateTo().

Here is the call graph for this function:

◆ QuantizeOffset()

double WaveTrackShifter::QuantizeOffset ( double  desiredOffset)
inlineoverridevirtual

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

Default implementation returns argument

Reimplemented from TrackShifter.

Definition at line 106 of file WaveTrackShifter.cpp.

107 {
108 const auto rate = mpTrack->GetRate();
109 // set it to a sample point
110 return rint(desiredOffset * rate) / rate;
111 }

References mpTrack.

◆ SelectInterval()

void WaveTrackShifter::SelectInterval ( const TrackInterval interval)
inlineoverridevirtual

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 from TrackShifter.

Definition at line 69 of file WaveTrackShifter.cpp.

70 {
71 UnfixIntervals( [&](auto &myInterval){
72 // Use a slightly different test from CommonSelectInterval, rounding times
73 // to exact samples according to the clip's rate
74 auto data =
75 static_cast<WaveTrack::IntervalData*>( myInterval.Extra() );
76 auto clip = data->GetClip().get();
77 const auto c0 = mpTrack->TimeToLongSamples(clip->GetPlayStartTime());
78 const auto c1 = mpTrack->TimeToLongSamples(clip->GetPlayEndTime());
79 return
80 mpTrack->TimeToLongSamples(interval.Start()) < c1 &&
81 mpTrack->TimeToLongSamples(interval.End()) > c0;
82 });
83 }
double Start() const
Definition: Track.h:193
double End() const
Definition: Track.h:194

References ConstTrackInterval::End(), WaveTrack::IntervalData::GetClip(), mpTrack, ConstTrackInterval::Start(), and TrackShifter::UnfixIntervals().

Referenced by HitTest().

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

◆ SyncLocks()

bool WaveTrackShifter::SyncLocks ( )
inlineoverridevirtual

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

Implements TrackShifter.

Definition at line 85 of file WaveTrackShifter.cpp.

85{ return true; }

Member Data Documentation

◆ mMigrated

std::unordered_set<WaveClip *> WaveTrackShifter::mMigrated
private

Definition at line 212 of file WaveTrackShifter.cpp.

Referenced by Attach(), Detach(), and FinishMigration().

◆ mpTrack

std::shared_ptr<WaveTrack> WaveTrackShifter::mpTrack
private

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