6#include "../../../ui/TimeShiftHandle.h"
13#include <unordered_set>
30 const auto pClip = [&]() -> std::shared_ptr<WaveClip> {
31 for (
auto clip :
mpTrack->Intervals())
36 *clip, viewInfo,
params->rect, { params->xx, params->yy })
41 clip->GetPlayStartTime() <= time &&
42 time < clip->GetPlayEndTime()
53 if (
mpTrack->IsSelected() && time >= t0 && time < t1) {
61 return &interval == pClip.get();
73 const auto c0 =
mpTrack->TimeToLongSamples(clip.GetPlayStartTime());
74 const auto c1 =
mpTrack->TimeToLongSamples(clip.GetPlayEndTime());
77 mpTrack->TimeToLongSamples(interval.
End()) > c0;
91 bool positive = (desiredOffset > 0);
94 double nSamples =
rint(
mpTrack->GetRate() * desiredOffset);
95 nSamples = std::max(nSamples, 1.0);
96 desiredOffset = nSamples /
mpTrack->GetRate();
104 const auto rate =
mpTrack->GetRate();
106 return rint(desiredOffset * rate) / rate;
111 std::vector<WaveTrack::Interval *> movingClips;
114 movingClips.push_back(&data);
116 double newAmount = 0;
117 mpTrack->CanOffsetClips(movingClips, desiredOffset, &newAmount);
123 for (
auto &interval:
mMoving) {
124 auto pClip = std::static_pointer_cast<WaveTrack::Interval>(interval);
125 mpTrack->RemoveInterval(pClip);
135 double &desiredOffset,
double tolerance)
override
138 auto pOtherWaveTrack =
static_cast<const WaveTrack*
>(&otherTrack);
139 for (
auto &interval: intervals) {
141 if (!(ok = pOtherWaveTrack->CanInsertClip(data, desiredOffset, tolerance)))
149 for (
auto interval : intervals) {
150 auto data = std::static_pointer_cast<WaveTrack::Interval>(interval);
151 mpTrack->InsertInterval(data,
false);
154 data->ShiftBy(offset);
155 mMoving.emplace_back(std::move(interval));
162 auto rate =
mpTrack->GetRate();
166 pClip->Resample(rate);
189 t0 = std::clamp(t0, clip.GetPlayStartTime(), clip.GetPlayEndTime());
204 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.
Abstract base class for policies to manipulate a track type for Time Shift.
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.
void UnfixIntervals(std::function< bool(const ChannelGroupInterval &)> pred)
Change intervals satisfying a predicate from fixed to moving.
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.
std::vector< std::shared_ptr< ChannelGroupInterval > > Intervals
NotifyingSelectedRegion selectedRegion
static bool HitTest(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &rect, const wxPoint &pos)
This allows multiple clips to be a part of one WaveTrack.
void ShiftBy(double delta) noexcept
A Track that contains audio waveform data.
Intervals Detach() override
Remove all moving intervals from the track, if possible.
bool Attach(Intervals intervals, double offset) override
Put moving intervals into the track, which may have migrated from another.
double AdjustT0(double t0) const override
const std::shared_ptr< WaveTrack > mpTrack
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.
bool MayMigrateTo(Track &other) override
bool AdjustFit(const Track &otherTrack, const Intervals &intervals, double &desiredOffset, double tolerance) override
void DoHorizontalOffset(double offset) override
std::vector< WaveTrack::IntervalHolder > mMigrated
Track & GetTrack() const override
There is always an associated track.
void SelectInterval(TimeInterval interval) override
Notifies the shifter that a region is selected, so it may update its fixed and moving intervals.
WaveTrackShifter(WaveTrack &track)
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.
HitTestResult HitTest(double time, const ViewInfo &viewInfo, HitTestParams *params) override
Decide how shift behaves, based on the track that is clicked in.
__finl float __vecc rint(float a)
For defining overrides of the method.
Optional, more complete information for hit testing.