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
17#include "widgets/TimeFormat.h"
18#include "Observer.h"
19#include "Prefs.h"
20#include "ViewInfo.h" // for PlayRegion
21#include "TimeDisplayMode.h"
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:
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:
139
142
144
145 wxRect mOuter;
147 wxRect mInner;
148
149 int mLeftOffset; // Number of pixels before we hit the 'zero position'.
150
151
152 double mIndTime;
153
154 static constexpr size_t MAX_GUIDES = 2;
155 double mQuickPlayOffset[MAX_GUIDES]{};
156 double mQuickPlayPosUnsnapped[MAX_GUIDES]{};
157 double mQuickPlayPos[MAX_GUIDES]{};
158 bool mIsSnapped[MAX_GUIDES]{};
159 size_t mNumGuides{ 1 };
160
162
164
165 //
166 // Pop-up menu
167 //
168 void ShowMenu(const wxPoint & pos);
169 void ShowScrubMenu(const wxPoint & pos);
170 static void DragSelection(AudacityProject &project);
171 void HandleSnapping(size_t index);
172 void OnTimelineFormatChange(wxCommandEvent& evt);
173 void OnSyncSelToQuickPlay(wxCommandEvent &evt);
174 void OnAutoScroll(wxCommandEvent &evt);
175 void OnTogglePlayRegion(wxCommandEvent &evt);
176 void OnClearPlayRegion(wxCommandEvent &evt);
177 void OnSetPlayRegionToSelection(wxCommandEvent &evt);
178
179 void OnPinnedButton(wxCommandEvent & event);
180 void OnTogglePinnedState(wxCommandEvent & event);
181
183
189 mesSelectingPlayRegionRange
190 };
191
193 double mLeftDownClickUnsnapped; // click position in seconds, before snap
194 double mLeftDownClick; // click position in seconds
196
197 DECLARE_EVENT_TABLE()
198
199 wxWindow *mButtons[3];
200 bool mNeedButtonUpdate { true };
201
202 //
203 // CellularPanel implementation
204 //
205
206 // Get the root object defining a recursive subdivision of the panel's
207 // area into cells
208 std::shared_ptr<TrackPanelNode> Root() override;
209public:
210 AudacityProject * GetProject() const override;
211private:
212 std::shared_ptr<TrackPanelCell> GetFocusedCell() override;
213 void SetFocusedCell() override;
215 (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
216 unsigned refreshResult) override;
217
218 void UpdateStatusMessage( const TranslatableString & ) override;
219
220 void CreateOverlays();
221
222 // Cooperating objects
223 class TrackPanelGuidelineOverlay;
224 std::shared_ptr<TrackPanelGuidelineOverlay> mOverlay;
225
227
228private:
229 class CommonRulerHandle;
230 class QPHandle;
235 class ScrubbingHandle;
236
237 class CommonCell;
238
239 class QPCell;
240 std::shared_ptr<QPCell> mQPCell;
241
242 class ScrubbingCell;
243 std::shared_ptr<ScrubbingCell> mScrubbingCell;
244
249
250 // classes implementing subdivision for CellularPanel
251 struct Subgroup;
252 struct MainGroup;
253
255 std::pair<double, double> mLastDrawnPlayRegion{};
256 bool mLastPlayRegionActive = false;
257 double mLastDrawnH{};
258 double mLastDrawnZoom{};
259
260public:
262 void SetTimeDisplayMode(TimeDisplayMode rulerType);
263
264private:
265
267};
268
269#endif //define __AUDACITY_ADORNED_RULER_PANEL__
const auto project
TimeDisplayMode
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
std::shared_ptr< ScrubbingCell > mScrubbingCell
Observer::Subscription mAudioIOSubscription
LinearUpdater & mUpdater
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)
Observer::Subscription mRulerInvalidatedSubscription
TimeDisplayMode mTimeDisplayMode
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: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 std::shared_ptr< TrackPanelCell > GetFocusedCell()=0
virtual void UpdateStatusMessage(const TranslatableString &)=0
virtual void SetFocusedCell()=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:652
virtual void UpdatePrefs()=0
Definition: Prefs.cpp:154
Used to display a Ruler.
Definition: Ruler.h:34
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:850
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:202
void ClearPlayRegion(AudacityProject &project)
TimeDisplayMode GetTimeDisplayMode(const AudacityProject &project)
void SetTimeDisplayMode(const CommandContext &context, TimeDisplayMode 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