Audacity 3.2.0
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 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 (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.

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}
WaveTrackLocation mLocation
Definition: CutlineHandle.h:73
std::shared_ptr< WaveTrack > mpTrack
Definition: CutlineHandle.h:69

◆ ~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;
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}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Operation mOperation
Definition: CutlineHandle.h:71
double mStartTime
Definition: CutlineHandle.h:72
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:51
static ProjectHistory & Get(AudacityProject &project)
unsigned Result
Definition: UIHandle.h:38
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16

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 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.
146
147 if (event.LeftDown())
148 {
150 {
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 :
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 :
173 // Don't assume correspondence of merge points across channels!
174 int idx = FindMergeLine(channel, pos);
175 if (idx >= 0) {
176 auto location =
177 WaveTrackLocations::Get(*channel).Get()[idx];
178 channel->MergeClips(
179 location.clipidx1, location.clipidx2);
180 }
181 }
182
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
198 }
199 else
200 result = RefreshNone;
201
202 return result;
203}
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1544
const std::vector< Location > & Get() const
int FindMergeLine(WaveTrack *track, double time)

References RefreshCode::Cancelled, TrackList::Channels(), TrackPanelMouseEvent::event, Expand, anonymous_namespace{CutlineHandle.cpp}::FindMergeLine(), WaveTrackLocations::Get(), 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 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}
Result mChangeHighlight
Definition: UIHandle.h:139

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}
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:186

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}
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
bool IsOverCutline(const ViewInfo &viewInfo, WaveTrack *track, const wxRect &rect, const wxMouseState &state, WaveTrackLocation *pmLocation)

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

Referenced by WaveTrackSubView::DoDetailedHitTest().

Here is the call graph for this function:
Here is the caller 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();
216 return HitPreview( bCutline, unsafe );
217}
static HitTestPreview HitPreview(bool cutline, bool unsafe)

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}
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)

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: