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);
122 void UpdateTrackVRuler(Track &t);
123 void UpdateVRulerSize();
124
125 protected:
126 bool IsAudioActive();
127
128public:
129 size_t GetSelectedTrackCount() const;
130
131protected:
132 void UpdateSelectionDisplay();
133
134public:
135 void MakeParentRedrawScrollbars();
136
142 wxRect FindTrackRect( const Track * target );
143
149 wxRect FindFocusedTrackRect( const Track * target );
150
156 std::vector<wxRect> FindRulerRects(const Channel &target);
157
158protected:
159 // Get the root object defining a recursive subdivision of the panel's
160 // area into cells
161 std::shared_ptr<TrackPanelNode> Root() override;
162
163public:
164// JKC Nov-2011: These four functions only used from within a dll
165// They work around some messy problems with constructors.
166 const TrackList * GetTracks() const { return mTracks.get(); }
167 TrackList * GetTracks() { return mTracks.get(); }
169 AdornedRulerPanel * GetRuler(){ return mRuler;}
170
171protected:
172 void DrawTracks(wxDC * dc);
173
174public:
175 // Set the object that performs catch-all event handling when the pointer
176 // is not in any track or ruler or control panel.
177 void SetBackgroundCell
178 (const std::shared_ptr< CommonTrackPanelCell > &pCell);
179 std::shared_ptr< CommonTrackPanelCell > GetBackgroundCell();
180
181public:
182
183protected:
192 ;
193
194 std::shared_ptr<TrackList> mTracks;
195
197
198 std::unique_ptr<TrackArtist> mTrackArtist;
199
200 class AUDACITY_DLL_API AudacityTimer final : public wxTimer {
201 public:
202 void Notify() override{
203 // (From Debian)
204 //
205 // Don't call parent->OnTimer(..) directly here, but instead post
206 // an event. This ensures that this is a pure wxWidgets event
207 // (no GDK event behind it) and that it therefore isn't processed
208 // within the YieldFor(..) of the clipboard operations (workaround
209 // for Debian bug #765341).
210 // QueueEvent() will take ownership of the event
211 parent->GetEventHandler()->QueueEvent(safenew wxTimerEvent(*this));
212 }
214 } mTimer;
215
217
219
220
221protected:
222
223 SelectedRegion mLastDrawnSelectedRegion {};
224
225 protected:
226
227 std::shared_ptr<CommonTrackPanelCell> mpBackground;
228
229 DECLARE_EVENT_TABLE()
230
231 void ProcessUIHandleResult
232 (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
233 unsigned refreshResult) override;
234
235 void UpdateStatusMessage( const TranslatableString &status ) override;
236};
237
238#endif
#define safenew
Definition: MemoryX.h:9
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:39
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:993
Timer class dedicated to informing the TrackPanel that it is time to refresh some aspect of the scree...
Definition: TrackPanel.h:200
void Notify() override
Definition: TrackPanel.h:202
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:191
AdornedRulerPanel * mRuler
Definition: TrackPanel.h:196
AdornedRulerPanel * GetRuler()
Definition: TrackPanel.h:169
std::shared_ptr< TrackList > mTracks
Definition: TrackPanel.h:194
Observer::Subscription mAudioIOSubscription
Definition: TrackPanel.h:186
Observer::Subscription mTrackListSubscription
Definition: TrackPanel.h:185
ViewInfo * GetViewInfo()
Definition: TrackPanel.h:168
const TrackList * GetTracks() const
Definition: TrackPanel.h:166
Observer::Subscription mRealtimeEffectManagerSubscription
Definition: TrackPanel.h:189
std::shared_ptr< CommonTrackPanelCell > mpBackground
Definition: TrackPanel.h:227
Observer::Subscription mSyncLockSubscription
Definition: TrackPanel.h:190
bool mRefreshBacking
Definition: TrackPanel.h:218
Observer::Subscription mUndoSubscription
Definition: TrackPanel.h:187
int mTimeCount
Definition: TrackPanel.h:216
Observer::Subscription mFocusChangeSubscription
Definition: TrackPanel.h:188
TrackList * GetTracks()
Definition: TrackPanel.h:167
std::unique_ptr< TrackArtist > mTrackArtist
Definition: TrackPanel.h:198
Observer::Subscription mSelectionSubscription
Definition: TrackPanel.h:192
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
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:946
Type of message published by UndoManager.
Definition: UndoManager.h:55