Audacity  3.0.3
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 
15 
16 
17 #include <vector>
18 
19 #include <wx/setup.h> // for wxUSE_* macros
20 #include <wx/timer.h> // to inherit
21 
22 #include "HitTestResult.h"
23 #include "Prefs.h"
24 
25 #include "SelectedRegion.h"
26 
27 #include "CellularPanel.h"
28 
30 
31 
32 class wxRect;
33 
34 class SpectrumAnalyst;
35 class Track;
36 class TrackList;
37 struct TrackListEvent;
38 class TrackPanel;
39 class TrackArtist;
40 class Ruler;
41 class SnapManager;
42 class AdornedRulerPanel;
43 class LWSlider;
44 
45 class TrackPanelAx;
46 
47 // Declared elsewhere, to reduce compilation dependencies
48 class TrackPanelListener;
49 
51 
52 enum class UndoPush : unsigned char;
53 
54 enum {
55  kTimerInterval = 50, // milliseconds
56 };
57 
58 const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
59 
60 class AUDACITY_DLL_API TrackPanel final
61  : public CellularPanel
63  , private PrefsListener
64 {
65  public:
66  static TrackPanel &Get( AudacityProject &project );
67  static const TrackPanel &Get( const AudacityProject &project );
68  static void Destroy( AudacityProject &project );
69 
70  TrackPanel(wxWindow * parent,
71  wxWindowID id,
72  const wxPoint & pos,
73  const wxSize & size,
74  const std::shared_ptr<TrackList> &tracks,
75  ViewInfo * viewInfo,
76  AudacityProject * project,
78 
79  virtual ~ TrackPanel();
80 
81  void UpdatePrefs() override;
82 
83  void OnAudioIO(wxCommandEvent & evt);
84 
85  void OnPaint(wxPaintEvent & event);
86  void OnMouseEvent(wxMouseEvent & event);
87  void OnKeyDown(wxKeyEvent & event);
88 
89  void OnTrackListResizing(TrackListEvent & event);
90  void OnTrackListDeletion(wxEvent & event);
91  void OnEnsureVisible(TrackListEvent & event);
92  void UpdateViewIfNoTracks(); // Call this to update mViewInfo, etc, after track(s) removal, before Refresh().
93 
94  double GetMostRecentXPos();
95 
96  void OnSize( wxSizeEvent & );
97  void OnIdle(wxIdleEvent & event);
98  void OnTimer(wxTimerEvent& event);
99  void OnProjectSettingsChange(wxCommandEvent &event);
100  void OnTrackFocusChange( wxCommandEvent &event );
101 
102  void OnUndoReset( wxCommandEvent &event );
103 
104  void Refresh
105  (bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
106  override;
107 
108  void RefreshTrack(Track *trk, bool refreshbacking = true);
109 
110  void HandlePageUpKey();
111  void HandlePageDownKey();
112  AudacityProject * GetProject() const override;
113 
114  void OnTrackMenu(Track *t = NULL);
115 
116  void VerticalScroll( float fracPosition);
117 
118  TrackPanelCell *GetFocusedCell() override;
119  void SetFocusedCell() override;
120 
121  void UpdateVRulers();
122  void UpdateVRuler(Track *t);
123  void UpdateTrackVRuler(Track *t);
124  void UpdateVRulerSize();
125 
126  protected:
127  bool IsAudioActive();
128 
129 public:
130  size_t GetSelectedTrackCount() const;
131 
132 protected:
133  void UpdateSelectionDisplay();
134 
135 public:
136  void MakeParentRedrawScrollbars();
137 
138  // Rectangle includes track control panel, and the vertical ruler, and
139  // the proper track area of all channels, and the separators between them.
140  wxRect FindTrackRect( const Track * target );
141 
142 protected:
143  // Get the root object defining a recursive subdivision of the panel's
144  // area into cells
145  std::shared_ptr<TrackPanelNode> Root() override;
146 
147 public:
148 // JKC Nov-2011: These four functions only used from within a dll
149 // They work around some messy problems with constructors.
150  const TrackList * GetTracks() const { return mTracks.get(); }
151  TrackList * GetTracks() { return mTracks.get(); }
153  TrackPanelListener * GetListener(){ return mListener;}
154  AdornedRulerPanel * GetRuler(){ return mRuler;}
155 
156 protected:
157  void DrawTracks(wxDC * dc);
158 
159 public:
160  // Set the object that performs catch-all event handling when the pointer
161  // is not in any track or ruler or control panel.
162  void SetBackgroundCell
163  (const std::shared_ptr< TrackPanelCell > &pCell);
164  std::shared_ptr< TrackPanelCell > GetBackgroundCell();
165 
166 public:
167 
168 protected:
170 
171  std::shared_ptr<TrackList> mTracks;
172 
174 
175  std::unique_ptr<TrackArtist> mTrackArtist;
176 
177  class AUDACITY_DLL_API AudacityTimer final : public wxTimer {
178  public:
179  void Notify() override{
180  // (From Debian)
181  //
182  // Don't call parent->OnTimer(..) directly here, but instead post
183  // an event. This ensures that this is a pure wxWidgets event
184  // (no GDK event behind it) and that it therefore isn't processed
185  // within the YieldFor(..) of the clipboard operations (workaround
186  // for Debian bug #765341).
187  // QueueEvent() will take ownership of the event
188  parent->GetEventHandler()->QueueEvent(safenew wxTimerEvent(*this));
189  }
191  } mTimer;
192 
194 
196 
197 
198 protected:
199 
200  SelectedRegion mLastDrawnSelectedRegion {};
201 
202  protected:
203 
204  std::shared_ptr<TrackPanelCell> mpBackground;
205 
206  DECLARE_EVENT_TABLE()
207 
208  void ProcessUIHandleResult
209  (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
210  unsigned refreshResult) override;
211 
212  void UpdateStatusMessage( const TranslatableString &status ) override;
213 };
214 
215 // A predicate class
216 struct AUDACITY_DLL_API IsVisibleTrack
217 {
219 
220  bool operator () (const Track *pTrack) const;
221 
222  wxRect mPanelRect;
223 };
224 
225 #endif
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
CellularPanel::GetFocusedCell
virtual TrackPanelCell * GetFocusedCell()=0
TrackPanel::GetTracks
TrackList * GetTracks()
Definition: TrackPanel.h:151
TrackPanel::GetTracks
const TrackList * GetTracks() const
Definition: TrackPanel.h:150
AdornedRulerPanel
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
Definition: AdornedRulerPanel.h:28
CellularPanel::mViewInfo
ViewInfo * mViewInfo
Definition: CellularPanel.h:161
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1264
ViewInfo
Definition: ViewInfo.h:173
SelectedRegion.h
TrackPanel::AudacityTimer::parent
TrackPanel * parent
Definition: TrackPanel.h:190
TrackInfo::UpdatePrefs
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
TrackPanelAx
Helper to TrackPanel to give accessibility.
Definition: TrackPanelAx.h:44
HitTestResult.h
BackedPanel::OnSize
void OnSize(wxSizeEvent &event)
Definition: BackedPanel.cpp:71
anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler
Ruler & ruler()
Definition: TimeTrackVRulerControls.cpp:34
TrackArtist
This class handles the actual rendering of WaveTracks (both waveforms and spectra),...
Definition: TrackArtist.h:70
TrackPanel
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:64
TrackPanel::AudacityTimer::Notify
void Notify() override
Definition: TrackPanel.h:179
PrefsListener
A listener notified of changes in preferences.
Definition: Prefs.h:389
CellularPanel::Root
virtual std::shared_ptr< TrackPanelNode > Root()=0
SpectrumAnalyst
Used for finding the peaks, for snapping to peaks.
Definition: SpectrumAnalyst.h:21
TrackPanel::mpBackground
std::shared_ptr< TrackPanelCell > mpBackground
Definition: TrackPanel.h:204
DragThreshold
const int DragThreshold
Definition: TrackPanel.h:58
TrackPanel::~ TrackPanel
virtual ~ TrackPanel()
CellularPanel::OnMouseEvent
void OnMouseEvent(wxMouseEvent &event)
Definition: CellularPanel.cpp:682
TrackListEvent
Notification of changes in individual tracks of TrackList, or of TrackList's composition.
Definition: Track.h:1206
LWSlider
Lightweight version of ASlider. In other words it does not have a window permanently associated with ...
Definition: ASlider.h:62
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
TrackPanel::AudacityTimer
Timer class dedicated to informing the TrackPanel that it is time to refresh some aspect of the scree...
Definition: TrackPanel.h:177
Ruler
Used to display a Ruler.
Definition: Ruler.h:26
IsVisibleTrack::mPanelRect
wxRect mPanelRect
Definition: TrackPanel.h:222
TrackPanelCell
Definition: TrackPanelCell.h:74
@0::kTimerInterval
@ kTimerInterval
IsVisibleTrack
Definition: TrackPanel.h:217
UndoPush
UndoPush
Definition: UndoManager.h:122
RefreshCode::UpdateVRuler
@ UpdateVRuler
Definition: RefreshCode.h:30
TrackPanel::mRuler
AdornedRulerPanel * mRuler
Definition: TrackPanel.h:173
TrackPanelListener
Definition: TrackPanelListener.h:23
NonKeystrokeInterceptingWindow
Definition: CommandManagerWindowClasses.h:20
TrackPanel::mListener
TrackPanelListener * mListener
Definition: TrackPanel.h:169
TrackPanel::GetViewInfo
ViewInfo * GetViewInfo()
Definition: TrackPanel.h:152
CellularPanel.h
CellularPanel::SetFocusedCell
virtual void SetFocusedCell()=0
CellularPanel::OnKeyDown
void OnKeyDown(wxKeyEvent &event)
Definition: CellularPanel.cpp:561
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:113
TrackPanel::mRefreshBacking
bool mRefreshBacking
Definition: TrackPanel.h:195
CellularPanel
Formerly part of TrackPanel, this abstract base class has no special knowledge of Track objects and i...
Definition: CellularPanel.h:34
TrackPanel::mTrackArtist
std::unique_ptr< TrackArtist > mTrackArtist
Definition: TrackPanel.h:175
SnapManager
Definition: Snap.h:56
CommandManagerWindowClasses.h
Prefs.h
TrackPanel::mTracks
std::shared_ptr< TrackList > mTracks
Definition: TrackPanel.h:171
TrackPanel::GetRuler
AdornedRulerPanel * GetRuler()
Definition: TrackPanel.h:154
safenew
#define safenew
Definition: MemoryX.h:10
TrackPanel::mTimeCount
int mTimeCount
Definition: TrackPanel.h:193
TrackPanel::GetListener
TrackPanelListener * GetListener()
Definition: TrackPanel.h:153
CellularPanel::GetProject
virtual AudacityProject * GetProject() const =0
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:38