18#include "../../../../TrackArt.h"
19#include "../../../../TrackArtist.h"
21#include "../../../../TrackPanelDrawingContext.h"
22#include "../../../../../images/Cursors.h"
75 const wxRect &panelRect,
84 bool adjustingLeftBorder,
87 if (!adjustingLeftBorder)
95 return prevInterval ? prevInterval->End() :
96 std::numeric_limits<double>::lowest();
107 if (adjustingLeftBorder)
115 return nextInterval ? nextInterval->Start() :
116 std::numeric_limits<double>::max();
120 nextInterval->Start());
154 const std::pair<double, double> range)
158 auto addSnapPoint = [&](
double t,
const Track* track)
160 if(t > range.second || t < range.first)
163 for(
const auto& snapPoint : result)
166 result.emplace_back(t, track);
169 if(
const auto trackList = currentTrack->
GetOwner())
171 for(
const auto track : as_const(*trackList))
173 if(track == currentTrack)
179 for (
const auto &interval : track->Intervals()) {
180 addSnapPoint(interval->Start(), track);
181 if(interval->Start() != interval->End())
182 addSnapPoint(interval->End(), track);
191 std::shared_ptr<WaveTrack> track,
192 std::shared_ptr<WaveTrack::Interval> interval,
193 bool adjustLeftBorder,
208 if(
const auto trackList =
mTrack->GetOwner())
211 *trackList->GetOwner(),
219 if (event.
event.LeftDown())
229 const auto eventX =
event.event.GetX();
234 const auto eventT = viewInfo.PositionToTime(
297 auto &dc = context.
dc;
312 static auto disabledCursor =
313 MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
314 static auto trimCursorLeft =
315 MakeCursor(wxCURSOR_SIZEWE, ClipTrimLeftXpm , 16, 16);
316 static auto trimCursorRight =
317 MakeCursor(wxCURSOR_SIZEWE, ClipTrimRightXpm, 16, 16);
318 auto message =
XO(
"Click and drag to move clip boundary in time");
324 : &*(isLeftBorder ? trimCursorLeft : trimCursorRight))
330 static auto disabledCursor =
331 MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
332 static auto stretchCursorLeft =
333 MakeCursor(wxCURSOR_SIZEWE, ClipStretchLeftXpm, 16, 16);
334 static auto stretchCursorRight =
335 MakeCursor(wxCURSOR_SIZEWE, ClipStretchRightXpm, 16, 16);
336 auto message =
XO(
"Click and drag to stretch clip");
342 : &*(isLeftBorder ? stretchCursorLeft : stretchCursorRight))
347 std::unique_ptr<AdjustPolicy>& adjustPolicy,
348 std::shared_ptr<const WaveTrack> pTrack,
351 : mAdjustPolicy{
std::move(adjustPolicy) }
352 , mpTrack{ move(pTrack) }
353 , mIsStretchMode{stretchMode}
354 , mIsLeftBorder{leftBorder}
378 std::weak_ptr<WaveClipAdjustBorderHandle>& holder,
379 const std::shared_ptr<WaveTrack>& waveTrack,
383 const auto rect = state.
rect;
385 const auto px = state.
state.m_x;
389 std::shared_ptr<WaveTrack::Interval> leftInterval;
390 std::shared_ptr<WaveTrack::Interval> rightInterval;
395 for (
const auto &interval : waveTrack->Intervals()) {
396 const auto& clip = *interval;
402 rightInterval = interval;
404 leftInterval = interval;
407 std::shared_ptr<WaveTrack::Interval> adjustedInterval;
408 bool adjustLeftBorder {
false};
409 if (leftInterval && rightInterval)
414 adjustedInterval = leftInterval;
415 adjustLeftBorder =
false;
419 adjustedInterval = rightInterval;
420 adjustLeftBorder =
true;
425 adjustedInterval = leftInterval ? leftInterval : rightInterval;
426 if (adjustedInterval)
433 adjustLeftBorder =
true;
435 adjustLeftBorder =
false;
437 adjustedInterval.reset();
443 const auto isStretchMode = state.
state.AltDown();
448 std::unique_ptr<AdjustPolicy> policy =
449 std::make_unique<AdjustClipBorder>(
450 adjustHandler, waveTrack, adjustedInterval, adjustLeftBorder,
451 isStretchMode, zoomInfo);
455 std::make_shared<WaveClipAdjustBorderHandle>(policy, waveTrack,
469 if (waveChannel->GetChannelIndex() != 0)
472 std::vector<UIHandlePtr> results;
474 const auto rect = state.
rect;
476 auto py = state.
state.m_y;
478 if (py >= rect.GetTop() &&
479 py <= (rect.GetTop() +
static_cast<int>(rect.GetHeight() * 0.3)))
482 waveChannel->GetTrack().SharedPointer<
WaveTrack>(),
535 const wxRect& panelRect,
unsigned iPass)
537 return mAdjustPolicy->DrawingArea(context, rect, panelRect, iPass);
std::shared_ptr< UIHandle > UIHandlePtr
std::vector< SnapPoint > SnapPointArray
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
std::shared_ptr< WaveTrack::Interval > mInterval
void Finish(AudacityProject &project) override
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
const std::pair< double, double > mRange
std::shared_ptr< WaveTrack > mTrack
const double mInitialBorderPosition
static SnapPointArray FindSnapPoints(const WaveTrack *currentTrack, const std::pair< double, double > range)
std::unique_ptr< SnapManager > mSnapManager
const bool mAdjustingLeftBorder
std::function< void(WaveTrack::Interval &, double)> AdjustHandler
const bool mIsStretchMode
UIHandle::Result Drag(const TrackPanelMouseEvent &event, AudacityProject &project) override
wxRect DrawingArea(TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
AdjustClipBorder(AdjustHandler adjustHandler, std::shared_ptr< WaveTrack > track, std::shared_ptr< WaveTrack::Interval > interval, bool adjustLeftBorder, bool isStretchMode, const ZoomInfo &zoomInfo)
AdjustHandler mAdjustHandler
bool Init(const TrackPanelMouseEvent &event) override
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
Abstract base class for an object holding data associated with points on a time axis.
std::shared_ptr< TrackList > GetOwner() const
static wxRect MaximizeHeight(const wxRect &rect, const wxRect &panelRect)
static ViewInfo & Get(AudacityProject &project)
std::shared_ptr< WaveChannel > FindWaveChannel()
static bool ClipDetailsVisible(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
virtual UIHandle::Result Drag(const TrackPanelMouseEvent &event, AudacityProject &project)=0
virtual bool Init(const TrackPanelMouseEvent &event)=0
virtual wxRect DrawingArea(TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
virtual void Finish(AudacityProject &project)=0
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
std::shared_ptr< const Track > FindTrack() const override
std::unique_ptr< AdjustPolicy > mAdjustPolicy
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
HitTestPreview Preview(const TrackPanelMouseState &mouseState, AudacityProject *pProject) override
~WaveClipAdjustBorderHandle() override
wxRect DrawingArea(TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
static HitTestPreview HitPreviewTrim(const AudacityProject *, bool unsafe, bool isLeftBorder)
static constexpr int BoundaryThreshold
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Result Cancel(AudacityProject *pProject) override
WaveClipAdjustBorderHandle(std::unique_ptr< AdjustPolicy > &adjustPolicy, std::shared_ptr< const WaveTrack > pTrack, bool stretchMode, bool leftBorder)
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
static HitTestPreview HitPreviewStretch(const AudacityProject *, bool unsafe, bool isLeftBorder)
static UIHandlePtr HitAnywhere(std::weak_ptr< WaveClipAdjustBorderHandle > &holder, const std::shared_ptr< WaveTrack > &waveTrack, const AudacityProject *pProject, const TrackPanelMouseState &state)
std::shared_ptr< const WaveTrack > mpTrack
static UIHandlePtr HitTest(std::weak_ptr< WaveClipAdjustBorderHandle > &holder, WaveChannelView &view, const AudacityProject *pProject, const TrackPanelMouseState &state)
This allows multiple clips to be a part of one WaveTrack.
double GetSequenceStartTime() const noexcept
double Start() const override
double End() const override
void TrimLeftTo(double to)
Sets the the left trimming to the absolute time (if that is in bounds)
void TrimRightTo(double to)
Sets the the right trimming to the absolute time (if that is in bounds)
void StretchRightTo(double to)
Sets from the right to the absolute time (if in expected range)
double GetSequenceEndTime() const
void StretchLeftTo(double to)
Stretches from left to the absolute time (if in expected range)
A Track that contains audio waveform data.
IntervalConstHolder GetNextInterval(const Interval &interval, PlaybackDirection searchDirection) const
double GetRate() const override
Positions or offsets within audio files need a wide type.
AUDACITY_DLL_API void DrawSnapLines(wxDC *dc, wxInt64 snap0, wxInt64 snap1)
void PushClipSpeedChangedUndoState(AudacityProject &project, double speedInPercent)
void StretchRightTo(WaveTrack::Interval &interval, double t)
double GetRightAdjustLimit(const WaveTrack::Interval &interval, const WaveTrack &track, bool adjustingLeftBorder, bool isStretchMode)
void StretchLeftTo(WaveTrack::Interval &interval, double t)
double GetLeftAdjustLimit(const WaveTrack::Interval &interval, const WaveTrack &track, bool adjustingLeftBorder, bool isStretchMode)
void TrimLeftTo(WaveTrack::Interval &interval, double t)
void TrimRightTo(WaveTrack::Interval &interval, double t)
static wxRect GetClipRect(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)