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 // All cells of the TrackPanel are subclasses of this
36 
37 class SpectrumAnalyst;
38 class Track;
39 class TrackList;
40 struct TrackListEvent;
41 class TrackPanel;
42 class TrackArtist;
43 class Ruler;
44 class AdornedRulerPanel;
45 class LWSlider;
46 
47 class TrackPanelAx;
48 
49 // Declared elsewhere, to reduce compilation dependencies
50 class TrackPanelListener;
51 
53 
54 enum class UndoPush : unsigned char;
55 
56 enum {
57  kTimerInterval = 50, // milliseconds
58 };
59 
60 const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
61 
62 class AUDACITY_DLL_API TrackPanel final
63  : public CellularPanel
65  , private PrefsListener
66 {
67  public:
68  static TrackPanel &Get( AudacityProject &project );
69  static const TrackPanel &Get( const AudacityProject &project );
70  static void Destroy( AudacityProject &project );
71 
72  TrackPanel(wxWindow * parent,
73  wxWindowID id,
74  const wxPoint & pos,
75  const wxSize & size,
76  const std::shared_ptr<TrackList> &tracks,
77  ViewInfo * viewInfo,
78  AudacityProject * project,
80 
81  virtual ~ TrackPanel();
82 
83  void UpdatePrefs() override;
84 
85  void OnAudioIO(wxCommandEvent & evt);
86 
87  void OnPaint(wxPaintEvent & event);
88  void OnMouseEvent(wxMouseEvent & event);
89  void OnKeyDown(wxKeyEvent & event);
90 
91  void OnTrackListResizing(TrackListEvent & event);
92  void OnTrackListDeletion(wxEvent & event);
93  void OnEnsureVisible(TrackListEvent & event);
94  void UpdateViewIfNoTracks(); // Call this to update mViewInfo, etc, after track(s) removal, before Refresh().
95 
96  double GetMostRecentXPos();
97 
98  void OnSize( wxSizeEvent & );
99  void OnIdle(wxIdleEvent & event);
100  void OnTimer(wxTimerEvent& event);
101  void OnProjectSettingsChange(wxCommandEvent &event);
102  void OnTrackFocusChange( wxCommandEvent &event );
103 
104  void OnUndoReset( wxCommandEvent &event );
105 
106  void Refresh
107  (bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
108  override;
109 
110  void RefreshTrack(Track *trk, bool refreshbacking = true);
111 
112  void HandlePageUpKey();
113  void HandlePageDownKey();
114  AudacityProject * GetProject() const override;
115 
116  void OnTrackMenu(Track *t = NULL);
117 
118  void VerticalScroll( float fracPosition);
119 
120  TrackPanelCell *GetFocusedCell() override;
121  void SetFocusedCell() override;
122 
123  void UpdateVRulers();
124  void UpdateVRuler(Track *t);
125  void UpdateTrackVRuler(Track *t);
126  void UpdateVRulerSize();
127 
128  protected:
129  bool IsAudioActive();
130 
131 public:
132  size_t GetSelectedTrackCount() const;
133 
134 protected:
135  void UpdateSelectionDisplay();
136 
137 public:
138  void MakeParentRedrawScrollbars();
139 
145  wxRect FindTrackRect( const Track * target );
146 
152  wxRect FindFocusedTrackRect( const Track * target );
153 
159  std::vector<wxRect> FindRulerRects( const Track * target );
160 
161 protected:
162  // Get the root object defining a recursive subdivision of the panel's
163  // area into cells
164  std::shared_ptr<TrackPanelNode> Root() override;
165 
166 public:
167 // JKC Nov-2011: These four functions only used from within a dll
168 // They work around some messy problems with constructors.
169  const TrackList * GetTracks() const { return mTracks.get(); }
170  TrackList * GetTracks() { return mTracks.get(); }
172  TrackPanelListener * GetListener(){ return mListener;}
173  AdornedRulerPanel * GetRuler(){ return mRuler;}
174 
175 protected:
176  void DrawTracks(wxDC * dc);
177 
178 public:
179  // Set the object that performs catch-all event handling when the pointer
180  // is not in any track or ruler or control panel.
181  void SetBackgroundCell
182  (const std::shared_ptr< CommonTrackPanelCell > &pCell);
183  std::shared_ptr< CommonTrackPanelCell > GetBackgroundCell();
184 
185 public:
186 
187 protected:
189 
190  std::shared_ptr<TrackList> mTracks;
191 
193 
194  std::unique_ptr<TrackArtist> mTrackArtist;
195 
196  class AUDACITY_DLL_API AudacityTimer final : public wxTimer {
197  public:
198  void Notify() override{
199  // (From Debian)
200  //
201  // Don't call parent->OnTimer(..) directly here, but instead post
202  // an event. This ensures that this is a pure wxWidgets event
203  // (no GDK event behind it) and that it therefore isn't processed
204  // within the YieldFor(..) of the clipboard operations (workaround
205  // for Debian bug #765341).
206  // QueueEvent() will take ownership of the event
207  parent->GetEventHandler()->QueueEvent(safenew wxTimerEvent(*this));
208  }
210  } mTimer;
211 
213 
215 
216 
217 protected:
218 
219  SelectedRegion mLastDrawnSelectedRegion {};
220 
221  protected:
222 
223  std::shared_ptr<CommonTrackPanelCell> mpBackground;
224 
225  DECLARE_EVENT_TABLE()
226 
227  void ProcessUIHandleResult
228  (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
229  unsigned refreshResult) override;
230 
231  void UpdateStatusMessage( const TranslatableString &status ) override;
232 };
233 
234 #endif
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
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:170
TrackPanel::GetTracks
const TrackList * GetTracks() const
Definition: TrackPanel.h:169
AdornedRulerPanel
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
Definition: AdornedRulerPanel.h:27
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:1280
ViewInfo
Definition: ViewInfo.h:202
SelectedRegion.h
TrackPanel::AudacityTimer::parent
TrackPanel * parent
Definition: TrackPanel.h:209
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:76
TrackPanel
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:66
TrackPanel::AudacityTimer::Notify
void Notify() override
Definition: TrackPanel.h:198
PrefsListener
A listener notified of changes in preferences.
Definition: Prefs.h:392
CellularPanel::Root
virtual std::shared_ptr< TrackPanelNode > Root()=0
SpectrumAnalyst
Used for finding the peaks, for snapping to peaks.
Definition: SpectrumAnalyst.h:21
DragThreshold
const int DragThreshold
Definition: TrackPanel.h:60
TrackPanel::~ TrackPanel
virtual ~ TrackPanel()
CellularPanel::OnMouseEvent
void OnMouseEvent(wxMouseEvent &event)
Definition: CellularPanel.cpp:684
TrackListEvent
Notification of changes in individual tracks of TrackList, or of TrackList's composition.
Definition: Track.h:1222
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:196
Ruler
Used to display a Ruler.
Definition: Ruler.h:26
TrackPanelCell
Definition: TrackPanelCell.h:74
@0::kTimerInterval
@ kTimerInterval
UndoPush
UndoPush
Definition: UndoManager.h:122
RefreshCode::UpdateVRuler
@ UpdateVRuler
Definition: RefreshCode.h:30
TrackPanel::mRuler
AdornedRulerPanel * mRuler
Definition: TrackPanel.h:192
TrackPanelListener
Definition: TrackPanelListener.h:23
NonKeystrokeInterceptingWindow
Definition: CommandManagerWindowClasses.h:20
TrackPanel::mListener
TrackPanelListener * mListener
Definition: TrackPanel.h:188
TrackPanel::GetViewInfo
ViewInfo * GetViewInfo()
Definition: TrackPanel.h:171
CellularPanel.h
CellularPanel::SetFocusedCell
virtual void SetFocusedCell()=0
CellularPanel::OnKeyDown
void OnKeyDown(wxKeyEvent &event)
Definition: CellularPanel.cpp:563
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:92
TrackPanel::mRefreshBacking
bool mRefreshBacking
Definition: TrackPanel.h:214
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:194
CommandManagerWindowClasses.h
Prefs.h
TrackPanel::mTracks
std::shared_ptr< TrackList > mTracks
Definition: TrackPanel.h:190
TrackPanel::GetRuler
AdornedRulerPanel * GetRuler()
Definition: TrackPanel.h:173
CommonTrackPanelCell
Definition: CommonTrackPanelCell.h:28
safenew
#define safenew
Definition: MemoryX.h:10
TrackPanel::mTimeCount
int mTimeCount
Definition: TrackPanel.h:212
TrackPanel::GetListener
TrackPanelListener * GetListener()
Definition: TrackPanel.h:172
CellularPanel::GetProject
virtual AudacityProject * GetProject() const =0
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35
TrackPanel::mpBackground
std::shared_ptr< CommonTrackPanelCell > mpBackground
Definition: TrackPanel.h:223