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 (TimeInterval 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
 
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
 
bool Attach (Intervals intervals, double offset) 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 &)=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 (TimeInterval 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
 

Private Attributes

const std::shared_ptr< WaveTrackmpTrack
 
std::vector< WaveTrack::IntervalHoldermMigrated
 

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< std::shared_ptr< ChannelGroupInterval > >
 
- Protected Member Functions inherited from TrackShifter
void CommonSelectInterval (TimeInterval 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 15 of file WaveTrackShifter.cpp.

Constructor & Destructor Documentation

◆ WaveTrackShifter()

WaveTrackShifter::WaveTrackShifter ( WaveTrack track)
inline

Definition at line 17 of file WaveTrackShifter.cpp.

18 : mpTrack{ track.SharedPointer<WaveTrack>() }
19 {
21 }
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:146
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:203
const std::shared_ptr< WaveTrack > mpTrack

References TrackShifter::InitIntervals().

Here is the call graph for this function:

◆ ~WaveTrackShifter()

WaveTrackShifter::~WaveTrackShifter ( )
inlineoverride

Definition at line 22 of file WaveTrackShifter.cpp.

22{}

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 133 of file WaveTrackShifter.cpp.

136 {
137 bool ok = true;
138 auto pOtherWaveTrack = static_cast<const WaveTrack*>(&otherTrack);
139 for (auto &interval: intervals) {
140 auto &data = static_cast<WaveTrack::Interval&>(*interval);
141 if (!(ok = pOtherWaveTrack->CanInsertClip(data, desiredOffset, tolerance)))
142 break;
143 }
144 return ok;
145 }
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:238

◆ 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 109 of file WaveTrackShifter.cpp.

110 {
111 std::vector<WaveTrack::Interval *> movingClips;
112 for (auto &interval : MovingIntervals()) {
113 auto &data = static_cast<WaveTrack::Interval&>(*interval);
114 movingClips.push_back(&data);
115 }
116 double newAmount = 0;
117 mpTrack->CanOffsetClips(movingClips, desiredOffset, &newAmount);
118 return newAmount;
119 }
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 182 of file WaveTrackShifter.cpp.

183 {
184 if (MovingIntervals().empty())
185 return t0;
186 else {
187 auto &clip =
188 static_cast<WaveTrack::Interval&>(*MovingIntervals()[0]);
189 t0 = std::clamp(t0, clip.GetPlayStartTime(), clip.GetPlayEndTime());
190 }
191 return t0;
192 }

References TrackShifter::MovingIntervals().

Here is the call graph for this function:

◆ Attach()

bool WaveTrackShifter::Attach ( Intervals  intervals,
double  offset 
)
inlineoverridevirtual

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

Definition at line 147 of file WaveTrackShifter.cpp.

148 {
149 for (auto interval : intervals) {
150 auto data = std::static_pointer_cast<WaveTrack::Interval>(interval);
151 mpTrack->InsertInterval(data, false);
152 mMigrated.push_back(data);
153 if (offset != .0)
154 data->ShiftBy(offset);
155 mMoving.emplace_back(std::move(interval));
156 }
157 return true;
158 }
Intervals mMoving
std::vector< WaveTrack::IntervalHolder > mMigrated

References mMigrated, TrackShifter::mMoving, and mpTrack.

◆ Detach()

Intervals WaveTrackShifter::Detach ( )
inlineoverridevirtual

Remove all moving intervals from the track, if possible.

Default implementation does nothing

Reimplemented from TrackShifter.

Definition at line 121 of file WaveTrackShifter.cpp.

122 {
123 for (auto &interval: mMoving) {
124 auto pClip = std::static_pointer_cast<WaveTrack::Interval>(interval);
125 mpTrack->RemoveInterval(pClip);
126 mMigrated.erase(
127 std::remove(mMigrated.begin(), mMigrated.end(), pClip),
128 mMigrated.end());
129 }
130 return std::move(mMoving);
131 }

References mMigrated, TrackShifter::mMoving, and mpTrack.

◆ 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 171 of file WaveTrackShifter.cpp.

172 {
173 for (auto &interval : MovingIntervals()) {
174 auto &clip = static_cast<WaveTrack::Interval&>(*interval);
175 clip.ShiftBy(offset);
176 }
177 }
void ShiftBy(double delta) noexcept
Definition: WaveClip.cpp:1898

References TrackShifter::MovingIntervals(), and WaveClip::ShiftBy().

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 160 of file WaveTrackShifter.cpp.

161 {
162 auto rate = mpTrack->GetRate();
163 for (auto pClip : mMigrated) {
164 // Now that user has dropped the clip into a different track,
165 // make sure the sample rate matches the destination track.
166 pClip->Resample(rate);
167 }
168 return true;
169 }

References mMigrated, and mpTrack.

◆ GetTrack()

Track & WaveTrackShifter::GetTrack ( ) const
inlineoverridevirtual

There is always an associated track.

Implements TrackShifter.

Definition at line 23 of file WaveTrackShifter.cpp.

23 {
24 return *mpTrack;
25 }

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 88 of file WaveTrackShifter.cpp.

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

References mpTrack, and staffpad::audio::simd::rint().

Here is the call graph for this function:

◆ 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 27 of file WaveTrackShifter.cpp.

29 {
30 const auto pClip = [&]() -> std::shared_ptr<WaveClip> {
31 for (auto clip : mpTrack->Intervals())
32 if ((
33 // y coordinates in this HitTest come from the third argument
34 // The channel of the interval is used only for times
36 *clip, viewInfo, params->rect, { params->xx, params->yy })
37 ) || (
38 // WithinPlayRegion misses first sample, which breaks moving
39 // "selected" clip. Probable WithinPlayRegion should be fixed
40 // instead?
41 clip->GetPlayStartTime() <= time &&
42 time < clip->GetPlayEndTime()
43 ))
44 return clip;
45 return {};
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 &interval == pClip.get();
62 });
63
65 }
EffectDistortionSettings params
double t1() const
Definition: ViewInfo.h:36
double t0() const
Definition: ViewInfo.h:35
void UnfixIntervals(std::function< bool(const ChannelGroupInterval &)> 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:216
static bool HitTest(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &rect, const wxPoint &pos)
void SelectInterval(TimeInterval interval) override
Notifies the shifter that a region is selected, so it may update its fixed and moving intervals.

References WaveChannelView::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 83 of file WaveTrackShifter.cpp.

84 {
86 }
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 102 of file WaveTrackShifter.cpp.

103 {
104 const auto rate = mpTrack->GetRate();
105 // set it to a sample point
106 return rint(desiredOffset * rate) / rate;
107 }

References mpTrack, and staffpad::audio::simd::rint().

Here is the call graph for this function:

◆ SelectInterval()

void WaveTrackShifter::SelectInterval ( TimeInterval  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 67 of file WaveTrackShifter.cpp.

68 {
69 UnfixIntervals([&](auto &myInterval){
70 // Use a slightly different test from CommonSelectInterval, rounding times
71 // to exact samples according to the clip's rate
72 auto &clip = static_cast<const WaveTrack::Interval&>(myInterval);
73 const auto c0 = mpTrack->TimeToLongSamples(clip.GetPlayStartTime());
74 const auto c1 = mpTrack->TimeToLongSamples(clip.GetPlayEndTime());
75 return
76 mpTrack->TimeToLongSamples(interval.Start()) < c1 &&
77 mpTrack->TimeToLongSamples(interval.End()) > c0;
78 });
79 }

References TrackShifter::TimeInterval::End(), mpTrack, TrackShifter::TimeInterval::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 81 of file WaveTrackShifter.cpp.

81{ return true; }

Member Data Documentation

◆ mMigrated

std::vector<WaveTrack::IntervalHolder> WaveTrackShifter::mMigrated
private

Definition at line 198 of file WaveTrackShifter.cpp.

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

◆ mpTrack

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

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