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 OnProjectSettingsChange(wxCommandEvent &event);
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:
192 ;
193
195
196 std::shared_ptr<TrackList> mTracks;
197
199
200 std::unique_ptr<TrackArtist> mTrackArtist;
201
202 class AUDACITY_DLL_API AudacityTimer final : public wxTimer {
203 public:
204 void Notify() override{
205 // (From Debian)
206 //
207 // Don't call parent->OnTimer(..) directly here, but instead post
208 // an event. This ensures that this is a pure wxWidgets event
209 // (no GDK event behind it) and that it therefore isn't processed
210 // within the YieldFor(..) of the clipboard operations (workaround
211 // for Debian bug #765341).
212 // QueueEvent() will take ownership of the event
213 parent->GetEventHandler()->QueueEvent(safenew wxTimerEvent(*this));
214 }
216 } mTimer;
217
219
221
222
223protected:
224
225 SelectedRegion mLastDrawnSelectedRegion {};
226
227 protected:
228
229 std::shared_ptr<CommonTrackPanelCell> mpBackground;
230
231 DECLARE_EVENT_TABLE()
232
233 void ProcessUIHandleResult
234 (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
235 unsigned refreshResult) override;
236
237 void UpdateStatusMessage( const TranslatableString &status ) override;
238};
239
240#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:150
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: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
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:543
Used to display a Ruler.
Definition: Ruler.h:26
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:225
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1338
Timer class dedicated to informing the TrackPanel that it is time to refresh some aspect of the scree...
Definition: TrackPanel.h:202
void Notify() override
Definition: TrackPanel.h:204
Helper to TrackPanel to give accessibility.
Definition: TrackPanelAx.h:41
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:198
AdornedRulerPanel * GetRuler()
Definition: TrackPanel.h:172
TrackPanelListener * mListener
Definition: TrackPanel.h:194
std::shared_ptr< TrackList > mTracks
Definition: TrackPanel.h:196
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:229
TrackPanelListener * GetListener()
Definition: TrackPanel.h:171
bool mRefreshBacking
Definition: TrackPanel.h:220
Observer::Subscription mUndoSubscription
Definition: TrackPanel.h:190
int mTimeCount
Definition: TrackPanel.h:218
Observer::Subscription mFocusChangeSubscription
Definition: TrackPanel.h:191
TrackList * GetTracks()
Definition: TrackPanel.h:169
std::unique_ptr< TrackArtist > mTrackArtist
Definition: TrackPanel.h:200
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
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
Notification of changes in individual tracks of TrackList, or of TrackList's composition.
Definition: Track.h:1288
Type of message published by UndoManager.
Definition: UndoManager.h:61