Audacity  2.2.2
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:
UIHandle

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) override
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, const 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 ()
 
virtual void DrawExtras (DrawingPass pass, wxDC *dc, const wxRegion &updateRegion, const wxRect &panelRect)
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 

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 &)
 

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
enum  DrawingPass { Cells, Panel }
 
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 23 of file CutlineHandle.h.

Member Enumeration Documentation

Enumerator
Merge 
Expand 
Remove 

Definition at line 70 of file CutlineHandle.h.

Constructor & Destructor Documentation

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

Definition at line 28 of file CutlineHandle.cpp.

29  : mpTrack{ pTrack }
30  , mLocation{ location }
31 {
32 }
std::shared_ptr< WaveTrack > mpTrack
Definition: CutlineHandle.h:69
WaveTrackLocation mLocation
Definition: CutlineHandle.h:73
CutlineHandle::~CutlineHandle ( )
virtual

Definition at line 120 of file CutlineHandle.cpp.

121 {
122 }

Member Function Documentation

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

Implements UIHandle.

Definition at line 244 of file CutlineHandle.cpp.

References Expand, mEndTime, mOperation, mStartTime, RefreshCode::RefreshCell, AudacityProject::RollbackState(), AudacityProject::SetSel0(), AudacityProject::SetSel1(), and RefreshCode::UpdateSelection.

245 {
246  using namespace RefreshCode;
247  UIHandle::Result result = RefreshCell;
248  pProject->RollbackState();
249  if (mOperation == Expand) {
250  AudacityProject *const project = pProject;
251  project->SetSel0(mStartTime);
252  project->SetSel1(mEndTime);
253  result |= UpdateSelection;
254  }
255  return result;
256 }
Operation mOperation
Definition: CutlineHandle.h:71
void SetSel1(double)
Definition: Project.cpp:1411
void SetSel0(double)
Definition: Project.cpp:1404
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
unsigned Result
Definition: UIHandle.h:37
void RollbackState()
Definition: Project.cpp:4742
double mStartTime
Definition: CutlineHandle.h:72
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 125 of file CutlineHandle.cpp.

References RefreshCode::Cancelled, TrackPanelMouseEvent::event, AudacityProject::GetViewInfo(), AudacityProject::IsAudioActive(), WaveTrackLocation::locationCutLine, WaveTrackLocation::locationMergePoint, RefreshCode::RefreshCell, RefreshCode::RefreshNone, ViewInfo::selectedRegion, SelectedRegion::setTimes(), SelectedRegion::t0(), SelectedRegion::t1(), and RefreshCode::UpdateSelection.

126 {
127  using namespace RefreshCode;
128  const bool unsafe = pProject->IsAudioActive();
129  if ( unsafe )
130  return Cancelled;
131 
132  const wxMouseEvent &event = evt.event;
133  ViewInfo &viewInfo = pProject->GetViewInfo();
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  // Assume linked track is wave or null
147  const auto linked = static_cast<WaveTrack*>(mpTrack->GetLink());
148 
149  if (event.LeftDown())
150  {
152  {
153  mOperation = Expand;
154  mStartTime = viewInfo.selectedRegion.t0();
155  mEndTime = viewInfo.selectedRegion.t1();
156 
157  // When user presses left button on cut line, expand the line again
158  double cutlineStart = 0, cutlineEnd = 0;
159 
160  mpTrack->ExpandCutLine(mLocation.pos, &cutlineStart, &cutlineEnd);
161 
162  if (linked)
163  // Expand the cutline in the opposite channel if it is present.
164  linked->ExpandCutLine(mLocation.pos);
165 
166  viewInfo.selectedRegion.setTimes(cutlineStart, cutlineEnd);
167  result |= UpdateSelection;
168  }
170  const double pos = mLocation.pos;
172 
173  if (linked) {
174  // Don't assume correspondence of merge points across channels!
175  int idx = FindMergeLine(linked, pos);
176  if (idx >= 0) {
177  WaveTrack::Location location = linked->GetCachedLocations()[idx];
178  linked->MergeClips(location.clipidx1, location.clipidx2);
179  }
180  }
181 
182  mOperation = Merge;
183  }
184  }
185  else if (event.RightDown())
186  {
187  bool removed = mpTrack->RemoveCutLine(mLocation.pos);
188 
189  if (linked)
190  removed = linked->RemoveCutLine(mLocation.pos) || removed;
191 
192  if (!removed)
193  // Nothing happened, make no Undo item
194  return Cancelled;
195 
196  mOperation = Remove;
197  }
198  else
199  result = RefreshNone;
200 
201  return result;
202 }
Operation mOperation
Definition: CutlineHandle.h:71
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
std::shared_ptr< WaveTrack > mpTrack
Definition: CutlineHandle.h:69
WaveTrackLocation mLocation
Definition: CutlineHandle.h:73
unsigned Result
Definition: UIHandle.h:37
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
double mStartTime
Definition: CutlineHandle.h:72
bool IsAudioActive() const
Definition: Project.cpp:1454
Used only by WaveTrack, a special way to hold location that can accommodate merged regions...
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
UIHandle::Result CutlineHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 205 of file CutlineHandle.cpp.

References RefreshCode::RefreshNone.

206 {
208 }
void CutlineHandle::Enter ( bool  forward)
overridevirtual

Reimplemented from UIHandle.

Definition at line 34 of file CutlineHandle.cpp.

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

35 {
36 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
38 #endif
39 }
Result mChangeHighlight
Definition: UIHandle.h:150
const WaveTrackLocation& CutlineHandle::GetLocation ( )
inline

Definition at line 45 of file CutlineHandle.h.

References mLocation.

45 { return mLocation; }
WaveTrackLocation mLocation
Definition: CutlineHandle.h:73
std::shared_ptr<WaveTrack> CutlineHandle::GetTrack ( )
inline

Definition at line 46 of file CutlineHandle.h.

References mpTrack.

Referenced by TrackArtist::DrawWaveform().

46 { return mpTrack; }
std::shared_ptr< WaveTrack > mpTrack
Definition: CutlineHandle.h:69
static UIHandlePtr CutlineHandle::HitAnywhere ( const AudacityProject pProject,
bool  cutline,
UIHandlePtr  ptr 
)
static
HitTestPreview CutlineHandle::HitPreview ( bool  cutline,
bool  unsafe 
)
staticprivate

Definition at line 41 of file CutlineHandle.cpp.

References _(), and MakeCursor().

42 {
43  static auto disabledCursor =
44  ::MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
45  static wxCursor arrowCursor{ wxCURSOR_ARROW };
46  return {
47  (cutline
48  ? _("Left-Click to expand, Right-Click to remove")
49  : _("Left-Click to merge clips")),
50  (unsafe
51  ? &*disabledCursor
52  : &arrowCursor)
53  };
54 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:274
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 99 of file CutlineHandle.cpp.

References AssignUIHandlePtr(), AudacityProject::GetViewInfo(), and Track::Wave.

Referenced by WaveTrack::DetailedHitTest().

103 {
104  const ViewInfo &viewInfo = pProject->GetViewInfo();
107  if (pTrack->GetKind() != Track::Wave)
108  return {};
109 
110  WaveTrack *wavetrack = pTrack.get();
111  WaveTrackLocation location;
112  if (!IsOverCutline(viewInfo, wavetrack, rect, state, &location))
113  return {};
114 
115  auto result = std::make_shared<CutlineHandle>( pTrack, location );
116  result = AssignUIHandlePtr( holder, result );
117  return result;
118 }
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162
CutlineHandle& CutlineHandle::operator= ( const CutlineHandle )
default
HitTestPreview CutlineHandle::Preview ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 211 of file CutlineHandle.cpp.

References AudacityProject::IsAudioActive(), and WaveTrackLocation::locationCutLine.

212 {
213  const bool unsafe = pProject->IsAudioActive();
214  auto bCutline = (mLocation.typ == WaveTrackLocation::locationCutLine);
215  return HitPreview( bCutline, unsafe );
216 }
WaveTrackLocation mLocation
Definition: CutlineHandle.h:73
bool IsAudioActive() const
Definition: Project.cpp:1454
static HitTestPreview HitPreview(bool cutline, bool unsafe)
UIHandle::Result CutlineHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Implements UIHandle.

Definition at line 219 of file CutlineHandle.cpp.

References _(), CONSOLIDATE, AudacityProject::PushState(), RefreshCode::RefreshNone, and RefreshCode::UpdateSelection.

220 {
222 
223  // Only now commit the result to the undo stack
224  AudacityProject *const project = pProject;
225  switch (mOperation) {
226  default:
227  wxASSERT(false);
228  case Merge:
229  project->PushState(_("Merged Clips"), _("Merge"), UndoPush::CONSOLIDATE);
230  break;
231  case Expand:
232  project->PushState(_("Expanded Cut Line"), _("Expand"));
234  break;
235  case Remove:
236  project->PushState(_("Removed Cut Line"), _("Remove"));
237  break;
238  }
239 
240  // Nothing to do for the display
241  return result;
242 }
Operation mOperation
Definition: CutlineHandle.h:71
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
unsigned Result
Definition: UIHandle.h:37
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4702
bool CutlineHandle::StopsOnKeystroke ( )
inlineoverridevirtual

Reimplemented from UIHandle.

Definition at line 66 of file CutlineHandle.h.

66 { return true; }

Member Data Documentation

double CutlineHandle::mEndTime {}
private

Definition at line 72 of file CutlineHandle.h.

Referenced by Cancel().

WaveTrackLocation CutlineHandle::mLocation {}
private

Definition at line 73 of file CutlineHandle.h.

Referenced by GetLocation().

Operation CutlineHandle::mOperation { Merge }
private

Definition at line 71 of file CutlineHandle.h.

Referenced by Cancel().

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

Definition at line 69 of file CutlineHandle.h.

Referenced by GetTrack().

double CutlineHandle::mStartTime {}
private

Definition at line 72 of file CutlineHandle.h.

Referenced by Cancel().


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