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