Audacity  3.0.3
SelectHandle.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 SelectHandle.h
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_SELECT_HANDLE__
12 #define __AUDACITY_SELECT_HANDLE__
13 
14 #include "../../UIHandle.h"
15 #include "SelectedRegion.h"
16 #include "../../Snap.h"
17 
18 #include <vector>
19 
21 class SnapManager;
22 class SpectrumAnalyst;
23 class Track;
24 class TrackView;
25 class TrackList;
26 class ViewInfo;
27 class WaveTrack;
28 class wxMouseState;
29 
30 class AUDACITY_DLL_API SelectHandle : public UIHandle
31 {
33 
34 public:
35  explicit SelectHandle
36  (const std::shared_ptr<TrackView> &pTrackView, bool useSnap,
37  const TrackList &trackList,
38  const TrackPanelMouseState &st, const ViewInfo &viewInfo);
39 
40  // This always hits, but details of the hit vary with mouse position and
41  // key state.
42  static UIHandlePtr HitTest
43  (std::weak_ptr<SelectHandle> &holder,
44  const TrackPanelMouseState &state, const AudacityProject *pProject,
45  const std::shared_ptr<TrackView> &pTrackView);
46 
47  SelectHandle &operator=(const SelectHandle&) = default;
48 
49  virtual ~SelectHandle();
50 
51  bool IsClicked() const;
52 
53  void SetUseSnap(bool use, AudacityProject *pProject);
54  void Enter(bool forward, AudacityProject *pProject) override;
55 
56  bool HasSnap() const;
57  bool HasEscape(AudacityProject *pProject) const override;
58 
59  bool Escape(AudacityProject *pProject) override;
60 
62  (const TrackPanelMouseEvent &event, AudacityProject *pProject) override;
63 
64  Result Drag
65  (const TrackPanelMouseEvent &event, AudacityProject *pProject) override;
66 
68  (const TrackPanelMouseState &state, AudacityProject *pProject)
69  override;
70 
72  (const TrackPanelMouseEvent &event, AudacityProject *pProject,
73  wxWindow *pParent) override;
74 
75  Result Cancel(AudacityProject*) override;
76 
78  (const SelectHandle &oldState,
79  const SelectHandle &newState);
80 
81 private:
82  std::weak_ptr<Track> FindTrack();
83 
84  void Connect(AudacityProject *pProject);
85 
86  void StartSelection(AudacityProject *pProject);
87  void AdjustSelection
88  (AudacityProject *pProject,
89  ViewInfo &viewInfo, int mouseXCoordinate, int trackLeftEdge,
90  Track *pTrack);
91  void AssignSelection(ViewInfo &viewInfo, double selend, Track *pTrack);
92 
93  void StartFreqSelection
94  (ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge,
95  int trackHeight, TrackView *pTrackView);
96  void AdjustFreqSelection
97  (const WaveTrack *wt,
98  ViewInfo &viewInfo, int mouseYCoordinate, int trackTopEdge,
99  int trackHeight);
100 
101  void HandleCenterFrequencyClick
102  (const ViewInfo &viewInfo, bool shiftDown,
103  const WaveTrack *pTrack, double value);
104  static void StartSnappingFreqSelection
105  (SpectrumAnalyst &analyst,
106  const ViewInfo &viewInfo, const WaveTrack *pTrack);
107  void MoveSnappingFreqSelection
108  (AudacityProject *pProject, ViewInfo &viewInfo, int mouseYCoordinate,
109  int trackTopEdge,
110  int trackHeight, TrackView *pTrackView);
111 public:
112  // This is needed to implement a command assignable to keystrokes
113  static void SnapCenterOnce
114  (SpectrumAnalyst &analyst,
115  ViewInfo &viewInfo, const WaveTrack *pTrack, bool up);
116 private:
117 
118  // TrackPanelDrawable implementation
119  void Draw(
120  TrackPanelDrawingContext &context,
121  const wxRect &rect, unsigned iPass ) override;
122 
123  wxRect DrawingArea(
125  const wxRect &rect, const wxRect &panelRect, unsigned iPass ) override;
126 
127  //void ResetFreqSelectionPin
128  // (const ViewInfo &viewInfo, double hintFrequency, bool logF);
129 
130 
131  std::weak_ptr<TrackView> mpView;
132  wxRect mRect{};
133  SelectedRegion mInitialSelection{};
134 
135  std::shared_ptr<SnapManager> mSnapManager;
137  bool mUseSnap{ true };
138 
139  bool mSelStartValid{};
140  double mSelStart{ 0.0 };
141 
142  int mSelectionBoundary{ 0 };
143 
146 
150 
154  } mFreqSelMode{ FREQ_SEL_INVALID };
155  std::weak_ptr<const WaveTrack> mFreqSelTrack;
156  // Following holds:
157  // the center for FREQ_SEL_PINNED_CENTER,
158  // the ratio of top to center (== center to bottom) for FREQ_SEL_DRAG_CENTER,
159  // a frequency boundary for FREQ_SEL_FREE, FREQ_SEL_TOP_FREE, or
160  // FREQ_SEL_BOTTOM_FREE,
161  // and is ignored otherwise.
162  double mFreqSelPin{ -1.0 };
163  std::shared_ptr<SpectrumAnalyst> mFrequencySnapper;
164 
165  int mMostRecentX{ -1 }, mMostRecentY{ -1 };
166 
167  bool mAutoScrolling{};
168 
169  std::shared_ptr<SelectionStateChanger> mSelectionStateChanger;
170 
171  class TimerHandler;
172  friend TimerHandler;
173  std::shared_ptr<TimerHandler> mTimerHandler;
174 };
175 #endif
SelectHandle::mSelectionStateChanger
std::shared_ptr< SelectionStateChanger > mSelectionStateChanger
Definition: SelectHandle.h:169
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:70
UIHandle::Preview
virtual HitTestPreview Preview(const TrackPanelMouseState &state, AudacityProject *pProject)=0
SelectHandle::FREQ_SEL_SNAPPING_CENTER
@ FREQ_SEL_SNAPPING_CENTER
Definition: SelectHandle.h:147
SelectHandle::FREQ_SEL_FREE
@ FREQ_SEL_FREE
Definition: SelectHandle.h:151
SelectHandle::FREQ_SEL_INVALID
@ FREQ_SEL_INVALID
Definition: SelectHandle.h:145
SelectHandle::operator=
SelectHandle & operator=(const SelectHandle &)=default
SelectHandle::TimerHandler
friend TimerHandler
Definition: SelectHandle.h:171
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
SelectHandle::mFreqSelTrack
std::weak_ptr< const WaveTrack > mFreqSelTrack
Definition: SelectHandle.h:155
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1310
ViewInfo
Definition: ViewInfo.h:211
SelectionStateChanger
Definition: SelectionState.h:56
SelectedRegion.h
TrackPanelDrawable::DrawingArea
virtual wxRect DrawingArea(TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
Definition: TrackPanelDrawable.cpp:22
SelectHandle::FREQ_SEL_TOP_FREE
@ FREQ_SEL_TOP_FREE
Definition: SelectHandle.h:152
SnapResults
Definition: Snap.h:45
SelectHandle::mTimerHandler
std::shared_ptr< TimerHandler > mTimerHandler
Definition: SelectHandle.h:173
SelectHandle::FREQ_SEL_PINNED_CENTER
@ FREQ_SEL_PINNED_CENTER
Definition: SelectHandle.h:148
UIHandle
Short-lived drawing and event-handling object associated with a TrackPanelCell.
Definition: UIHandle.h:35
SpectrumAnalyst
Used for finding the peaks, for snapping to peaks.
Definition: SpectrumAnalyst.h:21
SelectHandle::FREQ_SEL_BOTTOM_FREE
@ FREQ_SEL_BOTTOM_FREE
Definition: SelectHandle.h:153
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
SelectHandle::mpView
std::weak_ptr< TrackView > mpView
Definition: SelectHandle.h:131
SelectHandle
Definition: SelectHandle.h:31
UIHandle::Click
virtual Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
UIHandle::Cancel
virtual Result Cancel(AudacityProject *pProject)=0
HitTestPreview
Definition: HitTestResult.h:20
SelectHandle::SelectHandle
SelectHandle(const SelectHandle &)
anonymous_namespace{TrackPanel.cpp}::FindTrack
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:530
SelectHandle::TimerHandler
Definition: SelectHandle.cpp:1059
UIHandle::HasEscape
virtual bool HasEscape(AudacityProject *pProject) const
Definition: UIHandle.cpp:34
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:224
TrackView
Definition: TrackView.h:25
SelectHandle::mFrequencySnapper
std::shared_ptr< SpectrumAnalyst > mFrequencySnapper
Definition: SelectHandle.h:163
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
TrackPanelMouseEvent
Definition: TrackPanelMouseEvent.h:46
SnapManager
Definition: Snap.h:56
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
UIHandle::NeedChangeHighlight
static UIHandle::Result NeedChangeHighlight(const UIHandle &, const UIHandle &)
Definition: UIHandle.h:130
UIHandle::Enter
virtual void Enter(bool forward, AudacityProject *pProject)
Definition: UIHandle.cpp:20
UIHandle::Drag
virtual Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
UIHandle::Release
virtual Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
UIHandle::Escape
virtual bool Escape(AudacityProject *pProject)
Definition: UIHandle.cpp:39
SelectHandle::mSnapStart
SnapResults mSnapStart
Definition: SelectHandle.h:136
SelectHandle::mSnapManager
std::shared_ptr< SnapManager > mSnapManager
Definition: SelectHandle.h:135
SelectHandle::eFreqSelMode
eFreqSelMode
Definition: SelectHandle.h:144
SelectHandle::FREQ_SEL_DRAG_CENTER
@ FREQ_SEL_DRAG_CENTER
Definition: SelectHandle.h:149
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:38
TrackPanelDrawable::Draw
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
Definition: TrackPanelDrawable.cpp:17