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;
22class TrackList;
23
24// This is an Audacity Specific ruler panel.
25class AUDACITY_DLL_API AdornedRulerPanel final
26: public CellularPanel
27, private PrefsListener
28{
29public:
30 static AdornedRulerPanel &Get( AudacityProject &project );
31 static const AdornedRulerPanel &Get( const AudacityProject &project );
32 static void Destroy( AudacityProject &project );
33
35 wxWindow* parent,
36 wxWindowID id,
37 const wxPoint& pos = wxDefaultPosition,
38 const wxSize& size = wxDefaultSize,
39 ViewInfo *viewinfo = NULL);
40
42
43 void Refresh
44 (bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
45 override;
46
47 bool AcceptsFocus() const override { return s_AcceptsFocus; }
48 bool AcceptsFocusFromKeyboard() const override { return true; }
49 void SetFocusFromKbd() override;
50
51public:
52 int GetRulerHeight() { return GetRulerHeight( ShowingScrubRuler() ); }
53 static int GetRulerHeight(bool showScrubBar);
54 wxRect GetInnerRect() const { return mInner; }
55
56 void SetLeftOffset(int offset);
57
58 void DrawSelection();
59
60 void SetPlayRegion(double playRegionStart, double playRegionEnd);
61 void ClearPlayRegion();
62 void TogglePinnedHead();
63
64 void GetMaxSize(wxCoord *width, wxCoord *height);
65
66 void InvalidateRuler();
67
68 void UpdatePrefs() override;
69 void ReCreateButtons();
70
71 void UpdateQuickPlayPos(wxCoord &mousePosX);
72
73 bool ShowingScrubRuler() const;
74 //void OnToggleScrubRulerFromMenu(wxCommandEvent& );
75 bool SetPanelSize();
76
77 void DrawBothOverlays();
78
79
80private:
81 void DoIdle();
82 void OnIdle( wxIdleEvent &evt );
83 void OnAudioStartStop(AudioIOEvent);
84 void OnPaint(wxPaintEvent &evt);
85 void OnSize(wxSizeEvent &evt);
86 void OnLeave(wxMouseEvent &evt);
87 void OnThemeChange(struct ThemeChangeMessage);
88 void OnSelectionChange(Observer::Message);
89 void DoSelectionChange( const SelectedRegion &selectedRegion );
90 bool UpdateRects();
91 void HandleQPClick(wxMouseEvent &event, wxCoord mousePosX);
92 void HandleQPDrag(wxMouseEvent &event, wxCoord mousePosX);
93 void HandleQPRelease(wxMouseEvent &event);
94 void StartQPPlay(
95 bool newDefault, bool cutPreview, const double *pStartTime = nullptr);
96
97 void DoDrawBackground(wxDC * dc);
98 void DoDrawEdge(wxDC *dc);
99 void DoDrawMarks(wxDC * dc, bool /*text */ );
100 wxRect RegionRectangle(double t0, double t1) const;
101 wxRect PlayRegionRectangle() const;
102 wxRect SelectedRegionRectangle() const;
103 void DoDrawPlayRegion(wxDC * dc,
104 const wxRect &rectP, const wxRect &rectL, const wxRect &rectR);
105 void DoDrawPlayRegionLimits(wxDC * dc, const wxRect &rect);
106 void DoDrawOverlap(wxDC * dc, const wxRect &rect);
107 void DoDrawSelection(wxDC * dc,
108 const wxRect &rectS, const wxRect &rectL, const wxRect &rectR);
109
110public:
111 void DoDrawScrubIndicator(wxDC * dc, wxCoord xx, int width, bool scrub, bool seek);
112 void UpdateButtonStates();
113
114private:
115 static bool s_AcceptsFocus;
116 struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
117 using TempAllowFocus = std::unique_ptr<bool, Resetter>;
118
119public:
120 static TempAllowFocus TemporarilyAllowFocus();
121
122 void SetNumGuides(size_t nn);
123
124private:
125 enum class MenuChoice { QuickPlay, Scrub };
126 void ShowContextMenu( MenuChoice choice, const wxPoint *pPosition);
127
128 double Pos2Time(int p, bool ignoreFisheye = false) const;
129 int Time2Pos(double t, bool ignoreFisheye = false) const;
130
131 bool IsWithinMarker(int mousePosX, double markerTime);
132
133private:
134
138
139 wxRect mOuter;
141 wxRect mInner;
142
143 int mLeftOffset; // Number of pixels before we hit the 'zero position'.
144
145
146 double mIndTime;
147
148 static constexpr size_t MAX_GUIDES = 2;
149 double mQuickPlayOffset[MAX_GUIDES]{};
150 double mQuickPlayPosUnsnapped[MAX_GUIDES]{};
151 double mQuickPlayPos[MAX_GUIDES]{};
152 bool mIsSnapped[MAX_GUIDES]{};
153 size_t mNumGuides{ 1 };
154
156
158
159 //
160 // Pop-up menu
161 //
162 void ShowMenu(const wxPoint & pos);
163 void ShowScrubMenu(const wxPoint & pos);
164 static void DragSelection(AudacityProject &project);
165 void HandleSnapping(size_t index);
166 void OnSyncSelToQuickPlay(wxCommandEvent &evt);
167 //void OnTimelineToolTips(wxCommandEvent &evt);
168 void OnAutoScroll(wxCommandEvent &evt);
169 void OnTogglePlayRegion(wxCommandEvent &evt);
170 void OnClearPlayRegion(wxCommandEvent &evt);
171 void OnSetPlayRegionToSelection(wxCommandEvent &evt);
172
173 void OnPinnedButton(wxCommandEvent & event);
174 void OnTogglePinnedState(wxCommandEvent & event);
175
178
184 mesSelectingPlayRegionRange
185 };
186
188 double mLeftDownClickUnsnapped; // click position in seconds, before snap
189 double mLeftDownClick; // click position in seconds
191
192 DECLARE_EVENT_TABLE()
193
194 wxWindow *mButtons[3];
195 bool mNeedButtonUpdate { true };
196
197 //
198 // CellularPanel implementation
199 //
200
201 // Get the root object defining a recursive subdivision of the panel's
202 // area into cells
203 std::shared_ptr<TrackPanelNode> Root() override;
204public:
205 AudacityProject * GetProject() const override;
206private:
207 TrackPanelCell *GetFocusedCell() override;
208 void SetFocusedCell() override;
210 (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
211 unsigned refreshResult) override;
212
213 void UpdateStatusMessage( const TranslatableString & ) override;
214
215 void CreateOverlays();
216
217 // Cooperating objects
218 class TrackPanelGuidelineOverlay;
219 std::shared_ptr<TrackPanelGuidelineOverlay> mOverlay;
220
222
223private:
224 class CommonRulerHandle;
225 class QPHandle;
230 class ScrubbingHandle;
231
232 class CommonCell;
233
234 class QPCell;
235 std::shared_ptr<QPCell> mQPCell;
236
237 class ScrubbingCell;
238 std::shared_ptr<ScrubbingCell> mScrubbingCell;
239
243
244 // classes implementing subdivision for CellularPanel
245 struct Subgroup;
246 struct MainGroup;
247
249 std::pair<double, double> mLastDrawnPlayRegion{};
250 bool mLastPlayRegionActive = false;
251 double mLastDrawnH{};
252 double mLastDrawnZoom{};
253};
254
255#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: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
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: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:1338
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:194
void ClearPlayRegion(AudacityProject &project)
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
void OnSetPlayRegionToSelection(const CommandContext &context)
void OnTogglePlayRegion(const CommandContext &context)
void OnClearPlayRegion(const CommandContext &context)
Default message type for Publisher.
Definition: Observer.h:26