Audacity 3.2.0
WaveTrackView.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5WaveTrackView.h
6
7Paul 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"
17namespace WaveTrackViewConstants{ enum Display : int; }
19
20class CutlineHandle;
22class SampleTrack;
23class WaveTrack;
24class WaveTrackView;
25class WaveClip;
27class ZoomInfo;
28
29
32
36
37class wxDC;
38
39class AUDACITY_DLL_API WaveTrackSubView : public CommonTrackView
40{
41public:
42
45
46 explicit
47 WaveTrackSubView(WaveTrackView &waveTrackView);
48
49 virtual const Type &SubViewType() const = 0;
50
51 // For undo and redo purpose
52 // Empty abstract method to be inherited, for copying the spectral data in SpectrumSubView
53 virtual void CopyToSubView(WaveTrackSubView *destSubView) const;
54
55 std::pair<
56 bool, // if true, hit-testing is finished
57 std::vector<UIHandlePtr>
58 > DoDetailedHitTest(
59 const TrackPanelMouseState &state,
60 const AudacityProject *pProject, int currentTool, bool bMultiTool,
61 const std::shared_ptr<WaveTrack> &wt );
62
63protected:
64 static void DrawBoldBoundaries(
65 TrackPanelDrawingContext &context, const WaveTrack *track,
66 const wxRect &rect );
67
68 std::weak_ptr<WaveTrackView> GetWaveTrackView() const;
69
70 std::vector<MenuItem> GetMenuItems(
71 const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject )
72 override;
73
74 // Which channel of a WaveTrack (it may contain wide clips)
75 const size_t mChannel;
76
77private:
78 std::weak_ptr<SubViewCloseHandle> mCloseHandle;
79 std::weak_ptr<TrackPanelResizeHandle> mResizeHandle;
80 std::weak_ptr<SubViewAdjustHandle> mAdjustHandle;
81 std::weak_ptr<SubViewRearrangeHandle> mRearrangeHandle;
82 std::weak_ptr<WaveClipTrimHandle> mClipTrimHandle;
83 std::weak_ptr<CutlineHandle> mCutlineHandle;
84 std::weak_ptr<WaveTrackView> mwWaveTrackView;
85};
86
88 int index;
89 float fraction;
90};
91using WaveTrackSubViewPlacements = std::vector< WaveTrackSubViewPlacement >;
92
93class WaveTrackView;
96>;
97
98class AUDACITY_DLL_API WaveTrackView final
99 : public CommonTrackView
100 , public WaveTrackSubViews
101{
102 WaveTrackView( const WaveTrackView& ) = delete;
104
105public:
106 static constexpr int kChannelSeparatorThickness{ 8 };
107
109
110 static WaveTrackView &Get( WaveTrack &track );
111 static const WaveTrackView &Get( const WaveTrack &track );
112 static WaveTrackView *Find( WaveTrack *pTrack );
113 static const WaveTrackView *Find( const WaveTrack *pTrack );
114
116
119 WaveTrackView(const std::shared_ptr<Track> &pTrack, size_t channel);
120 ~WaveTrackView() override;
121
122 size_t GetChannel() const { return mChannel; }
123
124 // Preserve some view state too for undo/redo purposes
125 void CopyTo( Track &track ) const override;
126
127 std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
128
129 // CommonTrackView implementation
130 void Reparent( const std::shared_ptr<Track> &parent ) override;
131
132 static std::pair<
133 bool, // if true, hit-testing is finished
134 std::vector<UIHandlePtr>
135 > DoDetailedHitTest(
136 const TrackPanelMouseState &state,
137 const AudacityProject *pProject, int currentTool, bool bMultiTool,
138 const std::shared_ptr<WaveTrack> &wt,
139 CommonTrackView &view);
140
141 std::vector< WaveTrackSubView::Type > GetDisplays() const;
142 void SetDisplay(Display display, bool exclusive = true);
143
145 { return DoGetPlacements(); }
147 { DoGetPlacements() = placements; }
148
149 // Return true if successful. Fails if you try to toggle off the only
150 // sub-view.
151 bool ToggleSubView( Display id );
152
153 // Get all the sub-views, in a sequence that is unspecified but in
154 // correspondence with the result of SavePlacements
155 std::vector< std::shared_ptr< WaveTrackSubView > > GetAllSubViews();
156
157 // Return cached height of rect in last call of GetSubViews
158 wxCoord GetLastHeight() const { return mLastHeight; }
159
160 bool GetMultiView() const { return DoGetMultiView(); }
161 void SetMultiView( bool value ) { DoGetMultiView() = value; }
162
163
164 std::weak_ptr<WaveClip> GetSelectedClip();
165
166 // Returns a visible subset of subviews, sorted in the same
167 // order as they are supposed to be displayed
168
169
170 // Get the visible sub-views,
171 // if rect is provided then result will contain
172 // y coordinate for each subview within this rect
173 Refinement GetSubViews(const wxRect* rect = nullptr);
174
175 unsigned CaptureKey
176 (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
177 AudacityProject* project) override;
178
179 unsigned KeyDown(wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
180 AudacityProject* project) override;
181
182 unsigned Char
183 (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
184 AudacityProject* project) override;
185
186 unsigned LoseFocus(AudacityProject *project) override;
187
188 static bool ClipDetailsVisible(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect);
189 static wxRect ClipHitTestArea(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect);
190 static bool HitTest(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& rect, const wxPoint& pos);
191
192 //FIXME: These functions do not push state to undo history
193 //because attempt to do so leads to a focus lose which, in
194 //turn finalizes text editing (state is saved after text
195 //editing was intentionally finished instead)
196
197 bool CutSelectedText(AudacityProject& project);
198 bool CopySelectedText(AudacityProject& project);
199 bool PasteText(AudacityProject& project);
200 bool SelectAllText(AudacityProject& project);
201
202private:
203 void BuildSubViews() const;
204 void DoSetDisplay(Display display, bool exclusive = true);
205 bool SelectNextClip(ViewInfo& viewInfo, AudacityProject* project, bool forward);
206
207 // TrackPanelDrawable implementation
208 void Draw(
210 const wxRect &rect, unsigned iPass ) override;
211
212 std::vector<UIHandlePtr> DetailedHitTest
213 (const TrackPanelMouseState &state,
214 const AudacityProject *pProject, int currentTool, bool bMultiTool)
215 override;
216
217 // TrackView implementation
218 Refinement GetSubViews(const wxRect& rect) override;
219
220private:
221 std::shared_ptr<CommonTrackCell> GetAffordanceControls() override;
222
223 void DoSetMinimized( bool minimized ) override;
224
225 // Placements are in correspondence with the array of sub-views
226 // in the WaveTrackSubViews base class, though their sequence is
227 // unspecified and maybe different in different platforms.
228 WaveTrackSubViewPlacements &DoGetPlacements();
229 const WaveTrackSubViewPlacements &DoGetPlacements() const;
230 mutable wxCoord mLastHeight{};
231
232 bool &DoGetMultiView();
233 bool DoGetMultiView() const;
234
235 std::shared_ptr<CommonTrackCell> DoGetAffordance(const std::shared_ptr<Track>& track);
236
237 std::shared_ptr<CommonTrackCell> mpAffordanceCellControl;
238
239 std::weak_ptr<TrackPanelCell> mKeyEventDelegate;
240
241 std::weak_ptr<WaveTrackAffordanceHandle> mAffordanceHandle;
242
243 const size_t mChannel;
244};
245
246// Helper for drawing routines
247class SelectedRegion;
248class WaveClip;
249class ZoomInfo;
250
251struct AUDACITY_DLL_API ClipParameters
252{
253 // Do a bunch of calculations common to waveform and spectrum drawing.
255 bool spectrum, const SampleTrack *track,
256 const WaveClip *clip, const wxRect &rect,
257 const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo);
258
259 double tOffset;
260 double rate;
261 double h; // absolute time of left edge of display
262 double tpre; // offset corrected time of left edge of display
263 double h1;
264 double tpost; // offset corrected time of right edge of display
265
266 // Calculate actual selection bounds so that t0 > 0 and t1 < the
267 // end of the track
268 double t0;
269 double t1;
270
273
276
277 wxRect hiddenMid;
279
280 wxRect mid;
282
283 // returns a clip rectangle restricted by viewRect,
284 // and with clipOffsetX - clip horizontal origin offset within view rect
285 static wxRect GetClipRect(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect, bool* outShowSamples = nullptr);
286};
287
288#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
@ kChannelSeparatorThickness
std::vector< WaveTrackSubViewPlacement > WaveTrackSubViewPlacements
Definition: WaveTrackView.h:91
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Utility to register hooks into a host class that attach client data.
Definition: ClientData.h:220
void Reparent(const std::shared_ptr< Track > &parent) override
Object may be shared among tracks but hold a special back-pointer to one of them; reassign it.
virtual std::vector< MenuItem > GetMenuItems(const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject)
Return a list of items for DoContextMenu() (empties for separators)
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &, const AudacityProject *pProject) final override
virtual std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &, const AudacityProject *pProject, int currentTool, bool bMultiTool)=0
Defines a selected portion of a project.
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:164
virtual unsigned KeyDown(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
virtual unsigned CaptureKey(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
virtual unsigned LoseFocus(AudacityProject *project)
virtual unsigned Char(wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
virtual void DoSetMinimized(bool isMinimized)
Definition: TrackView.cpp:141
static TrackView * Find(Track *)
Definition: TrackView.cpp:79
void CopyTo(Track &track) const override
Copy state, for undo/redo purposes.
Definition: TrackView.cpp:52
virtual Refinement GetSubViews(const wxRect &rect)
Definition: TrackView.cpp:131
virtual std::shared_ptr< TrackVRulerControls > DoGetVRulerControls()=0
static TrackView & Get(Track &)
Definition: TrackView.cpp:69
virtual std::shared_ptr< CommonTrackCell > GetAffordanceControls()
Definition: TrackView.cpp:183
Holds a msgid for the translation catalog; may also bind format arguments.
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:98
Implements some features which are specific to Wave Clips.
A Track that contains audio waveform data.
Definition: WaveTrack.h:54
std::weak_ptr< TrackPanelResizeHandle > mResizeHandle
Definition: WaveTrackView.h:79
std::weak_ptr< SubViewAdjustHandle > mAdjustHandle
Definition: WaveTrackView.h:80
std::weak_ptr< SubViewRearrangeHandle > mRearrangeHandle
Definition: WaveTrackView.h:81
virtual const Type & SubViewType() const =0
std::weak_ptr< WaveTrackView > mwWaveTrackView
Definition: WaveTrackView.h:84
std::weak_ptr< WaveClipTrimHandle > mClipTrimHandle
Definition: WaveTrackView.h:82
std::weak_ptr< CutlineHandle > mCutlineHandle
Definition: WaveTrackView.h:83
const size_t mChannel
Definition: WaveTrackView.h:75
std::weak_ptr< SubViewCloseHandle > mCloseHandle
Definition: WaveTrackView.h:78
void SetMultiView(bool value)
std::weak_ptr< TrackPanelCell > mKeyEventDelegate
WaveTrackView(const WaveTrackView &)=delete
wxCoord GetLastHeight() const
void RestorePlacements(const WaveTrackSubViewPlacements &placements)
bool GetMultiView() const
const size_t mChannel
const WaveTrackSubViewPlacements & SavePlacements() const
size_t GetChannel() const
WaveTrackView & operator=(const WaveTrackView &)=delete
std::weak_ptr< WaveTrackAffordanceHandle > mAffordanceHandle
std::shared_ptr< CommonTrackCell > mpAffordanceCellControl
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
@ SkipCopying
ignore the source and leave empty
sampleCount ssel1
sampleCount ssel0
double averagePixelsPerSample
bool showIndividualSamples