Audacity 3.2.0
AdornedRulerPanel.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 AdornedRulerPanel.h
6
7 Dominic Mazzoni
8
9**********************************************************************/
10
11#ifndef __AUDACITY_ADORNED_RULER_PANEL__
12#define __AUDACITY_ADORNED_RULER_PANEL__
13
14#include "CellularPanel.h"
15#include "widgets/Ruler.h" // member variable
16#include "Observer.h"
17#include "Prefs.h"
18#include "ViewInfo.h" // for PlayRegion
19
20class AudacityProject;
21struct AudioIOEvent;
22struct SelectedRegionEvent;
23class TrackList;
24
25// This is an Audacity Specific ruler panel.
26class AUDACITY_DLL_API AdornedRulerPanel final
27: public CellularPanel
28, private PrefsListener
29{
30public:
31 static AdornedRulerPanel &Get( AudacityProject &project );
32 static const AdornedRulerPanel &Get( const AudacityProject &project );
33 static void Destroy( AudacityProject &project );
34
36 wxWindow* parent,
37 wxWindowID id,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize,
40 ViewInfo *viewinfo = NULL);
41
43
44 void Refresh
45 (bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
46 override;
47
48 bool AcceptsFocus() const override { return s_AcceptsFocus; }
49 bool AcceptsFocusFromKeyboard() const override { return true; }
50 void SetFocusFromKbd() override;
51
52public:
53 int GetRulerHeight() { return GetRulerHeight( ShowingScrubRuler() ); }
54 static int GetRulerHeight(bool showScrubBar);
55 wxRect GetInnerRect() const { return mInner; }
56
57 void SetLeftOffset(int offset);
58
59 void DrawSelection();
60
61 void SetPlayRegion(double playRegionStart, double playRegionEnd);
62 void ClearPlayRegion();
63 void TogglePinnedHead();
64
65 void GetMaxSize(wxCoord *width, wxCoord *height);
66
67 void InvalidateRuler();
68
69 void UpdatePrefs() override;
70 void ReCreateButtons();
71
72 void UpdateQuickPlayPos(wxCoord &mousePosX);
73
74 bool ShowingScrubRuler() const;
75 //void OnToggleScrubRulerFromMenu(wxCommandEvent& );
76 bool SetPanelSize();
77
78 void DrawBothOverlays();
79
80
81private:
82 void DoIdle();
83 void OnIdle( wxIdleEvent &evt );
84 void OnAudioStartStop(AudioIOEvent);
85 void OnPaint(wxPaintEvent &evt);
86 void OnSize(wxSizeEvent &evt);
87 void OnLeave(wxMouseEvent &evt);
88 void OnThemeChange(struct ThemeChangeMessage);
89 void OnSelectionChange(Observer::Message);
90 void DoSelectionChange( const SelectedRegion &selectedRegion );
91 bool UpdateRects();
92 void HandleQPClick(wxMouseEvent &event, wxCoord mousePosX);
93 void HandleQPDrag(wxMouseEvent &event, wxCoord mousePosX);
94 void HandleQPRelease(wxMouseEvent &event);
95 void StartQPPlay(
96 bool newDefault, bool cutPreview, const double *pStartTime = nullptr);
97
98 void DoDrawBackground(wxDC * dc);
99 void DoDrawEdge(wxDC *dc);
100 void DoDrawMarks(wxDC * dc, bool /*text */ );
101 wxRect RegionRectangle(double t0, double t1) const;
102 wxRect PlayRegionRectangle() const;
103 wxRect SelectedRegionRectangle() const;
104 void DoDrawPlayRegion(wxDC * dc,
105 const wxRect &rectP, const wxRect &rectL, const wxRect &rectR);
106 void DoDrawPlayRegionLimits(wxDC * dc, const wxRect &rect);
107 void DoDrawOverlap(wxDC * dc, const wxRect &rect);
108 void DoDrawSelection(wxDC * dc,
109 const wxRect &rectS, const wxRect &rectL, const wxRect &rectR);
110
111public:
112 void DoDrawScrubIndicator(wxDC * dc, wxCoord xx, int width, bool scrub, bool seek);
113 void UpdateButtonStates();
114
115private:
116 static bool s_AcceptsFocus;
117 struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
118 using TempAllowFocus = std::unique_ptr<bool, Resetter>;
119
120public:
121 static TempAllowFocus TemporarilyAllowFocus();
122
123 void SetNumGuides(size_t nn);
124
125private:
126 enum class MenuChoice { QuickPlay, Scrub };
127 void ShowContextMenu( MenuChoice choice, const wxPoint *pPosition);
128
129 double Pos2Time(int p, bool ignoreFisheye = false) const;
130 int Time2Pos(double t, bool ignoreFisheye = false) const;
131
132 bool IsWithinMarker(int mousePosX, double markerTime);
133
134private:
135
139
140 wxRect mOuter;
142 wxRect mInner;
143
144 int mLeftOffset; // Number of pixels before we hit the 'zero position'.
145
146
147 double mIndTime;
148
149 static constexpr size_t MAX_GUIDES = 2;
150 double mQuickPlayOffset[MAX_GUIDES]{};
151 double mQuickPlayPosUnsnapped[MAX_GUIDES]{};
152 double mQuickPlayPos[MAX_GUIDES]{};
153 bool mIsSnapped[MAX_GUIDES]{};
154 size_t mNumGuides{ 1 };
155
157
159
160 //
161 // Pop-up menu
162 //
163 void ShowMenu(const wxPoint & pos);
164 void ShowScrubMenu(const wxPoint & pos);
165 static void DragSelection(AudacityProject &project);
166 void HandleSnapping(size_t index);
167 void OnSyncSelToQuickPlay(wxCommandEvent &evt);
168 //void OnTimelineToolTips(wxCommandEvent &evt);
169 void OnAutoScroll(wxCommandEvent &evt);
170 void OnTogglePlayRegion(wxCommandEvent &evt);
171 void OnClearPlayRegion(wxCommandEvent &evt);
172 void OnSetPlayRegionToSelection(wxCommandEvent &evt);
173
174 void OnPinnedButton(wxCommandEvent & event);
175 void OnTogglePinnedState(wxCommandEvent & event);
176
179
185 mesSelectingPlayRegionRange
186 };
187
189 double mLeftDownClickUnsnapped; // click position in seconds, before snap
190 double mLeftDownClick; // click position in seconds
192
193 DECLARE_EVENT_TABLE()
194
195 wxWindow *mButtons[3];
196 bool mNeedButtonUpdate { true };
197
198 //
199 // CellularPanel implementation
200 //
201
202 // Get the root object defining a recursive subdivision of the panel's
203 // area into cells
204 std::shared_ptr<TrackPanelNode> Root() override;
205public:
206 AudacityProject * GetProject() const override;
207private:
208 TrackPanelCell *GetFocusedCell() override;
209 void SetFocusedCell() override;
211 (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
212 unsigned refreshResult) override;
213
214 void UpdateStatusMessage( const TranslatableString & ) override;
215
216 void CreateOverlays();
217
218 // Cooperating objects
219 class TrackPanelGuidelineOverlay;
220 std::shared_ptr<TrackPanelGuidelineOverlay> mOverlay;
221
223
224private:
225 class CommonRulerHandle;
226 class QPHandle;
231 class ScrubbingHandle;
232
233 class CommonCell;
234
235 class QPCell;
236 std::shared_ptr<QPCell> mQPCell;
237
238 class ScrubbingCell;
239 std::shared_ptr<ScrubbingCell> mScrubbingCell;
240
244
245 // classes implementing subdivision for CellularPanel
246 struct Subgroup;
247 struct MainGroup;
248
250 std::pair<double, double> mLastDrawnPlayRegion{};
251 bool mLastPlayRegionActive = false;
252 double mLastDrawnH{};
253 double mLastDrawnZoom{};
254};
255
256#endif //define __AUDACITY_ADORNED_RULER_PANEL__
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
std::shared_ptr< ScrubbingCell > mScrubbingCell
Observer::Subscription mAudioIOSubscription
AudacityProject *const mProject
bool AcceptsFocus() const override
wxRect GetInnerRect() const
bool AcceptsFocusFromKeyboard() const override
std::shared_ptr< TrackPanelGuidelineOverlay > mOverlay
std::unique_ptr< bool, Resetter > TempAllowFocus
static bool s_AcceptsFocus
void HandleQPClick(wxMouseEvent &event, wxCoord mousePosX)
Observer::Subscription mPlayRegionSubscription
void HandleQPRelease(wxMouseEvent &event)
void HandleQPDrag(wxMouseEvent &event, wxCoord mousePosX)
Observer::Subscription mThemeChangeSubscription
MouseEventState mMouseEventState
std::shared_ptr< QPCell > mQPCell
SelectedRegion mLastDrawnSelectedRegion
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
void OnSize(wxSizeEvent &event)
Definition: BackedPanel.cpp:71
Formerly part of TrackPanel, this abstract base class has no special knowledge of Track objects and i...
Definition: CellularPanel.h:34
virtual std::shared_ptr< TrackPanelNode > Root()=0
virtual AudacityProject * GetProject() const =0
virtual void UpdateStatusMessage(const TranslatableString &)=0
virtual void SetFocusedCell()=0
virtual TrackPanelCell * GetFocusedCell()=0
virtual void ProcessUIHandleResult(TrackPanelCell *pClickedCell, TrackPanelCell *pLatestCell, unsigned refreshResult)=0
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
A listener notified of changes in preferences.
Definition: Prefs.h:543
Used to display a Ruler.
Definition: Ruler.h:26
Defines a selected portion of a project.
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1330
Holds a msgid for the translation catalog; may also bind format arguments.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
void ClearPlayRegion(AudacityProject &project)
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
Default message type for Publisher.
Definition: Observer.h:26