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 Channel;
39class SpectrumAnalyst;
40class Track;
41class TrackList;
42struct TrackListEvent;
43class TrackPanel;
44class TrackArtist;
45class Ruler;
47class LWSlider;
48
49class TrackPanelAx;
50
52
53enum class UndoPush : unsigned char;
54
55static constexpr auto kTimerInterval = std::chrono::milliseconds{50};
56
57const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
58
59class AUDACITY_DLL_API TrackPanel final
60 : public CellularPanel
62 , private PrefsListener
63{
64 public:
66 static const TrackPanel &Get( const AudacityProject &project );
67 static void Destroy( AudacityProject &project );
68
69 TrackPanel(wxWindow * parent,
70 wxWindowID id,
71 const wxPoint & pos,
72 const wxSize & size,
73 const std::shared_ptr<TrackList> &tracks,
74 ViewInfo * viewInfo,
77
78 virtual ~ TrackPanel();
79
80 void UpdatePrefs() override;
81
82 void OnAudioIO(AudioIOEvent);
83
84 void OnPaint(wxPaintEvent & event);
85 void OnMouseEvent(wxMouseEvent & event);
86 void OnKeyDown(wxKeyEvent & event);
87
88 void OnTrackListResizing(const TrackListEvent &event);
89 void OnTrackListDeletion();
90 void UpdateViewIfNoTracks(); // Call this to update mViewInfo, etc, after track(s) removal, before Refresh().
91
92 double GetMostRecentXPos();
93
94 void OnSize( wxSizeEvent & );
95 void OnIdle(wxIdleEvent & event);
96 void OnTimer(wxTimerEvent& event);
97 void OnSyncLockChange(struct SyncLockChangeMessage);
98 void OnTrackFocusChange(struct TrackFocusChangeMessage);
99
100 void OnUndoReset(struct UndoRedoMessage);
101
102 void Refresh
103 (bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
104 override;
105
106 void RefreshTrack(Track *trk, bool refreshbacking = true);
107
108 void HandlePageUpKey();
109 void HandlePageDownKey();
110 AudacityProject * GetProject() const override;
111
112 void OnTrackMenu(Track *t = NULL);
113
114 std::shared_ptr<TrackPanelCell> GetFocusedCell() override;
115 void SetFocusedCell() override;
116
117 void UpdateVRulers();
118 void UpdateVRuler(Track *t);
119 void UpdateTrackVRuler(Track &t);
120 void UpdateVRulerSize();
121
122 protected:
123 bool IsAudioActive();
124
125public:
126 size_t GetSelectedTrackCount() const;
127
128protected:
129 void UpdateSelectionDisplay();
130
131public:
132 void MakeParentRedrawScrollbars();
133
139 wxRect FindTrackRect( const Track * target );
140
146 wxRect FindFocusedTrackRect( const Track * target );
147
153 std::vector<wxRect> FindRulerRects(const Channel &target);
154
155protected:
156 // Get the root object defining a recursive subdivision of the panel's
157 // area into cells
158 std::shared_ptr<TrackPanelNode> Root() override;
159
160public:
161// JKC Nov-2011: These four functions only used from within a dll
162// They work around some messy problems with constructors.
163 const TrackList * GetTracks() const { return mTracks.get(); }
164 TrackList * GetTracks() { return mTracks.get(); }
166 AdornedRulerPanel * GetRuler(){ return mRuler;}
167
168protected:
169 void DrawTracks(wxDC * dc);
170
171public:
172 // Set the object that performs catch-all event handling when the pointer
173 // is not in any track or ruler or control panel.
174 void SetBackgroundCell
175 (const std::shared_ptr< CommonTrackPanelCell > &pCell);
176 std::shared_ptr< CommonTrackPanelCell > GetBackgroundCell();
177
178public:
179
180protected:
189 ;
190
191 std::shared_ptr<TrackList> mTracks;
192
194
195 std::unique_ptr<TrackArtist> mTrackArtist;
196
197 class AUDACITY_DLL_API AudacityTimer final : public wxTimer {
198 public:
199 void Notify() override{
200 // (From Debian)
201 //
202 // Don't call parent->OnTimer(..) directly here, but instead post
203 // an event. This ensures that this is a pure wxWidgets event
204 // (no GDK event behind it) and that it therefore isn't processed
205 // within the YieldFor(..) of the clipboard operations (workaround
206 // for Debian bug #765341).
207 // QueueEvent() will take ownership of the event
208 parent->GetEventHandler()->QueueEvent(safenew wxTimerEvent(*this));
209 }
211 } mTimer;
212
214
216
217
218protected:
219
220 SelectedRegion mLastDrawnSelectedRegion {};
221
222 protected:
223
224 std::shared_ptr<CommonTrackPanelCell> mpBackground;
225
226 DECLARE_EVENT_TABLE()
227
228 void ProcessUIHandleResult
229 (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
230 unsigned refreshResult) override;
231
232 void UpdateStatusMessage( const TranslatableString &status ) override;
233};
234
235#endif
#define safenew
Definition: MemoryX.h:10
const auto tracks
const auto project
static constexpr auto kTimerInterval
Definition: TrackPanel.h:55
const int DragThreshold
Definition: TrackPanel.h:57
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
virtual std::shared_ptr< TrackPanelCell > GetFocusedCell()=0
ViewInfo * mViewInfo
void OnKeyDown(wxKeyEvent &event)
void OnMouseEvent(wxMouseEvent &event)
virtual void SetFocusedCell()=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: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.
Used for finding the peaks, for snapping to peaks.
This class handles the actual rendering of WaveTracks (both waveforms and spectra),...
Definition: TrackArtist.h:40
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
Timer class dedicated to informing the TrackPanel that it is time to refresh some aspect of the scree...
Definition: TrackPanel.h:197
void Notify() override
Definition: TrackPanel.h:199
Helper to TrackPanel to give accessibility.
Definition: TrackPanelAx.h:34
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:63
Observer::Subscription mProjectRulerInvalidatedSubscription
Definition: TrackPanel.h:188
AdornedRulerPanel * mRuler
Definition: TrackPanel.h:193
AdornedRulerPanel * GetRuler()
Definition: TrackPanel.h:166
std::shared_ptr< TrackList > mTracks
Definition: TrackPanel.h:191
Observer::Subscription mAudioIOSubscription
Definition: TrackPanel.h:183
Observer::Subscription mTrackListSubscription
Definition: TrackPanel.h:182
ViewInfo * GetViewInfo()
Definition: TrackPanel.h:165
const TrackList * GetTracks() const
Definition: TrackPanel.h:163
Observer::Subscription mRealtimeEffectManagerSubscription
Definition: TrackPanel.h:186
std::shared_ptr< CommonTrackPanelCell > mpBackground
Definition: TrackPanel.h:224
Observer::Subscription mSyncLockSubscription
Definition: TrackPanel.h:187
bool mRefreshBacking
Definition: TrackPanel.h:215
Observer::Subscription mUndoSubscription
Definition: TrackPanel.h:184
int mTimeCount
Definition: TrackPanel.h:213
Observer::Subscription mFocusChangeSubscription
Definition: TrackPanel.h:185
TrackList * GetTracks()
Definition: TrackPanel.h:164
std::unique_ptr< TrackArtist > mTrackArtist
Definition: TrackPanel.h:195
Observer::Subscription mSelectionSubscription
Definition: TrackPanel.h:189
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 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:803
Type of message published by UndoManager.
Definition: UndoManager.h:55