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 "widgets/BeatsFormat.h"
15#include "CellularPanel.h"
16#include "widgets/Ruler.h" // member variable
18#include "widgets/TimeFormat.h"
19#include "Observer.h"
20#include "Prefs.h"
21#include "ViewInfo.h" // for PlayRegion
22
23class AudacityProject;
24struct AudioIOEvent;
25class LinearUpdater;
26class TrackList;
27
28// This is an Audacity Specific ruler panel.
29class AUDACITY_DLL_API AdornedRulerPanel final
30: public CellularPanel
31, private PrefsListener
32{
33public:
34 static AdornedRulerPanel &Get( AudacityProject &project );
35 static const AdornedRulerPanel &Get( const AudacityProject &project );
36 static void Destroy( AudacityProject &project );
37
39 wxWindow* parent,
40 wxWindowID id,
41 const wxPoint& pos = wxDefaultPosition,
42 const wxSize& size = wxDefaultSize,
43 ViewInfo *viewinfo = NULL);
44
46
47 void Refresh
48 (bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
49 override;
50
51 bool AcceptsFocus() const override { return s_AcceptsFocus; }
52 bool AcceptsFocusFromKeyboard() const override { return true; }
53 void SetFocusFromKbd() override;
54
55public:
56 int GetRulerHeight() { return GetRulerHeight( ShowingScrubRuler() ); }
57 static int GetRulerHeight(bool showScrubBar);
58 wxRect GetInnerRect() const { return mInner; }
59
60 void SetLeftOffset(int offset);
61
62 void DrawSelection();
63
64 void SetPlayRegion(double playRegionStart, double playRegionEnd);
65 void ClearPlayRegion();
66 void TogglePinnedHead();
67
68 void GetMaxSize(wxCoord *width, wxCoord *height);
69
70 void InvalidateRuler();
71
72 void UpdatePrefs() override;
73 void ReCreateButtons();
74
75 void UpdateQuickPlayPos(wxCoord &mousePosX);
76
77 bool ShowingScrubRuler() const;
78 //void OnToggleScrubRulerFromMenu(wxCommandEvent& );
79 bool SetPanelSize();
80
81 void DrawBothOverlays();
82
83
84private:
85 void DoIdle();
86 void OnIdle( wxIdleEvent &evt );
87 void OnAudioStartStop(AudioIOEvent);
88 void OnPaint(wxPaintEvent &evt);
89 void OnSize(wxSizeEvent &evt);
90 void OnLeave(wxMouseEvent &evt);
91 void OnThemeChange(struct ThemeChangeMessage);
92 void OnSelectionChange(Observer::Message);
93 void DoSelectionChange( const SelectedRegion &selectedRegion );
94 bool UpdateRects();
95 void HandleQPClick(wxMouseEvent &event, wxCoord mousePosX);
96 void HandleQPDrag(wxMouseEvent &event, wxCoord mousePosX);
97 void HandleQPRelease(wxMouseEvent &event);
98 void StartQPPlay(
99 bool newDefault, bool cutPreview, const double *pStartTime = nullptr);
100
101 void DoDrawBackground(wxDC * dc);
102 void DoDrawEdge(wxDC *dc);
103 void DoDrawMarks(wxDC * dc, bool /*text */ );
104 wxRect RegionRectangle(double t0, double t1) const;
105 wxRect PlayRegionRectangle() const;
106 wxRect SelectedRegionRectangle() const;
107 void DoDrawPlayRegion(wxDC * dc,
108 const wxRect &rectP, const wxRect &rectL, const wxRect &rectR);
109 void DoDrawPlayRegionLimits(wxDC * dc, const wxRect &rect);
110 void DoDrawOverlap(wxDC * dc, const wxRect &rect);
111 void DoDrawSelection(wxDC * dc,
112 const wxRect &rectS, const wxRect &rectL, const wxRect &rectR);
113
114public:
115 void DoDrawScrubIndicator(wxDC * dc, wxCoord xx, int width, bool scrub, bool seek);
116 void UpdateButtonStates();
117
118private:
119 static bool s_AcceptsFocus;
120 struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
121 using TempAllowFocus = std::unique_ptr<bool, Resetter>;
122
123public:
124 static TempAllowFocus TemporarilyAllowFocus();
125
126 void SetNumGuides(size_t nn);
127
128private:
129 enum class MenuChoice { QuickPlay, Scrub };
130 void ShowContextMenu( MenuChoice choice, const wxPoint *pPosition);
131
132 double Pos2Time(int p, bool ignoreFisheye = false) const;
133 int Time2Pos(double t, bool ignoreFisheye = false) const;
134
135 bool IsWithinMarker(int mousePosX, double markerTime);
136
137private:
138
139 // Stateless formatter object, but not used by default...
141
143
144 // ... Time formatter used by default instead
145 Ruler mRuler{ mUpdater, TimeFormat::Instance() };
146
149
150 wxRect mOuter;
152 wxRect mInner;
153
154 int mLeftOffset; // Number of pixels before we hit the 'zero position'.
155
156
157 double mIndTime;
158
159 static constexpr size_t MAX_GUIDES = 2;
160 double mQuickPlayOffset[MAX_GUIDES]{};
161 double mQuickPlayPosUnsnapped[MAX_GUIDES]{};
162 double mQuickPlayPos[MAX_GUIDES]{};
163 bool mIsSnapped[MAX_GUIDES]{};
164 size_t mNumGuides{ 1 };
165
167
169
170 //
171 // Pop-up menu
172 //
173 void ShowMenu(const wxPoint & pos);
174 void ShowScrubMenu(const wxPoint & pos);
175 static void DragSelection(AudacityProject &project);
176 void HandleSnapping(size_t index);
177 void UpdateBeatsAndMeasuresFormat();
178 void RefreshTimelineFormat();
179 void OnTimelineFormatChange(wxCommandEvent& evt);
180 void OnSyncSelToQuickPlay(wxCommandEvent &evt);
181 //void OnTimelineToolTips(wxCommandEvent &evt);
182 void OnAutoScroll(wxCommandEvent &evt);
183 void OnTogglePlayRegion(wxCommandEvent &evt);
184 void OnClearPlayRegion(wxCommandEvent &evt);
185 void OnSetPlayRegionToSelection(wxCommandEvent &evt);
186
187 void OnPinnedButton(wxCommandEvent & event);
188 void OnTogglePinnedState(wxCommandEvent & event);
189
192
198 mesSelectingPlayRegionRange
199 };
200
202 double mLeftDownClickUnsnapped; // click position in seconds, before snap
203 double mLeftDownClick; // click position in seconds
205
206 DECLARE_EVENT_TABLE()
207
208 wxWindow *mButtons[3];
209 bool mNeedButtonUpdate { true };
210
211 //
212 // CellularPanel implementation
213 //
214
215 // Get the root object defining a recursive subdivision of the panel's
216 // area into cells
217 std::shared_ptr<TrackPanelNode> Root() override;
218public:
219 AudacityProject * GetProject() const override;
220private:
221 TrackPanelCell *GetFocusedCell() override;
222 void SetFocusedCell() override;
224 (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
225 unsigned refreshResult) override;
226
227 void UpdateStatusMessage( const TranslatableString & ) override;
228
229 void CreateOverlays();
230
231 // Cooperating objects
232 class TrackPanelGuidelineOverlay;
233 std::shared_ptr<TrackPanelGuidelineOverlay> mOverlay;
234
236
237private:
238 class CommonRulerHandle;
239 class QPHandle;
244 class ScrubbingHandle;
245
246 class CommonCell;
247
248 class QPCell;
249 std::shared_ptr<QPCell> mQPCell;
250
251 class ScrubbingCell;
252 std::shared_ptr<ScrubbingCell> mScrubbingCell;
253
258
259 // classes implementing subdivision for CellularPanel
260 struct Subgroup;
261 struct MainGroup;
262
264 std::pair<double, double> mLastDrawnPlayRegion{};
265 bool mLastPlayRegionActive = false;
266 double mLastDrawnH{};
267 double mLastDrawnZoom{};
268
269public:
270
271 enum RulerTypeValues : int {
274
276 };
277
278 RulerTypeValues GetRulerType() const;
279 void SetRulerType(RulerTypeValues rulerType);
280
281private:
282
284};
285
287
288#endif //define __AUDACITY_ADORNED_RULER_PANEL__
EnumSetting< AdornedRulerPanel::RulerTypeValues > RulerPanelViewPreference
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
std::shared_ptr< ScrubbingCell > mScrubbingCell
Observer::Subscription mAudioIOSubscription
Observer::Subscription mProjectTimeSignatureChangedSubscription
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
RulerTypeValues mRulerType
MouseEventState mMouseEventState
std::shared_ptr< QPCell > mQPCell
BeatsFormat mBeatsFormat
SelectedRegion mLastDrawnSelectedRegion
LinearUpdater mUpdater
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
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
Adapts EnumSettingBase to a particular enumeration type.
Definition: Prefs.h:507
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
A listener notified of changes in preferences.
Definition: Prefs.h:556
Used to display a Ruler.
Definition: Ruler.h:28
Defines a selected portion of a project.
static const TimeFormat & Instance()
Definition: TimeFormat.cpp:15
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1212
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:196
void ClearPlayRegion(AudacityProject &project)
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
AdornedRulerPanel::RulerTypeValues GetRulerType(const AudacityProject &project)
void SetRulerType(const CommandContext &context, AdornedRulerPanel::RulerTypeValues type)
void OnSetPlayRegionToSelection(const CommandContext &context)
void OnTogglePlayRegion(const CommandContext &context)
void OnClearPlayRegion(const CommandContext &context)
Default message type for Publisher.
Definition: Observer.h:26