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
WaveClipTrimHandle Class Reference

#include <WaveClipTrimHandle.h>

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

Classes

class  AdjustBetweenBorders
 
class  AdjustBorder
 
class  ClipTrimPolicy
 

Public Member Functions

 WaveClipTrimHandle (std::unique_ptr< ClipTrimPolicy > &clipTrimPolicy)
 
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)
 
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< WaveClipTrimHandle > &holder, const std::shared_ptr< WaveTrack > &waveTrack, const AudacityProject *pProject, const TrackPanelMouseState &state)
 
static UIHandlePtr HitTest (std::weak_ptr< WaveClipTrimHandle > &holder, WaveTrackView &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 HitPreview (const AudacityProject *, bool unsafe)
 

Private Attributes

std::unique_ptr< ClipTrimPolicymClipTrimPolicy {}
 

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 WaveClipTrimHandle.h.

Constructor & Destructor Documentation

◆ WaveClipTrimHandle()

WaveClipTrimHandle::WaveClipTrimHandle ( std::unique_ptr< ClipTrimPolicy > &  clipTrimPolicy)

Definition at line 370 of file WaveClipTrimHandle.cpp.

371 : mClipTrimPolicy{ std::move(clipTrimPolicy) }
372{
373
374}
std::unique_ptr< ClipTrimPolicy > mClipTrimPolicy

Member Function Documentation

◆ Cancel()

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

Implements UIHandle.

Definition at line 505 of file WaveClipTrimHandle.cpp.

506{
507 mClipTrimPolicy->Cancel();
509}

References mClipTrimPolicy, and RefreshCode::RefreshAll.

◆ Click()

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

Implements UIHandle.

Definition at line 480 of file WaveClipTrimHandle.cpp.

482{
483 if (!ProjectAudioIO::Get(*pProject).IsAudioActive())
484 {
485 if (mClipTrimPolicy->Init(event))
487 }
489}
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)

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

Here is the call graph for this function:

◆ Drag()

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

Implements UIHandle.

Definition at line 491 of file WaveClipTrimHandle.cpp.

493{
494 return mClipTrimPolicy->Trim(event, *project);
495}

References mClipTrimPolicy.

◆ Draw()

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

Reimplemented from TrackPanelDrawable.

Definition at line 511 of file WaveClipTrimHandle.cpp.

512{
513 mClipTrimPolicy->Draw(context, rect, iPass);
514}

References mClipTrimPolicy.

◆ DrawingArea()

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

Reimplemented from TrackPanelDrawable.

Definition at line 516 of file WaveClipTrimHandle.cpp.

518{
519 return mClipTrimPolicy->DrawingArea(context, rect, panelRect, iPass);
520}

References mClipTrimPolicy.

◆ HitAnywhere()

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

Definition at line 383 of file WaveClipTrimHandle.cpp.

388{
389 const auto rect = state.rect;
390
391 auto px = state.state.m_x;
392
393 auto& zoomInfo = ViewInfo::Get(*pProject);
394
395 std::shared_ptr<WaveClip> leftClip;
396 std::shared_ptr<WaveClip> rightClip;
397
398 //Test left and right boundaries of each clip
399 //to determine which type of trimming should be applied
400 //and input for the policy
401 for (auto& clip : waveTrack->GetClips())
402 {
403 if (!WaveTrackView::ClipDetailsVisible(*clip, zoomInfo, rect))
404 continue;
405
406 auto clipRect = ClipParameters::GetClipRect(*clip.get(), zoomInfo, rect);
407
408 //double the hit testing area in case if clip are close to each other
409 if (std::abs(px - clipRect.GetLeft()) <= BoundaryThreshold * 2)
410 rightClip = clip;
411 else if (std::abs(px - clipRect.GetRight()) <= BoundaryThreshold * 2)
412 leftClip = clip;
413 }
414
415 std::unique_ptr<ClipTrimPolicy> clipTrimPolicy;
416 if (leftClip && rightClip)
417 {
418 //between adjacent clips
419 if(ClipParameters::GetClipRect(*leftClip, zoomInfo, rect).GetRight() > px)
420 clipTrimPolicy = std::make_unique<AdjustBorder>(waveTrack, leftClip, false, zoomInfo);//right border
421 else
422 clipTrimPolicy = std::make_unique<AdjustBorder>(waveTrack, rightClip, true, zoomInfo);//left border
423 }
424 else
425 {
426 auto clip = leftClip ? leftClip : rightClip;
427 if (clip)
428 {
429 //single clip case, determine the border,
430 //hit testing area differs from one
431 //used for general case
432 auto clipRect = ClipParameters::GetClipRect(*clip.get(), zoomInfo, rect);
433 if (std::abs(px - clipRect.GetLeft()) <= BoundaryThreshold)
434 clipTrimPolicy = std::make_unique<AdjustBorder>(waveTrack, clip, true, zoomInfo);
435 else if (std::abs(px - clipRect.GetRight()) <= BoundaryThreshold)
436 clipTrimPolicy = std::make_unique<AdjustBorder>(waveTrack, clip, false, zoomInfo);
437 }
438 }
439
440 if(clipTrimPolicy)
441 return AssignUIHandlePtr(
442 holder,
443 std::make_shared<WaveClipTrimHandle>(clipTrimPolicy)
444 );
445 return { };
446}
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static constexpr int BoundaryThreshold
static bool ClipDetailsVisible(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
static wxRect GetClipRect(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)

References AssignUIHandlePtr(), BoundaryThreshold, WaveTrackView::ClipDetailsVisible(), ViewInfo::Get(), ClipParameters::GetClipRect(), TrackPanelMouseState::rect, and TrackPanelMouseState::state.

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

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

◆ HitPreview()

HitTestPreview WaveClipTrimHandle::HitPreview ( const AudacityProject ,
bool  unsafe 
)
staticprivate

Definition at line 353 of file WaveClipTrimHandle.cpp.

354{
355 static auto disabledCursor =
356 ::MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
357 static auto slideCursor =
358 MakeCursor(wxCURSOR_SIZEWE, TimeCursorXpm, 16, 16);
359 auto message = XO("Click and drag to move clip boundary in time");
360
361 return {
362 message,
363 (unsafe
364 ? &*disabledCursor
365 : &*slideCursor)
366 };
367}
#define XO(s)
Definition: Internat.h:31
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:185

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 WaveClipTrimHandle::HitTest ( std::weak_ptr< WaveClipTrimHandle > &  holder,
WaveTrackView view,
const AudacityProject pProject,
const TrackPanelMouseState state 
)
static

Definition at line 448 of file WaveClipTrimHandle.cpp.

451{
452 auto waveTrack = std::dynamic_pointer_cast<WaveTrack>(view.FindTrack());
453 //For multichannel tracks, show trim handle only for the leader track
454 if (!waveTrack->IsLeader() && waveTrack->IsAlignedWithLeader())
455 return {};
456
457 std::vector<UIHandlePtr> results;
458
459 const auto rect = state.rect;
460
461 auto px = state.state.m_x;
462 auto py = state.state.m_y;
463
464 if (py >= rect.GetTop() &&
465 py <= (rect.GetTop() + static_cast<int>(rect.GetHeight() * 0.3)))
466 {
467 return HitAnywhere(holder, waveTrack, pProject, state);
468 }
469 return {};
470}
std::shared_ptr< Track > FindTrack()
static UIHandlePtr HitAnywhere(std::weak_ptr< WaveClipTrimHandle > &holder, const std::shared_ptr< WaveTrack > &waveTrack, const AudacityProject *pProject, const TrackPanelMouseState &state)

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

Referenced by WaveTrackSubView::DoDetailedHitTest().

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

◆ Preview()

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

Implements UIHandle.

Definition at line 474 of file WaveClipTrimHandle.cpp.

475{
476 const bool unsafe = ProjectAudioIO::Get(*pProject).IsAudioActive();
477 return HitPreview(pProject, unsafe);
478}
static HitTestPreview HitPreview(const AudacityProject *, bool unsafe)

References ProjectAudioIO::Get(), HitPreview(), and ProjectAudioIO::IsAudioActive().

Here is the call graph for this function:

◆ Release()

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

Implements UIHandle.

Definition at line 497 of file WaveClipTrimHandle.cpp.

500{
501 mClipTrimPolicy->Finish(*project);
503}

References mClipTrimPolicy, and RefreshCode::RefreshAll.

Member Data Documentation

◆ BoundaryThreshold

constexpr int WaveClipTrimHandle::BoundaryThreshold = 5
staticconstexprprivate

Definition at line 21 of file WaveClipTrimHandle.h.

Referenced by HitAnywhere().

◆ mClipTrimPolicy

std::unique_ptr<ClipTrimPolicy> WaveClipTrimHandle::mClipTrimPolicy {}
private

Definition at line 50 of file WaveClipTrimHandle.h.

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


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