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
 
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 () 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 68 of file CutlineHandle.h.

68 { 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 241 of file CutlineHandle.cpp.

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

References Expand, ProjectHistory::Get(), ViewInfo::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 119 of file CutlineHandle.cpp.

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

References Cancelled, TrackList::Channels(), WaveTrackLocation::clipidx1, WaveTrackLocation::clipidx2, TrackPanelMouseEvent::event, Expand, anonymous_namespace{CutlineHandle.cpp}::FindMergeLine(), ProjectAudioIO::Get(), ViewInfo::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 200 of file CutlineHandle.cpp.

202 {
204 }

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:

◆ 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 206 of file CutlineHandle.cpp.

208 {
209  const bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
210  auto bCutline = (mLocation.typ == WaveTrackLocation::locationCutLine);
211  return HitPreview( bCutline, unsafe );
212 }

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 214 of file CutlineHandle.cpp.

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

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

64 { return true; }

Member Data Documentation

◆ mEndTime

double CutlineHandle::mEndTime {}
private

Definition at line 70 of file CutlineHandle.h.

Referenced by Cancel(), and Click().

◆ mLocation

WaveTrackLocation CutlineHandle::mLocation {}
private

Definition at line 71 of file CutlineHandle.h.

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

◆ mOperation

Operation CutlineHandle::mOperation { Merge }
private

Definition at line 69 of file CutlineHandle.h.

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

◆ mpTrack

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

Definition at line 67 of file CutlineHandle.h.

Referenced by Click(), and GetTrack().

◆ mStartTime

double CutlineHandle::mStartTime {}
private

Definition at line 70 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:156
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:1467
MakeCursor
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:177
CutlineHandle::Merge
@ Merge
Definition: CutlineHandle.h:68
WaveTrackLocation::locationMergePoint
@ locationMergePoint
Definition: WaveTrackLocation.h:18
XO
#define XO(s)
Definition: Internat.h:31
ProgressResult::Cancelled
@ Cancelled
WaveTrackLocation
Definition: WaveTrackLocation.h:14
ProjectAudioIO::Get
static ProjectAudioIO & Get(AudacityProject &project)
Definition: ProjectAudioIO.cpp:23
CutlineHandle::mStartTime
double mStartTime
Definition: CutlineHandle.h:70
CutlineHandle::mEndTime
double mEndTime
Definition: CutlineHandle.h:70
ProjectAudioIO::IsAudioActive
bool IsAudioActive() const
Definition: ProjectAudioIO.cpp:52
CutlineHandle::mOperation
Operation mOperation
Definition: CutlineHandle.h:69
NotifyingSelectedRegion::setTimes
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:57
CutlineHandle::Remove
@ Remove
Definition: CutlineHandle.h:68
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:199
UIHandle::mChangeHighlight
Result mChangeHighlight
Definition: UIHandle.h:133
UIHandle::Result
unsigned Result
Definition: UIHandle.h:37
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:67
anonymous_namespace{CutlineHandle.cpp}::FindMergeLine
int FindMergeLine(WaveTrack *track, double time)
Definition: CutlineHandle.cpp:55
CutlineHandle::mLocation
WaveTrackLocation mLocation
Definition: CutlineHandle.h:71
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:112
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:145
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:68