Audacity  3.0.3
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
CutlineHandle Class Referencefinal

#include <CutlineHandle.h>

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

Public Member Functions

 CutlineHandle (const std::shared_ptr< WaveTrack > &pTrack, WaveTrackLocation location)
 
CutlineHandleoperator= (const CutlineHandle &)=default
 
virtual ~CutlineHandle ()
 
const WaveTrackLocationGetLocation ()
 
std::shared_ptr< WaveTrackGetTrack ()
 
void Enter (bool forward, AudacityProject *) override
 
bool HandlesRightClick () override
 Whether the handle has any special right-button handling. More...
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
bool StopsOnKeystroke () override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
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 (const AudacityProject *pProject, bool cutline, UIHandlePtr ptr)
 
static UIHandlePtr HitTest (std::weak_ptr< CutlineHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< WaveTrack > &pTrack)
 
- 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)
 

Private Types

enum  Operation { Merge, Expand, Remove }
 

Private Member Functions

 CutlineHandle (const CutlineHandle &)=delete
 

Static Private Member Functions

static HitTestPreview HitPreview (bool cutline, bool unsafe)
 

Private Attributes

std::shared_ptr< WaveTrackmpTrack {}
 
Operation mOperation { Merge }
 
double mStartTime {}
 
double mEndTime {}
 
WaveTrackLocation mLocation {}
 

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 21 of file CutlineHandle.h.

Member Enumeration Documentation

◆ Operation

Enumerator
Merge 
Expand 
Remove 

Definition at line 70 of file CutlineHandle.h.

70 { Merge, Expand, Remove };

Constructor & Destructor Documentation

◆ CutlineHandle() [1/2]

CutlineHandle::CutlineHandle ( const CutlineHandle )
privatedelete

◆ CutlineHandle() [2/2]

CutlineHandle::CutlineHandle ( const std::shared_ptr< WaveTrack > &  pTrack,
WaveTrackLocation  location 
)
explicit

Definition at line 25 of file CutlineHandle.cpp.

27  : mpTrack{ pTrack }
28  , mLocation{ location }
29 {
30 }

◆ ~CutlineHandle()

CutlineHandle::~CutlineHandle ( )
virtual

Definition at line 115 of file CutlineHandle.cpp.

116 {
117 }

Member Function Documentation

◆ Cancel()

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

Implements UIHandle.

Definition at line 246 of file CutlineHandle.cpp.

247 {
248  using namespace RefreshCode;
249  UIHandle::Result result = RefreshCell;
250  ProjectHistory::Get( *pProject ).RollbackState();
251  if (mOperation == Expand) {
252  AudacityProject &project = *pProject;
253  auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
254  selectedRegion.setTimes( mStartTime, mEndTime );
255  }
256  return result;
257 }

References Expand, ViewInfo::Get(), ProjectHistory::Get(), mEndTime, mOperation, mStartTime, RefreshCode::RefreshCell, ProjectHistory::RollbackState(), ViewInfo::selectedRegion, and NotifyingSelectedRegion::setTimes().

Here is the call graph for this function:

◆ Click()

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

Someone has just clicked the mouse. What do we do?

Implements UIHandle.

Definition at line 124 of file CutlineHandle.cpp.

126 {
127  using namespace RefreshCode;
128  const bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
129  if ( unsafe )
130  return Cancelled;
131 
132  const wxMouseEvent &event = evt.event;
133  auto &viewInfo = ViewInfo::Get( *pProject );
134 
135  // Can affect the track by merging clips, expanding a cutline, or
136  // deleting a cutline.
137  // All the change is done at button-down. Button-up just commits the undo item.
138 
140 
141  // FIXME: Disable this and return true when CutLines aren't showing?
142  // (Don't use gPrefs-> for the fix as registry access is slow).
143 
144  // Cutline data changed on either branch, so refresh the track display.
145  UIHandle::Result result = RefreshCell;
146 
147  if (event.LeftDown())
148  {
150  {
151  mOperation = Expand;
152  mStartTime = viewInfo.selectedRegion.t0();
153  mEndTime = viewInfo.selectedRegion.t1();
154 
155  // When user presses left button on cut line, expand the line again
156  double cutlineStart = 0, cutlineEnd = 0;
157  double *pCutlineStart = &cutlineStart, *pCutlineEnd = &cutlineEnd;
158 
159  for (auto channel :
160  TrackList::Channels(mpTrack.get())) {
161  channel->ExpandCutLine(
162  mLocation.pos, pCutlineStart, pCutlineEnd);
163  if ( channel == mpTrack.get() )
164  pCutlineStart = pCutlineEnd = nullptr;
165  }
166 
167  viewInfo.selectedRegion.setTimes(cutlineStart, cutlineEnd);
168  }
170  const double pos = mLocation.pos;
171  for (auto channel :
172  TrackList::Channels(mpTrack.get())) {
173  // Don't assume correspondence of merge points across channels!
174  int idx = FindMergeLine(channel, pos);
175  if (idx >= 0) {
176  WaveTrack::Location location =
177  channel->GetCachedLocations()[idx];
178  channel->MergeClips(
179  location.clipidx1, location.clipidx2);
180  }
181  }
182 
183  mOperation = Merge;
184  }
185  }
186  else if (event.RightDown())
187  {
188  bool removed = false;
189  for (auto channel :
191  removed = channel->RemoveCutLine(mLocation.pos) || removed;
192 
193  if (!removed)
194  // Nothing happened, make no Undo item
195  return Cancelled;
196 
197  mOperation = Remove;
198  }
199  else
200  result = RefreshNone;
201 
202  return result;
203 }

References RefreshCode::Cancelled, TrackList::Channels(), WaveTrackLocation::clipidx1, WaveTrackLocation::clipidx2, TrackPanelMouseEvent::event, Expand, anonymous_namespace{CutlineHandle.cpp}::FindMergeLine(), ViewInfo::Get(), ProjectAudioIO::Get(), ProjectAudioIO::IsAudioActive(), WaveTrackLocation::locationCutLine, WaveTrackLocation::locationMergePoint, mEndTime, Merge, mLocation, mOperation, mpTrack, mStartTime, WaveTrackLocation::pos, RefreshCode::RefreshCell, RefreshCode::RefreshNone, Remove, and WaveTrackLocation::typ.

Here is the call graph for this function:

◆ Drag()

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

Implements UIHandle.

Definition at line 205 of file CutlineHandle.cpp.

207 {
209 }

References RefreshCode::RefreshNone.

◆ Enter()

void CutlineHandle::Enter ( bool  forward,
AudacityProject  
)
overridevirtual

Reimplemented from UIHandle.

Definition at line 32 of file CutlineHandle.cpp.

33 {
34 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
36 #endif
37 }

References UIHandle::mChangeHighlight, and RefreshCode::RefreshCell.

◆ GetLocation()

const WaveTrackLocation& CutlineHandle::GetLocation ( )
inline

Definition at line 43 of file CutlineHandle.h.

43 { return mLocation; }

References mLocation.

◆ GetTrack()

std::shared_ptr<WaveTrack> CutlineHandle::GetTrack ( )
inline

Definition at line 44 of file CutlineHandle.h.

44 { return mpTrack; }

References mpTrack.

Referenced by WaveTrackSubView::DrawBoldBoundaries().

Here is the caller graph for this function:

◆ HandlesRightClick()

bool CutlineHandle::HandlesRightClick ( )
overridevirtual

Whether the handle has any special right-button handling.

If not, then Click() will not be called for right click. Default is always false

Reimplemented from UIHandle.

Definition at line 119 of file CutlineHandle.cpp.

120 {
121  return true;
122 }

◆ HitAnywhere()

static UIHandlePtr CutlineHandle::HitAnywhere ( const AudacityProject pProject,
bool  cutline,
UIHandlePtr  ptr 
)
static

◆ HitPreview()

HitTestPreview CutlineHandle::HitPreview ( bool  cutline,
bool  unsafe 
)
staticprivate

Definition at line 39 of file CutlineHandle.cpp.

40 {
41  static auto disabledCursor =
42  ::MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
43  static wxCursor arrowCursor{ wxCURSOR_ARROW };
44  return {
45  (cutline
46  ? XO("Left-Click to expand, Right-Click to remove")
47  : XO("Left-Click to merge clips")),
48  (unsafe
49  ? &*disabledCursor
50  : &arrowCursor)
51  };
52 }

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 CutlineHandle::HitTest ( std::weak_ptr< CutlineHandle > &  holder,
const wxMouseState &  state,
const wxRect &  rect,
const AudacityProject pProject,
const std::shared_ptr< WaveTrack > &  pTrack 
)
static

method that tells us if the mouse event landed on an editable Cutline

Definition at line 96 of file CutlineHandle.cpp.

101 {
102  auto &viewInfo = ViewInfo::Get( *pProject );
105 
106  WaveTrackLocation location;
107  if (!IsOverCutline(viewInfo, pTrack.get(), rect, state, &location))
108  return {};
109 
110  auto result = std::make_shared<CutlineHandle>( pTrack, location );
111  result = AssignUIHandlePtr( holder, result );
112  return result;
113 }

References AssignUIHandlePtr(), ViewInfo::Get(), and anonymous_namespace{CutlineHandle.cpp}::IsOverCutline().

Here is the call graph for this function:

◆ operator=()

CutlineHandle& CutlineHandle::operator= ( const CutlineHandle )
default

◆ Preview()

HitTestPreview CutlineHandle::Preview ( const TrackPanelMouseState state,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 211 of file CutlineHandle.cpp.

213 {
214  const bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
215  auto bCutline = (mLocation.typ == WaveTrackLocation::locationCutLine);
216  return HitPreview( bCutline, unsafe );
217 }

References ProjectAudioIO::Get(), HitPreview(), ProjectAudioIO::IsAudioActive(), WaveTrackLocation::locationCutLine, mLocation, and WaveTrackLocation::typ.

Here is the call graph for this function:

◆ Release()

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

Implements UIHandle.

Definition at line 219 of file CutlineHandle.cpp.

221 {
223 
224  // Only now commit the result to the undo stack
225  switch (mOperation) {
226  default:
227  wxASSERT(false);
228  case Merge:
229  ProjectHistory::Get( *pProject )
230  .PushState(XO("Merged Clips"), XO("Merge"), UndoPush::CONSOLIDATE);
231  break;
232  case Expand:
233  ProjectHistory::Get( *pProject )
234  .PushState(XO("Expanded Cut Line"), XO("Expand"));
235  break;
236  case Remove:
237  ProjectHistory::Get( *pProject )
238  .PushState(XO("Removed Cut Line"), XO("Remove"));
239  break;
240  }
241 
242  // Nothing to do for the display
243  return result;
244 }

References CONSOLIDATE, Expand, ProjectHistory::Get(), Merge, mOperation, ProjectHistory::PushState(), RefreshCode::RefreshNone, Remove, and XO.

Here is the call graph for this function:

◆ StopsOnKeystroke()

bool CutlineHandle::StopsOnKeystroke ( )
inlineoverridevirtual

Reimplemented from UIHandle.

Definition at line 66 of file CutlineHandle.h.

66 { return true; }

Member Data Documentation

◆ mEndTime

double CutlineHandle::mEndTime {}
private

Definition at line 72 of file CutlineHandle.h.

Referenced by Cancel(), and Click().

◆ mLocation

WaveTrackLocation CutlineHandle::mLocation {}
private

Definition at line 73 of file CutlineHandle.h.

Referenced by Click(), GetLocation(), and Preview().

◆ mOperation

Operation CutlineHandle::mOperation { Merge }
private

Definition at line 71 of file CutlineHandle.h.

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

◆ mpTrack

std::shared_ptr<WaveTrack> CutlineHandle::mpTrack {}
private

Definition at line 69 of file CutlineHandle.h.

Referenced by Click(), and GetTrack().

◆ mStartTime

double CutlineHandle::mStartTime {}
private

Definition at line 72 of file CutlineHandle.h.

Referenced by Cancel(), and Click().


The documentation for this class was generated from the following files:
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:259
WaveTrackLocation::clipidx2
int clipidx2
Definition: WaveTrackLocation.h:36
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
WaveTrackLocation::typ
LocationType typ
Definition: WaveTrackLocation.h:32
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1505
MakeCursor
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:182
CutlineHandle::Merge
@ Merge
Definition: CutlineHandle.h:70
WaveTrackLocation::locationMergePoint
@ locationMergePoint
Definition: WaveTrackLocation.h:18
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
XO
#define XO(s)
Definition: Internat.h:31
WaveTrackLocation
Definition: WaveTrackLocation.h:14
ProjectAudioIO::Get
static ProjectAudioIO & Get(AudacityProject &project)
Definition: ProjectAudioIO.cpp:22
CutlineHandle::mStartTime
double mStartTime
Definition: CutlineHandle.h:72
CutlineHandle::mEndTime
double mEndTime
Definition: CutlineHandle.h:72
ProjectAudioIO::IsAudioActive
bool IsAudioActive() const
Definition: ProjectAudioIO.cpp:51
CutlineHandle::mOperation
Operation mOperation
Definition: CutlineHandle.h:71
NotifyingSelectedRegion::setTimes
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:63
CutlineHandle::Remove
@ Remove
Definition: CutlineHandle.h:70
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:238
UIHandle::mChangeHighlight
Result mChangeHighlight
Definition: UIHandle.h:139
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
CutlineHandle::HitPreview
static HitTestPreview HitPreview(bool cutline, bool unsafe)
Definition: CutlineHandle.cpp:39
anonymous_namespace{CutlineHandle.cpp}::IsOverCutline
bool IsOverCutline(const ViewInfo &viewInfo, WaveTrack *track, const wxRect &rect, const wxMouseState &state, WaveTrackLocation *pmLocation)
Definition: CutlineHandle.cpp:69
RefreshCode::RefreshCell
@ RefreshCell
Definition: RefreshCode.h:24
CutlineHandle::mpTrack
std::shared_ptr< WaveTrack > mpTrack
Definition: CutlineHandle.h:69
anonymous_namespace{CutlineHandle.cpp}::FindMergeLine
int FindMergeLine(WaveTrack *track, double time)
Definition: CutlineHandle.cpp:55
CutlineHandle::mLocation
WaveTrackLocation mLocation
Definition: CutlineHandle.h:73
ProjectHistory::PushState
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
Definition: ProjectHistory.cpp:90
ProjectHistory::RollbackState
void RollbackState()
Definition: ProjectHistory.cpp:117
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
UndoPush::CONSOLIDATE
@ CONSOLIDATE
WaveTrackLocation::locationCutLine
@ locationCutLine
Definition: WaveTrackLocation.h:17
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
WaveTrackLocation::pos
double pos
Definition: WaveTrackLocation.h:29
WaveTrackLocation::clipidx1
int clipidx1
Definition: WaveTrackLocation.h:35
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
CutlineHandle::Expand
@ Expand
Definition: CutlineHandle.h:70