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 TrackFindTrack () 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 TrackFindTrack () 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 std::shared_ptr< const TrackTrackFromChannel (const std::shared_ptr< const Channel > &pChannel)
 A frequent convenience in the definition of UIHandles. More...
 
- 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 346 of file WaveClipAdjustBorderHandle.cpp.

351 : mAdjustPolicy{ std::move(adjustPolicy) }
352 , mpTrack{ move(pTrack) }
353 , mIsStretchMode{stretchMode}
354 , mIsLeftBorder{leftBorder}
355{
356
357}
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 523 of file WaveClipAdjustBorderHandle.cpp.

524{
525 mAdjustPolicy->Cancel();
527}

References mAdjustPolicy, and RefreshCode::RefreshAll.

◆ Click()

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

Implements UIHandle.

Definition at line 498 of file WaveClipAdjustBorderHandle.cpp.

500{
501 if (!ProjectAudioIO::Get(*pProject).IsAudioActive())
502 {
503 if (mAdjustPolicy->Init(event))
505 }
507}
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 509 of file WaveClipAdjustBorderHandle.cpp.

511{
512 return mAdjustPolicy->Drag(event, *project);
513}
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 529 of file WaveClipAdjustBorderHandle.cpp.

530{
531 mAdjustPolicy->Draw(context, rect, iPass);
532}

References mAdjustPolicy.

◆ DrawingArea()

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

Reimplemented from TrackPanelDrawable.

Definition at line 534 of file WaveClipAdjustBorderHandle.cpp.

536{
537 return mAdjustPolicy->DrawingArea(context, rect, panelRect, iPass);
538}

References mAdjustPolicy.

◆ FindTrack()

std::shared_ptr< const Track > WaveClipAdjustBorderHandle::FindTrack ( ) const
overridevirtual
Returns
pointer to associated track, if any

Implements UIHandle.

Definition at line 361 of file WaveClipAdjustBorderHandle.cpp.

362{
363 return mpTrack;
364}

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 377 of file WaveClipAdjustBorderHandle.cpp.

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

329{
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");
337
338 return {
339 message,
340 (unsafe
341 ? &*disabledCursor
342 : &*(isLeftBorder ? stretchCursorLeft : stretchCursorRight))
343 };
344}
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:189

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 310 of file WaveClipAdjustBorderHandle.cpp.

311{
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");
319
320 return {
321 message,
322 (unsafe
323 ? &*disabledCursor
324 : &*(isLeftBorder ? trimCursorLeft : trimCursorRight))
325 };
326}

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 462 of file WaveClipAdjustBorderHandle.cpp.

465{
466 auto waveChannel = view.FindWaveChannel();
467 // For multichannel tracks, show adjustment handle only for the topmost
468 // channel
469 if (waveChannel->GetChannelIndex() != 0)
470 return {};
471
472 std::vector<UIHandlePtr> results;
473
474 const auto rect = state.rect;
475
476 auto py = state.state.m_y;
477
478 if (py >= rect.GetTop() &&
479 py <= (rect.GetTop() + static_cast<int>(rect.GetHeight() * 0.3)))
480 {
481 return HitAnywhere(holder,
482 waveChannel->GetTrack().SharedPointer<WaveTrack>(),
483 pProject, state);
484 }
485 return {};
486}
std::shared_ptr< WaveChannel > FindWaveChannel()
static UIHandlePtr HitAnywhere(std::weak_ptr< WaveClipAdjustBorderHandle > &holder, const std::shared_ptr< WaveTrack > &waveTrack, const AudacityProject *pProject, const TrackPanelMouseState &state)
A Track that contains audio waveform data.
Definition: WaveTrack.h:203

References WaveChannelView::FindWaveChannel(), 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 490 of file WaveClipAdjustBorderHandle.cpp.

491{
492 const bool unsafe = ProjectAudioIO::Get(*pProject).IsAudioActive();
493 return mIsStretchMode
494 ? HitPreviewStretch(pProject, unsafe, mIsLeftBorder)
495 : HitPreviewTrim(pProject, unsafe, mIsLeftBorder);
496}
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 515 of file WaveClipAdjustBorderHandle.cpp.

518{
519 mAdjustPolicy->Finish(*project);
521}

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 FindTrack().


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