6#include "../../../ui/TimeShiftHandle.h"
26 for (
auto clip :
mpTrack->GetClips())
31 *clip, viewInfo,
params->rect,
32 { params->xx, params->yy }))
40 if (clip->GetPlayStartTime() <= time && time < clip->GetPlayEndTime())
45 return std::shared_ptr<WaveClip>{};
53 if (
mpTrack->IsSelected() && time >= t0 && time < t1 ) {
76 auto clip = data->
GetClip().get();
77 const auto c0 =
mpTrack->TimeToLongSamples(clip->GetPlayStartTime());
78 const auto c1 =
mpTrack->TimeToLongSamples(clip->GetPlayEndTime());
81 mpTrack->TimeToLongSamples(interval.
End()) > c0;
95 bool positive = (desiredOffset > 0);
98 double nSamples = rint(
mpTrack->GetRate() * desiredOffset);
99 nSamples = std::max(nSamples, 1.0);
100 desiredOffset = nSamples /
mpTrack->GetRate();
103 return desiredOffset;
108 const auto rate =
mpTrack->GetRate();
110 return rint(desiredOffset * rate) / rate;
115 std::vector< WaveClip * > movingClips;
119 movingClips.push_back(data->GetClip().get());
121 double newAmount = 0;
122 (void)
mpTrack->CanOffsetClips(movingClips, desiredOffset, &newAmount);
128 for (
auto &interval:
mMoving ) {
130 auto pClip = pData->
GetClip().get();
132 (void)
mpTrack->RemoveAndReturnClip(pClip);
140 double &desiredOffset,
double tolerance)
override
143 auto pOtherWaveTrack =
static_cast<const WaveTrack*
>(&otherTrack);
144 for (
auto &interval: intervals ) {
147 auto pClip = pData->
GetClip().get();
148 ok = pOtherWaveTrack->CanInsertClip(
149 pClip, desiredOffset, tolerance );
158 for (
auto &interval : intervals) {
161 if ( !
mpTrack->AddClip( pClip ) )
164 mMoving.emplace_back( std::move( interval ) );
171 auto rate =
mpTrack->GetRate();
175 pClip->Resample(rate);
176 pClip->MarkChanged();
186 data->
GetClip()->Offset( offset );
200 if (t0 < clip->GetPlayStartTime())
201 t0 = clip->GetPlayStartTime();
202 if (t0 > clip->GetPlayEndTime())
203 t0 = clip->GetPlayEndTime();
218 return std::make_unique<WaveTrackShifter>(track);
EffectDistortionSettings params
DEFINE_ATTACHED_VIRTUAL_OVERRIDE(MakeWaveTrackShifter)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Abstract base class for an object holding data associated with points on a time axis.
A start and an end time, and mutative access to optional extra information.
Abstract base class for policies to manipulate a track type with the Time Shift tool.
std::vector< TrackInterval > Intervals
void UnfixIntervals(std::function< bool(const TrackInterval &) > pred)
Change intervals satisfying a predicate from fixed to moving.
void InitIntervals()
Derived class constructor can initialize all intervals reported by the track as fixed,...
const Intervals & MovingIntervals() const
Return special intervals of the track that may move.
bool CommonMayMigrateTo(Track &otherTrack)
HitTestResult
Possibilities for HitTest on the clicked track.
@ 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
std::shared_ptr< const WaveClip > GetClip() const
A Track that contains audio waveform data.
Intervals Detach() override
Remove all moving intervals from the track, if possible.
double AdjustT0(double t0) const override
bool SyncLocks() override
Whether unfixing of an interval should propagate to all overlapping intervals in the sync lock group.
bool FinishMigration() override
When dragging is done, do (once) the final steps of migration (which may be expensive)
~WaveTrackShifter() override
double AdjustOffsetSmaller(double desiredOffset) override
Given amount to shift by horizontally, maybe adjust it toward zero to meet placement constraints.
void SelectInterval(const TrackInterval &interval) override
Notifies the shifter that a region is selected, so it may update its fixed and moving intervals.
bool MayMigrateTo(Track &other) override
Whether intervals may migrate to the other track, not yet checking all placement constraints */.
std::unordered_set< WaveClip * > mMigrated
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.
void DoHorizontalOffset(double offset) override
Track & GetTrack() const override
There is always an associated track.
WaveTrackShifter(WaveTrack &track)
bool Attach(Intervals intervals) override
Put moving intervals into the track, which may have migrated from another.
double HintOffsetLarger(double desiredOffset) override
Given amount to shift by horizontally, maybe adjust it from zero to suggest minimum distance.
double QuantizeOffset(double desiredOffset) override
Given amount to shift by horizontally, do any preferred rounding, before placement constraint checks.
std::shared_ptr< WaveTrack > mpTrack
HitTestResult HitTest(double time, const ViewInfo &viewInfo, HitTestParams *params) override
Decide how shift behaves, based on the track that is clicked in.
static bool HitTest(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &rect, const wxPoint &pos)
For defining overrides of the method.
Optional, more complete information for hit testing.