Audacity 3.2.0
TrackPanel.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 TrackPanel.h
6
7 Dominic Mazzoni
8
9**********************************************************************/
10
11#ifndef __AUDACITY_TRACK_PANEL__
12#define __AUDACITY_TRACK_PANEL__
13
14#include <chrono>
15#include <vector>
16
17#include <wx/setup.h> // for wxUSE_* macros
18#include <wx/timer.h> // to inherit
19
20#include "HitTestResult.h"
21#include "Prefs.h"
22
23#include "SelectedRegion.h"
24
25#include "CellularPanel.h"
26#include "Observer.h"
27
29
30
31class wxRect;
32
33struct AudioIOEvent;
34
35// All cells of the TrackPanel are subclasses of this
37
38class SpectrumAnalyst;
39class Track;
40class TrackList;
41struct TrackListEvent;
42class TrackPanel;
43class TrackArtist;
44class Ruler;
46class LWSlider;
47
48class TrackPanelAx;
49
50// Declared elsewhere, to reduce compilation dependencies
52
54
55enum class UndoPush : unsigned char;
56
57static constexpr auto kTimerInterval = std::chrono::milliseconds{50};
58
59const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
60
61class AUDACITY_DLL_API TrackPanel final
62 : public CellularPanel
64 , private PrefsListener
65{
66 public:
67 static TrackPanel &Get( AudacityProject &project );
68 static const TrackPanel &Get( const AudacityProject &project );
69 static void Destroy( AudacityProject &project );
70
71 TrackPanel(wxWindow * parent,
72 wxWindowID id,
73 const wxPoint & pos,
74 const wxSize & size,
75 const std::shared_ptr<TrackList> &tracks,
76 ViewInfo * viewInfo,
77 AudacityProject * project,
79
80 virtual ~ TrackPanel();
81
82 void UpdatePrefs() override;
83
84 void OnAudioIO(AudioIOEvent);
85
86 void OnPaint(wxPaintEvent & event);
87 void OnMouseEvent(wxMouseEvent & event);
88 void OnKeyDown(wxKeyEvent & event);
89
90 void OnTrackListResizing(const TrackListEvent &event);
91 void OnTrackListDeletion();
92 void OnEnsureVisible(const TrackListEvent & event);
93 void UpdateViewIfNoTracks(); // Call this to update mViewInfo, etc, after track(s) removal, before Refresh().
94
95 double GetMostRecentXPos();
96
97 void OnSize( wxSizeEvent & );
98 void OnIdle(wxIdleEvent & event);
99 void OnTimer(wxTimerEvent& event);
100 void OnSyncLockChange(struct SyncLockChangeMessage);
101 void OnTrackFocusChange(struct TrackFocusChangeMessage);
102
103 void OnUndoReset(struct UndoRedoMessage);
104
105 void Refresh
106 (bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
107 override;
108
109 void RefreshTrack(Track *trk, bool refreshbacking = true);
110
111 void HandlePageUpKey();
112 void HandlePageDownKey();
113 AudacityProject * GetProject() const override;
114
115 void OnTrackMenu(Track *t = NULL);
116
117 void VerticalScroll( float fracPosition);
118
119 TrackPanelCell *GetFocusedCell() override;
120 void SetFocusedCell() override;
121
122 void UpdateVRulers();
123 void UpdateVRuler(Track *t);
124 void UpdateTrackVRuler(Track *t);
125 void UpdateVRulerSize();
126
127 protected:
128 bool IsAudioActive();
129
130public:
131 size_t GetSelectedTrackCount() const;
132
133protected:
134 void UpdateSelectionDisplay();
135
136public:
137 void MakeParentRedrawScrollbars();
138
144 wxRect FindTrackRect( const Track * target );
145
151 wxRect FindFocusedTrackRect( const Track * target );
152
158 std::vector<wxRect> FindRulerRects( const Track * target );
159
160protected:
161 // Get the root object defining a recursive subdivision of the panel's
162 // area into cells
163 std::shared_ptr<TrackPanelNode> Root() override;
164
165public:
166// JKC Nov-2011: These four functions only used from within a dll
167// They work around some messy problems with constructors.
168 const TrackList * GetTracks() const { return mTracks.get(); }
169 TrackList * GetTracks() { return mTracks.get(); }
171 TrackPanelListener * GetListener(){ return mListener;}
172 AdornedRulerPanel * GetRuler(){ return mRuler;}
173
174protected:
175 void DrawTracks(wxDC * dc);
176
177public:
178 // Set the object that performs catch-all event handling when the pointer
179 // is not in any track or ruler or control panel.
180 void SetBackgroundCell
181 (const std::shared_ptr< CommonTrackPanelCell > &pCell);
182 std::shared_ptr< CommonTrackPanelCell > GetBackgroundCell();
183
184public:
185
186protected:
193 ;
194
196
197 std::shared_ptr<TrackList> mTracks;
198
200
201 std::unique_ptr<TrackArtist> mTrackArtist;
202
203 class AUDACITY_DLL_API AudacityTimer final : public wxTimer {
204 public:
205 void Notify() override{
206 // (From Debian)
207 //
208 // Don't call parent->OnTimer(..) directly here, but instead post
209 // an event. This ensures that this is a pure wxWidgets event
210 // (no GDK event behind it) and that it therefore isn't processed
211 // within the YieldFor(..) of the clipboard operations (workaround
212 // for Debian bug #765341).
213 // QueueEvent() will take ownership of the event
214 parent->GetEventHandler()->QueueEvent(safenew wxTimerEvent(*this));
215 }
217 } mTimer;
218
220
222
223
224protected:
225
226 SelectedRegion mLastDrawnSelectedRegion {};
227
228 protected:
229
230 std::shared_ptr<CommonTrackPanelCell> mpBackground;
231
232 DECLARE_EVENT_TABLE()
233
234 void ProcessUIHandleResult
235 (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
236 unsigned refreshResult) override;
237
238 void UpdateStatusMessage( const TranslatableString &status ) override;
239};
240
241#endif
#define safenew
Definition: MemoryX.h:10
static constexpr auto kTimerInterval
Definition: TrackPanel.h:57
const int DragThreshold
Definition: TrackPanel.h:59
UndoPush
Definition: UndoManager.h:138
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
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
ViewInfo * mViewInfo
void OnKeyDown(wxKeyEvent &event)
void OnMouseEvent(wxMouseEvent &event)
virtual void SetFocusedCell()=0
virtual TrackPanelCell * GetFocusedCell()=0
Lightweight version of ASlider. In other words it does not have a window permanently associated with ...
Definition: ASlider.h:64
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.
Used for finding the peaks, for snapping to peaks.
This class handles the actual rendering of WaveTracks (both waveforms and spectra),...
Definition: TrackArtist.h:39
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:226
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1339
Timer class dedicated to informing the TrackPanel that it is time to refresh some aspect of the scree...
Definition: TrackPanel.h:203
void Notify() override
Definition: TrackPanel.h:205
Helper to TrackPanel to give accessibility.
Definition: TrackPanelAx.h:39
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:65
AdornedRulerPanel * mRuler
Definition: TrackPanel.h:199
AdornedRulerPanel * GetRuler()
Definition: TrackPanel.h:172
TrackPanelListener * mListener
Definition: TrackPanel.h:195
std::shared_ptr< TrackList > mTracks
Definition: TrackPanel.h:197
Observer::Subscription mAudioIOSubscription
Definition: TrackPanel.h:189
Observer::Subscription mTrackListSubscription
Definition: TrackPanel.h:188
ViewInfo * GetViewInfo()
Definition: TrackPanel.h:170
const TrackList * GetTracks() const
Definition: TrackPanel.h:168
Observer::Subscription mRealtimeEffectManagerSubscription
Definition: TrackPanel.h:192
std::shared_ptr< CommonTrackPanelCell > mpBackground
Definition: TrackPanel.h:230
TrackPanelListener * GetListener()
Definition: TrackPanel.h:171
Observer::Subscription mSyncLockSubscription
Definition: TrackPanel.h:193
bool mRefreshBacking
Definition: TrackPanel.h:221
Observer::Subscription mUndoSubscription
Definition: TrackPanel.h:190
int mTimeCount
Definition: TrackPanel.h:219
Observer::Subscription mFocusChangeSubscription
Definition: TrackPanel.h:191
TrackList * GetTracks()
Definition: TrackPanel.h:169
std::unique_ptr< TrackArtist > mTrackArtist
Definition: TrackPanel.h:201
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
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
void OnTrackMenu(const CommandContext &context)
Sent after sync lock setting changes, with its new state.
Definition: SyncLock.h:20
Notification of changes in individual tracks of TrackList, or of TrackList's composition.
Definition: Track.h:1289
Type of message published by UndoManager.
Definition: UndoManager.h:55