Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
WaveClipAdjustBorderHandle Class Referencefinal

#include <WaveClipAdjustBorderHandle.h>

Inheritance diagram for WaveClipAdjustBorderHandle:
[legend]
Collaboration diagram for WaveClipAdjustBorderHandle:
[legend]

Classes

class  AdjustPolicy
 

Public Member Functions

 WaveClipAdjustBorderHandle (std::unique_ptr< AdjustPolicy > &adjustPolicy, std::shared_ptr< const WaveTrack > pTrack, bool stretchMode, bool leftBorder)
 
 ~WaveClipAdjustBorderHandle () override
 
std::shared_ptr< const ChannelFindChannel () const override
 
 WaveClipAdjustBorderHandle (WaveClipAdjustBorderHandle &&) noexcept
 
WaveClipAdjustBorderHandleoperator= (WaveClipAdjustBorderHandle &&) noexcept
 
HitTestPreview Preview (const TrackPanelMouseState &mouseState, AudacityProject *pProject) override
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
 
wxRect DrawingArea (TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual void Enter (bool forward, AudacityProject *pProject)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool HandlesRightClick ()
 Whether the handle has any special right-button handling. More...
 
virtual Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject)=0
 
virtual Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
 
virtual Result Cancel (AudacityProject *pProject)=0
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
virtual std::shared_ptr< const ChannelFindChannel () const =0
 
virtual bool IsDragging () const
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

Static Public Member Functions

static UIHandlePtr HitAnywhere (std::weak_ptr< WaveClipAdjustBorderHandle > &holder, const std::shared_ptr< WaveTrack > &waveTrack, const AudacityProject *pProject, const TrackPanelMouseState &state)
 
static UIHandlePtr HitTest (std::weak_ptr< WaveClipAdjustBorderHandle > &holder, WaveChannelView &view, const AudacityProject *pProject, const TrackPanelMouseState &state)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 

Static Private Member Functions

static HitTestPreview HitPreviewTrim (const AudacityProject *, bool unsafe, bool isLeftBorder)
 
static HitTestPreview HitPreviewStretch (const AudacityProject *, bool unsafe, bool isLeftBorder)
 

Private Attributes

std::unique_ptr< AdjustPolicymAdjustPolicy {}
 
std::shared_ptr< const WaveTrackmpTrack
 
bool mIsStretchMode
 
bool mIsLeftBorder
 

Static Private Attributes

static constexpr int BoundaryThreshold = 5
 

Additional Inherited Members

- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 19 of file WaveClipAdjustBorderHandle.h.

Constructor & Destructor Documentation

◆ WaveClipAdjustBorderHandle() [1/2]

WaveClipAdjustBorderHandle::WaveClipAdjustBorderHandle ( std::unique_ptr< AdjustPolicy > &  adjustPolicy,
std::shared_ptr< const WaveTrack pTrack,
bool  stretchMode,
bool  leftBorder 
)

Definition at line 354 of file WaveClipAdjustBorderHandle.cpp.

359 : mAdjustPolicy{ std::move(adjustPolicy) }
360 , mpTrack{ move(pTrack) }
361 , mIsStretchMode{stretchMode}
362 , mIsLeftBorder{leftBorder}
363{
364
365}
std::unique_ptr< AdjustPolicy > mAdjustPolicy
std::shared_ptr< const WaveTrack > mpTrack

◆ ~WaveClipAdjustBorderHandle()

WaveClipAdjustBorderHandle::~WaveClipAdjustBorderHandle ( )
overridedefault

◆ WaveClipAdjustBorderHandle() [2/2]

WaveClipAdjustBorderHandle::WaveClipAdjustBorderHandle ( WaveClipAdjustBorderHandle &&  )
defaultnoexcept

Member Function Documentation

◆ Cancel()

UIHandle::Result WaveClipAdjustBorderHandle::Cancel ( AudacityProject pProject)
overridevirtual

Implements UIHandle.

Definition at line 531 of file WaveClipAdjustBorderHandle.cpp.

532{
533 mAdjustPolicy->Cancel();
535}

References mAdjustPolicy, and RefreshCode::RefreshAll.

◆ Click()

UIHandle::Result WaveClipAdjustBorderHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 506 of file WaveClipAdjustBorderHandle.cpp.

508{
509 if (!ProjectAudioIO::Get(*pProject).IsAudioActive())
510 {
511 if (mAdjustPolicy->Init(event))
513 }
515}
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)

References RefreshCode::Cancelled, ProjectAudioIO::Get(), ProjectAudioIO::IsAudioActive(), mAdjustPolicy, and RefreshCode::RefreshNone.

Here is the call graph for this function:

◆ Drag()

UIHandle::Result WaveClipAdjustBorderHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 517 of file WaveClipAdjustBorderHandle.cpp.

519{
520 return mAdjustPolicy->Drag(event, *project);
521}
const auto project

References mAdjustPolicy, and project.

◆ Draw()

void WaveClipAdjustBorderHandle::Draw ( TrackPanelDrawingContext context,
const wxRect &  rect,
unsigned  iPass 
)
overridevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 537 of file WaveClipAdjustBorderHandle.cpp.

538{
539 mAdjustPolicy->Draw(context, rect, iPass);
540}

References mAdjustPolicy.

◆ DrawingArea()

wxRect WaveClipAdjustBorderHandle::DrawingArea ( TrackPanelDrawingContext context,
const wxRect &  rect,
const wxRect &  panelRect,
unsigned  iPass 
)
overridevirtual

Reimplemented from TrackPanelDrawable.

Definition at line 542 of file WaveClipAdjustBorderHandle.cpp.

544{
545 return mAdjustPolicy->DrawingArea(context, rect, panelRect, iPass);
546}

References mAdjustPolicy.

◆ FindChannel()

std::shared_ptr< const Channel > WaveClipAdjustBorderHandle::FindChannel ( ) const
overridevirtual
Returns
pointer to associated channel, if any

Implements UIHandle.

Definition at line 369 of file WaveClipAdjustBorderHandle.cpp.

370{
371 return mpTrack;
372}

References mpTrack.

◆ HitAnywhere()

UIHandlePtr WaveClipAdjustBorderHandle::HitAnywhere ( std::weak_ptr< WaveClipAdjustBorderHandle > &  holder,
const std::shared_ptr< WaveTrack > &  waveTrack,
const AudacityProject pProject,
const TrackPanelMouseState state 
)
static

Definition at line 385 of file WaveClipAdjustBorderHandle.cpp.

390{
391 assert(waveTrack->IsLeader());
392
393 const auto rect = state.rect;
394
395 const auto px = state.state.m_x;
396
397 auto& zoomInfo = ViewInfo::Get(*pProject);
398
399 std::shared_ptr<WaveTrack::Interval> leftInterval;
400 std::shared_ptr<WaveTrack::Interval> rightInterval;
401
402 //Test left and right boundaries of each clip
403 //to determine which kind of adjustment is
404 //more appropriate
405 for(const auto& interval : waveTrack->Intervals())
406 {
407 const auto& clip = *interval->GetClip(0);
408 if(!WaveChannelView::ClipDetailsVisible(clip, zoomInfo, rect))
409 continue;
410
411 auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect);
412 if(std::abs(px - clipRect.GetLeft()) <= BoundaryThreshold * 2)
413 rightInterval = interval;
414 else if (std::abs(px - clipRect.GetRight()) <= BoundaryThreshold * 2)
415 leftInterval = interval;
416 }
417
418 std::shared_ptr<WaveTrack::Interval> adjustedInterval;
419 bool adjustLeftBorder {false};
420 if (leftInterval && rightInterval)
421 {
422 //between adjacent clips
423 if(ClipParameters::GetClipRect(*leftInterval->GetClip(0), zoomInfo, rect).GetRight() > px)
424 {
425 adjustedInterval = leftInterval;
426 adjustLeftBorder = false;
427 }
428 else
429 {
430 adjustedInterval = rightInterval;
431 adjustLeftBorder = true;
432 }
433 }
434 else
435 {
436 adjustedInterval = leftInterval ? leftInterval : rightInterval;
437 if (adjustedInterval)
438 {
439 //single clip case, determine the border,
440 //hit testing area differs from one
441 //used for general case
442 const auto clipRect = ClipParameters::GetClipRect(*adjustedInterval->GetClip(0), zoomInfo, rect);
443 if (std::abs(px - clipRect.GetLeft()) <= BoundaryThreshold)
444 adjustLeftBorder = true;
445 else if (std::abs(px - clipRect.GetRight()) <= BoundaryThreshold)
446 adjustLeftBorder = false;
447 else
448 adjustedInterval.reset();
449 }
450 }
451
452 if(adjustedInterval)
453 {
454 const auto isStretchMode = state.state.AltDown();
455 AdjustClipBorder::AdjustHandler adjustHandler = isStretchMode
456 ? (adjustLeftBorder ? StretchLeftTo : StretchRightTo)
457 : (adjustLeftBorder ? TrimLeftTo : TrimRightTo);
458
459 std::unique_ptr<AdjustPolicy> policy =
460 std::make_unique<AdjustClipBorder>(
461 adjustHandler, waveTrack, adjustedInterval, adjustLeftBorder,
462 isStretchMode, zoomInfo);
463
464 return AssignUIHandlePtr(
465 holder,
466 std::make_shared<WaveClipAdjustBorderHandle>(policy, waveTrack,
467 isStretchMode,
468 adjustLeftBorder));
469 }
470 return { };
471}
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:159
std::function< void(WaveTrack::Interval &, double)> AdjustHandler
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static bool ClipDetailsVisible(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
void StretchRightTo(WaveTrack::Interval &interval, double t)
void StretchLeftTo(WaveTrack::Interval &interval, double t)
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)

References AssignUIHandlePtr(), BoundaryThreshold, WaveChannelView::ClipDetailsVisible(), ViewInfo::Get(), ClipParameters::GetClipRect(), TrackPanelMouseState::rect, TrackPanelMouseState::state, anonymous_namespace{WaveClipAdjustBorderHandle.cpp}::StretchLeftTo(), anonymous_namespace{WaveClipAdjustBorderHandle.cpp}::StretchRightTo(), anonymous_namespace{WaveClipAdjustBorderHandle.cpp}::TrimLeftTo(), and anonymous_namespace{WaveClipAdjustBorderHandle.cpp}::TrimRightTo().

Referenced by WaveTrackAffordanceControls::HitTest(), and HitTest().

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

◆ HitPreviewStretch()

HitTestPreview WaveClipAdjustBorderHandle::HitPreviewStretch ( const AudacityProject ,
bool  unsafe,
bool  isLeftBorder 
)
staticprivate

Definition at line 336 of file WaveClipAdjustBorderHandle.cpp.

337{
338 static auto disabledCursor =
339 MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
340 static auto stretchCursorLeft =
341 MakeCursor(wxCURSOR_SIZEWE, ClipStretchLeftXpm, 16, 16);
342 static auto stretchCursorRight =
343 MakeCursor(wxCURSOR_SIZEWE, ClipStretchRightXpm, 16, 16);
344 auto message = XO("Click and drag to stretch clip");
345
346 return {
347 message,
348 (unsafe
349 ? &*disabledCursor
350 : &*(isLeftBorder ? stretchCursorLeft : stretchCursorRight))
351 };
352}
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:188

References MakeCursor(), and XO().

Referenced by Preview().

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

◆ HitPreviewTrim()

HitTestPreview WaveClipAdjustBorderHandle::HitPreviewTrim ( const AudacityProject ,
bool  unsafe,
bool  isLeftBorder 
)
staticprivate

Definition at line 318 of file WaveClipAdjustBorderHandle.cpp.

319{
320 static auto disabledCursor =
321 MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
322 static auto trimCursorLeft =
323 MakeCursor(wxCURSOR_SIZEWE, ClipTrimLeftXpm , 16, 16);
324 static auto trimCursorRight =
325 MakeCursor(wxCURSOR_SIZEWE, ClipTrimRightXpm, 16, 16);
326 auto message = XO("Click and drag to move clip boundary in time");
327
328 return {
329 message,
330 (unsafe
331 ? &*disabledCursor
332 : &*(isLeftBorder ? trimCursorLeft : trimCursorRight))
333 };
334}

References MakeCursor(), and XO().

Referenced by Preview().

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

◆ HitTest()

UIHandlePtr WaveClipAdjustBorderHandle::HitTest ( std::weak_ptr< WaveClipAdjustBorderHandle > &  holder,
WaveChannelView view,
const AudacityProject pProject,
const TrackPanelMouseState state 
)
static

Definition at line 473 of file WaveClipAdjustBorderHandle.cpp.

476{
477 auto waveTrack = std::dynamic_pointer_cast<WaveTrack>(view.FindTrack());
478 //For multichannel tracks, show adjustment handle only for the leader track
479 if (!waveTrack->IsLeader())
480 return {};
481
482 std::vector<UIHandlePtr> results;
483
484 const auto rect = state.rect;
485
486 auto py = state.state.m_y;
487
488 if (py >= rect.GetTop() &&
489 py <= (rect.GetTop() + static_cast<int>(rect.GetHeight() * 0.3)))
490 {
491 return HitAnywhere(holder, waveTrack, pProject, state);
492 }
493 return {};
494}
std::shared_ptr< Track > FindTrack()
static UIHandlePtr HitAnywhere(std::weak_ptr< WaveClipAdjustBorderHandle > &holder, const std::shared_ptr< WaveTrack > &waveTrack, const AudacityProject *pProject, const TrackPanelMouseState &state)

References CommonTrackPanelCell::FindTrack(), HitAnywhere(), TrackPanelMouseState::rect, and TrackPanelMouseState::state.

Referenced by WaveChannelSubView::DoDetailedHitTest().

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

◆ operator=()

WaveClipAdjustBorderHandle & WaveClipAdjustBorderHandle::operator= ( WaveClipAdjustBorderHandle &&  )
defaultnoexcept

◆ Preview()

HitTestPreview WaveClipAdjustBorderHandle::Preview ( const TrackPanelMouseState mouseState,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 498 of file WaveClipAdjustBorderHandle.cpp.

499{
500 const bool unsafe = ProjectAudioIO::Get(*pProject).IsAudioActive();
501 return mIsStretchMode
502 ? HitPreviewStretch(pProject, unsafe, mIsLeftBorder)
503 : HitPreviewTrim(pProject, unsafe, mIsLeftBorder);
504}
static HitTestPreview HitPreviewTrim(const AudacityProject *, bool unsafe, bool isLeftBorder)
static HitTestPreview HitPreviewStretch(const AudacityProject *, bool unsafe, bool isLeftBorder)

References ProjectAudioIO::Get(), HitPreviewStretch(), HitPreviewTrim(), ProjectAudioIO::IsAudioActive(), mIsLeftBorder, and mIsStretchMode.

Here is the call graph for this function:

◆ Release()

UIHandle::Result WaveClipAdjustBorderHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Implements UIHandle.

Definition at line 523 of file WaveClipAdjustBorderHandle.cpp.

526{
527 mAdjustPolicy->Finish(*project);
529}

References mAdjustPolicy, project, and RefreshCode::RefreshAll.

Member Data Documentation

◆ BoundaryThreshold

constexpr int WaveClipAdjustBorderHandle::BoundaryThreshold = 5
staticconstexprprivate

Definition at line 25 of file WaveClipAdjustBorderHandle.h.

Referenced by HitAnywhere().

◆ mAdjustPolicy

std::unique_ptr<AdjustPolicy> WaveClipAdjustBorderHandle::mAdjustPolicy {}
private

Definition at line 30 of file WaveClipAdjustBorderHandle.h.

Referenced by Cancel(), Click(), Drag(), Draw(), DrawingArea(), and Release().

◆ mIsLeftBorder

bool WaveClipAdjustBorderHandle::mIsLeftBorder
private

Definition at line 33 of file WaveClipAdjustBorderHandle.h.

Referenced by Preview().

◆ mIsStretchMode

bool WaveClipAdjustBorderHandle::mIsStretchMode
private

Definition at line 32 of file WaveClipAdjustBorderHandle.h.

Referenced by Preview().

◆ mpTrack

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

Definition at line 31 of file WaveClipAdjustBorderHandle.h.

Referenced by FindChannel().


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