Audacity  3.0.3
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
 
virtual Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
virtual Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
virtual Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
virtual Result Cancel (AudacityProject *pProject) 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 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, 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 270 of file WaveClipTrimHandle.cpp.

271  : mClipTrimPolicy(std::move(clipTrimPolicy))
272 {
273 }

Member Function Documentation

◆ Cancel()

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

Implements UIHandle.

Definition at line 394 of file WaveClipTrimHandle.cpp.

395 {
396  mClipTrimPolicy->Cancel();
398 }

References mClipTrimPolicy, and RefreshCode::RefreshCell.

◆ Click()

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

Implements UIHandle.

Definition at line 368 of file WaveClipTrimHandle.cpp.

370 {
371  if (!ProjectAudioIO::Get(*pProject).IsAudioActive())
372  {
373  if (mClipTrimPolicy->Init(event))
375  }
376  return RefreshCode::Cancelled;
377 }

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 379 of file WaveClipTrimHandle.cpp.

381 {
382  mClipTrimPolicy->Trim(event, *project);
384 }

References mClipTrimPolicy, and RefreshCode::RefreshCell.

◆ HitAnywhere()

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

Definition at line 275 of file WaveClipTrimHandle.cpp.

276 {
277  const auto rect = state.rect;
278 
279  auto px = state.state.m_x;
280 
281  auto& zoomInfo = ViewInfo::Get(*pProject);
282 
283  std::shared_ptr<WaveClip> leftClip;
284  std::shared_ptr<WaveClip> rightClip;
285 
286  //Test left and right boundaries of each clip
287  //to determine which type of trimming should be applied
288  //and input for the policy
289  for (auto& clip : waveTrack->GetClips())
290  {
291  if (!WaveTrackView::ClipDetailsVisible(*clip, zoomInfo, rect))
292  continue;
293 
294  auto clipRect = ClipParameters::GetClipRect(*clip.get(), zoomInfo, rect);
295 
296  //double the hit testing area in case if clip are close to each other
297  if (std::abs(px - clipRect.GetLeft()) <= BoundaryThreshold * 2)
298  rightClip = clip;
299  else if (std::abs(px - clipRect.GetRight()) <= BoundaryThreshold * 2)
300  leftClip = clip;
301  }
302 
303  std::unique_ptr<ClipTrimPolicy> clipTrimPolicy;
304  if (leftClip && rightClip)
305  {
306  //between adjacent clips
307  if(ClipParameters::GetClipRect(*leftClip, zoomInfo, rect).GetRight() > px)
308  clipTrimPolicy = std::make_unique<AdjustBorder>(waveTrack, leftClip, false);//right border
309  else
310  clipTrimPolicy = std::make_unique<AdjustBorder>(waveTrack, rightClip, true);//left border
311  }
312  else
313  {
314  auto clip = leftClip ? leftClip : rightClip;
315  if (clip)
316  {
317  //single clip case, determine the border,
318  //hit testing area differs from one
319  //used for general case
320  auto clipRect = ClipParameters::GetClipRect(*clip.get(), zoomInfo, rect);
321  if (std::abs(px - clipRect.GetLeft()) <= BoundaryThreshold)
322  clipTrimPolicy = std::make_unique<AdjustBorder>(waveTrack, clip, true);
323  else if (std::abs(px - clipRect.GetRight()) <= BoundaryThreshold)
324  clipTrimPolicy = std::make_unique<AdjustBorder>(waveTrack, clip, false);
325  }
326  }
327 
328  if(clipTrimPolicy)
329  return AssignUIHandlePtr(
330  holder,
331  std::make_shared<WaveClipTrimHandle>(clipTrimPolicy)
332  );
333  return { };
334 }

References AssignUIHandlePtr(), BoundaryThreshold, WaveTrackView::ClipDetailsVisible(), ViewInfo::Get(), ClipParameters::GetClipRect(), WaveTrack::GetClips(), 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 253 of file WaveClipTrimHandle.cpp.

254 {
255  static auto disabledCursor =
256  ::MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
257  static auto slideCursor =
258  MakeCursor(wxCURSOR_SIZEWE, TimeCursorXpm, 16, 16);
259  auto message = XO("Click and drag to move clip boundary in time");
260 
261  return {
262  message,
263  (unsafe
264  ? &*disabledCursor
265  : &*slideCursor)
266  };
267 }

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 336 of file WaveClipTrimHandle.cpp.

339 {
340  auto waveTrack = std::dynamic_pointer_cast<WaveTrack>(view.FindTrack());
341  //For multichannel tracks, show trim handle only for the leader track
342  if (!waveTrack->IsLeader() && waveTrack->IsAlignedWithLeader())
343  return {};
344 
345  std::vector<UIHandlePtr> results;
346 
347  const auto rect = state.rect;
348 
349  auto px = state.state.m_x;
350  auto py = state.state.m_y;
351 
352  if (py >= rect.GetTop() &&
353  py <= (rect.GetTop() + static_cast<int>(rect.GetHeight() * 0.3)))
354  {
355  return HitAnywhere(holder, waveTrack.get(), pProject, state);
356  }
357  return {};
358 }

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

Here is the call graph for this function:

◆ Preview()

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

Implements UIHandle.

Definition at line 362 of file WaveClipTrimHandle.cpp.

363 {
364  const bool unsafe = ProjectAudioIO::Get(*pProject).IsAudioActive();
365  return HitPreview(pProject, unsafe);
366 }

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 386 of file WaveClipTrimHandle.cpp.

389 {
390  mClipTrimPolicy->Finish(*project);
392 }

References mClipTrimPolicy, and RefreshCode::RefreshNone.

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 39 of file WaveClipTrimHandle.h.

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


The documentation for this class was generated from the following files:
WaveTrackView::ClipDetailsVisible
static bool ClipDetailsVisible(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect)
Definition: WaveTrackView.cpp:1350
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:259
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:48
MakeCursor
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:182
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
XO
#define XO(s)
Definition: Internat.h:31
ProjectAudioIO::Get
static ProjectAudioIO & Get(AudacityProject &project)
Definition: ProjectAudioIO.cpp:22
ClipParameters::GetClipRect
static wxRect GetClipRect(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &viewRect, bool *outShowSamples=nullptr)
Definition: WaveTrackView.cpp:1667
WaveClipTrimHandle::mClipTrimPolicy
std::unique_ptr< ClipTrimPolicy > mClipTrimPolicy
Definition: WaveClipTrimHandle.h:37
TrackPanelMouseState::rect
const wxRect & rect
Definition: TrackPanelMouseEvent.h:39
ProjectAudioIO::IsAudioActive
bool IsAudioActive() const
Definition: ProjectAudioIO.cpp:51
WaveTrack::GetClips
WaveClipHolders & GetClips()
Definition: WaveTrack.h:374
WaveClipTrimHandle::HitAnywhere
static UIHandlePtr HitAnywhere(std::weak_ptr< WaveClipTrimHandle > &holder, WaveTrack *waveTrack, const AudacityProject *pProject, const TrackPanelMouseState &state)
Definition: WaveClipTrimHandle.cpp:275
WaveClipTrimHandle::HitPreview
static HitTestPreview HitPreview(const AudacityProject *, bool unsafe)
Definition: WaveClipTrimHandle.cpp:253
RefreshCode::RefreshCell
@ RefreshCell
Definition: RefreshCode.h:24
WaveClipTrimHandle::BoundaryThreshold
static constexpr int BoundaryThreshold
Definition: WaveClipTrimHandle.h:21
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
TrackPanelMouseState::state
wxMouseState & state
Definition: TrackPanelMouseEvent.h:38