Audacity  3.0.3
WaveTrackView.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 WaveTrackView.h
6 
7 Paul Licameli split from class WaveTrack
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_WAVE_TRACK_VIEW__
12 #define __AUDACITY_WAVE_TRACK_VIEW__
13 
14 #include "../../../ui/CommonTrackView.h"
15 #include "ClientData.h"
16 #include "SampleCount.h"
17 namespace WaveTrackViewConstants{ enum Display : int; }
19 
20 class CutlineHandle;
21 class TranslatableString;
22 class WaveTrack;
23 class WaveTrackView;
24 class WaveClip;
25 class WaveClipTrimHandle;
26 
27 
29 
30 namespace {
31  class SubViewCloseHandle;
32  class SubViewAdjustHandle;
33  class SubViewRearrangeHandle;
34 }
35 
36 class wxDC;
37 
38 class AUDACITY_DLL_API WaveTrackSubView : public CommonTrackView
39 {
40 public:
41 
44 
45  explicit
46  WaveTrackSubView( WaveTrackView &waveTrackView );
47 
48  virtual const Type &SubViewType() const = 0;
49 
50  // For undo and redo purpose
51  // Empty abstract method to be inherited, for copying the spectral data in SpectrumSubView
52  virtual void CopyToSubView(WaveTrackSubView *destSubView) const;
53 
54  std::pair<
55  bool, // if true, hit-testing is finished
56  std::vector<UIHandlePtr>
58  const TrackPanelMouseState &state,
59  const AudacityProject *pProject, int currentTool, bool bMultiTool,
60  const std::shared_ptr<WaveTrack> &wt );
61 
62 protected:
63  static void DrawBoldBoundaries(
64  TrackPanelDrawingContext &context, const WaveTrack *track,
65  const wxRect &rect );
66 
67  std::weak_ptr<WaveTrackView> GetWaveTrackView() const;
68 
69  std::vector<MenuItem> GetMenuItems(
70  const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject )
71  override;
72 
73 private:
74  std::weak_ptr<SubViewCloseHandle> mCloseHandle;
75  std::weak_ptr<TrackPanelResizeHandle> mResizeHandle;
76  std::weak_ptr<SubViewAdjustHandle> mAdjustHandle;
77  std::weak_ptr<SubViewRearrangeHandle> mRearrangeHandle;
78  std::weak_ptr<WaveClipTrimHandle> mClipTrimHandle;
79  std::weak_ptr<CutlineHandle> mCutlineHandle;
80  std::weak_ptr<WaveTrackView> mwWaveTrackView;
81 };
82 
84  int index;
85  float fraction;
86 };
87 using WaveTrackSubViewPlacements = std::vector< WaveTrackSubViewPlacement >;
88 
89 class WaveTrackView;
92 >;
93 
94 class AUDACITY_DLL_API WaveTrackView final
95  : public CommonTrackView
96  , public WaveTrackSubViews
97 {
98  WaveTrackView( const WaveTrackView& ) = delete;
99  WaveTrackView &operator=( const WaveTrackView& ) = delete;
100 
101 public:
102  static constexpr int kChannelSeparatorThickness{ 8 };
103 
105 
106  static WaveTrackView &Get( WaveTrack &track );
107  static const WaveTrackView &Get( const WaveTrack &track );
108 
109  explicit
110  WaveTrackView( const std::shared_ptr<Track> &pTrack );
111  ~WaveTrackView() override;
112 
113  // Preserve some view state too for undo/redo purposes
114  void CopyTo( Track &track ) const override;
115 
116  std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
117 
118  // CommonTrackView implementation
119  void Reparent( const std::shared_ptr<Track> &parent ) override;
120 
121  static std::pair<
122  bool, // if true, hit-testing is finished
123  std::vector<UIHandlePtr>
124  > DoDetailedHitTest(
125  const TrackPanelMouseState &state,
126  const AudacityProject *pProject, int currentTool, bool bMultiTool,
127  const std::shared_ptr<WaveTrack> &wt,
128  CommonTrackView &view);
129 
130  std::vector< WaveTrackSubView::Type > GetDisplays() const;
131  void SetDisplay(Display display, bool exclusive = true);
132 
134  { return mPlacements; }
136  { mPlacements = placements; }
137 
138  // Return true if successful. Fails if you try to toggle off the only
139  // sub-view.
140  bool ToggleSubView( Display id );
141 
142  // Get all the sub-views, in a sequence that is unspecified but in
143  // correspondence with the result of SavePlacements
144  std::vector< std::shared_ptr< WaveTrackSubView > > GetAllSubViews();
145 
146  // Return cached height of rect in last call of GetSubViews
147  wxCoord GetLastHeight() const { return mLastHeight; }
148 
149  bool GetMultiView() const { return mMultiView; }
150  void SetMultiView( bool value ) { mMultiView = value; }
151 
152 
153  std::weak_ptr<WaveClip> GetSelectedClip();
154 
155  // Returns a visible subset of subviews, sorted in the same
156  // order as they are supposed to be displayed
157 
158 
159  // Get the visible sub-views,
160  // if rect is provided then result will contain
161  // y coordinate for each subview within this rect
162  Refinement GetSubViews(const wxRect* rect = nullptr);
163 
164  unsigned CaptureKey
165  (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
166  AudacityProject* project) override;
167 
168  unsigned KeyDown(wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
169  AudacityProject* project) override;
170 
171  unsigned Char
172  (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
173  AudacityProject* project) override;
174 
175  unsigned LoseFocus(AudacityProject *project) override;
176 
177 private:
178  void BuildSubViews() const;
179  void DoSetDisplay(Display display, bool exclusive = true);
180 
181  // TrackPanelDrawable implementation
182  void Draw(
183  TrackPanelDrawingContext &context,
184  const wxRect &rect, unsigned iPass ) override;
185 
186  std::vector<UIHandlePtr> DetailedHitTest
187  (const TrackPanelMouseState &state,
188  const AudacityProject *pProject, int currentTool, bool bMultiTool)
189  override;
190 
191  // TrackView implementation
192  Refinement GetSubViews(const wxRect& rect) override;
193 
194 protected:
195  std::shared_ptr<CommonTrackCell> GetAffordanceControls() override;
196 
197  void DoSetMinimized( bool minimized ) override;
198 
199  // Placements are in correspondence with the array of sub-views
200  // in the WaveTrackSubViews base class, though their sequence is
201  // unspecified and maybe different in different platforms.
203  mutable wxCoord mLastHeight{};
204 
205  bool mMultiView{ false };
206 
207 private:
208  std::shared_ptr<CommonTrackCell> DoGetAffordance(const std::shared_ptr<Track>& track);
209 
210  std::shared_ptr<CommonTrackCell> mpAffordanceCellControl;
211 
212  std::weak_ptr<TrackPanelCell> mKeyEventDelegate;
213 };
214 
215 // Helper for drawing routines
216 class SelectedRegion;
217 class WaveClip;
218 class ZoomInfo;
219 
220 struct AUDACITY_DLL_API ClipParameters
221 {
222  // Do a bunch of calculations common to waveform and spectrum drawing.
224  (bool spectrum, const WaveTrack *track, const WaveClip *clip, const wxRect &rect,
225  const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo);
226 
227  double tOffset;
228  double rate;
229  double h; // absolute time of left edge of display
230  double tpre; // offset corrected time of left edge of display
231  double h1;
232  double tpost; // offset corrected time of right edge of display
233 
234  // Calculate actual selection bounds so that t0 > 0 and t1 < the
235  // end of the track
236  double t0;
237  double t1;
238 
241 
244 
245  wxRect hiddenMid;
247 
248  wxRect mid;
250 
251  // returns a clip rectangle restricted by viewRect,
252  // and with clipOffsetX - clip horizontal origin offset within view rect
253  static wxRect GetClipRect(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect);
254 };
255 
256 #endif
ClipParameters::tpost
double tpost
Definition: WaveTrackView.h:232
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
WaveTrackView::mPlacements
WaveTrackSubViewPlacements mPlacements
Definition: WaveTrackView.h:202
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
CommonTrackView
Definition: CommonTrackView.h:20
WaveTrackSubViewPlacement::fraction
float fraction
Definition: WaveTrackView.h:85
WaveTrackSubView::SubViewType
virtual const Type & SubViewType() const =0
ClipParameters::rate
double rate
Definition: WaveTrackView.h:228
WaveTrackView
Definition: WaveTrackView.h:97
WaveTrackView::operator=
WaveTrackView & operator=(const WaveTrackView &)=delete
TrackView::Get
static TrackView & Get(Track &)
Definition: TrackView.cpp:63
ClipParameters::averagePixelsPerSample
double averagePixelsPerSample
Definition: WaveTrackView.h:239
CutlineHandle
Definition: CutlineHandle.h:22
ZoomInfo
Definition: ZoomInfo.h:47
TrackPanelCell::KeyDown
virtual unsigned KeyDown(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
Definition: TrackPanelCell.cpp:62
WaveTrackViewConstants
Definition: WaveTrackView.h:17
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
ViewInfo
Definition: ViewInfo.h:202
WaveTrackView::RestorePlacements
void RestorePlacements(const WaveTrackSubViewPlacements &placements)
Definition: WaveTrackView.h:135
WaveTrackView::GetMultiView
bool GetMultiView() const
Definition: WaveTrackView.h:149
ClipParameters::h
double h
Definition: WaveTrackView.h:229
ClientData.h
Utility ClientData::Site to register hooks into a host class that attach client data.
WaveClipTrimHandle
Definition: WaveClipTrimHandle.h:20
WaveTrackViewConstants::Display
Display
Definition: WaveTrackViewConstants.h:18
ClipParameters::hiddenLeftOffset
int hiddenLeftOffset
Definition: WaveTrackView.h:246
TrackPanelResizeHandle
Definition: TrackPanelResizeHandle.h:19
WaveTrackView::GetLastHeight
wxCoord GetLastHeight() const
Definition: WaveTrackView.h:147
CommonTrackPanelCell::GetMenuItems
virtual std::vector< MenuItem > GetMenuItems(const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject)
Return a list of items for DoContextMenu() (empties for separators)
Definition: CommonTrackPanelCell.cpp:55
WaveTrackSubView
Definition: WaveTrackView.h:39
ClientData::SkipCopying
@ SkipCopying
ignore the source and leave empty
Definition: ClientDataHelpers.h:34
ClipParameters::ssel0
sampleCount ssel0
Definition: WaveTrackView.h:242
WaveTrackSubView::DoDetailedHitTest
std::pair< bool, std::vector< UIHandlePtr > > DoDetailedHitTest(const TrackPanelMouseState &state, const AudacityProject *pProject, int currentTool, bool bMultiTool, const std::shared_ptr< WaveTrack > &wt)
ClipParameters::hiddenMid
wxRect hiddenMid
Definition: WaveTrackView.h:245
SampleCount.h
WaveTrackSubView::mCloseHandle
std::weak_ptr< SubViewCloseHandle > mCloseHandle
Definition: WaveTrackView.h:74
WaveClip
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:175
ClipParameters::showIndividualSamples
bool showIndividualSamples
Definition: WaveTrackView.h:240
WaveTrackView::WaveTrackView
WaveTrackView(const WaveTrackView &)=delete
WaveTrackSubView::mClipTrimHandle
std::weak_ptr< WaveClipTrimHandle > mClipTrimHandle
Definition: WaveTrackView.h:78
WaveTrackSubViewType
Definition: WaveTrackViewConstants.h:91
ClipParameters::ssel1
sampleCount ssel1
Definition: WaveTrackView.h:243
TrackView::GetAffordanceControls
virtual std::shared_ptr< CommonTrackCell > GetAffordanceControls()
Definition: TrackView.cpp:168
ClientData::Site
Utility to register hooks into a host class that attach client data.
Definition: ClientData.h:220
WaveTrackSubView::mRearrangeHandle
std::weak_ptr< SubViewRearrangeHandle > mRearrangeHandle
Definition: WaveTrackView.h:77
ClipParameters
Definition: WaveTrackView.h:221
WaveTrackView::mKeyEventDelegate
std::weak_ptr< TrackPanelCell > mKeyEventDelegate
Definition: WaveTrackView.h:212
WaveTrackSubView::mwWaveTrackView
std::weak_ptr< WaveTrackView > mwWaveTrackView
Definition: WaveTrackView.h:80
WaveTrackSubViewPlacements
std::vector< WaveTrackSubViewPlacement > WaveTrackSubViewPlacements
Definition: WaveTrackView.h:87
WaveTrackSubView::mResizeHandle
std::weak_ptr< TrackPanelResizeHandle > mResizeHandle
Definition: WaveTrackView.h:75
TrackView::DoSetMinimized
virtual void DoSetMinimized(bool isMinimized)
Definition: TrackView.cpp:126
WaveTrackView::SavePlacements
const WaveTrackSubViewPlacements & SavePlacements() const
Definition: WaveTrackView.h:133
ClipParameters::tOffset
double tOffset
Definition: WaveTrackView.h:227
WaveTrackSubViewPlacement
Definition: WaveTrackView.h:83
TrackPanelCell::CaptureKey
virtual unsigned CaptureKey(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
Definition: TrackPanelCell.cpp:55
ClipParameters::t0
double t0
Definition: WaveTrackView.h:236
ClipParameters::leftOffset
int leftOffset
Definition: WaveTrackView.h:249
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
WaveTrackView::mpAffordanceCellControl
std::shared_ptr< CommonTrackCell > mpAffordanceCellControl
Definition: WaveTrackView.h:210
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
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
ClipParameters::h1
double h1
Definition: WaveTrackView.h:231
TrackView::GetSubViews
virtual Refinement GetSubViews(const wxRect &rect)
Definition: TrackView.cpp:116
ClipParameters::mid
wxRect mid
Definition: WaveTrackView.h:248
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
TrackView::CopyTo
void CopyTo(Track &track) const override
Definition: TrackView.cpp:52
ClipParameters::t1
double t1
Definition: WaveTrackView.h:237
CommonTrackCell::Reparent
virtual void Reparent(const std::shared_ptr< Track > &parent)
Definition: CommonTrackPanelCell.cpp:142
ClipParameters::tpre
double tpre
Definition: WaveTrackView.h:230
kChannelSeparatorThickness
@ kChannelSeparatorThickness
Definition: TrackPanelConstants.h:24
WaveTrackSubView::mCutlineHandle
std::weak_ptr< CutlineHandle > mCutlineHandle
Definition: WaveTrackView.h:79
WaveTrackSubView::mAdjustHandle
std::weak_ptr< SubViewAdjustHandle > mAdjustHandle
Definition: WaveTrackView.h:76
CommonTrackView::DetailedHitTest
virtual std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &, const AudacityProject *pProject, int currentTool, bool bMultiTool)=0
WaveTrackSubViewPlacement::index
int index
Definition: WaveTrackView.h:84
TrackPanelCell::Char
virtual unsigned Char(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
Definition: TrackPanelCell.cpp:76
TrackPanelCell::LoseFocus
virtual unsigned LoseFocus(AudacityProject *project)
Definition: TrackPanelCell.cpp:83
TrackView::DoGetVRulerControls
virtual std::shared_ptr< TrackVRulerControls > DoGetVRulerControls()=0
WaveTrackView::SetMultiView
void SetMultiView(bool value)
Definition: WaveTrackView.h:150
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35
TrackPanelDrawable::Draw
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
Definition: TrackPanelDrawable.cpp:17