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
74private:
75 std::weak_ptr<SubViewCloseHandle> mCloseHandle;
76 std::weak_ptr<TrackPanelResizeHandle> mResizeHandle;
77 std::weak_ptr<SubViewAdjustHandle> mAdjustHandle;
78 std::weak_ptr<SubViewRearrangeHandle> mRearrangeHandle;
79 std::weak_ptr<WaveClipTrimHandle> mClipTrimHandle;
80 std::weak_ptr<CutlineHandle> mCutlineHandle;
81 std::weak_ptr<WaveTrackView> mwWaveTrackView;
82};
83
85 int index;
86 float fraction;
87};
88using WaveTrackSubViewPlacements = std::vector< WaveTrackSubViewPlacement >;
89
90class WaveTrackView;
93>;
94
95class AUDACITY_DLL_API WaveTrackView final
96 : public CommonTrackView
97 , public WaveTrackSubViews
98{
99 WaveTrackView( const WaveTrackView& ) = delete;
101
102public:
103 static constexpr int kChannelSeparatorThickness{ 8 };
104
106
107 static WaveTrackView &Get( WaveTrack &track );
108 static const WaveTrackView &Get( const WaveTrack &track );
109 static WaveTrackView *Find( WaveTrack *pTrack );
110 static const WaveTrackView *Find( const WaveTrack *pTrack );
111
112 explicit
113 WaveTrackView( const std::shared_ptr<Track> &pTrack );
114 ~WaveTrackView() override;
115
116 // Preserve some view state too for undo/redo purposes
117 void CopyTo( Track &track ) const override;
118
119 std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
120
121 // CommonTrackView implementation
122 void Reparent( const std::shared_ptr<Track> &parent ) override;
123
124 static std::pair<
125 bool, // if true, hit-testing is finished
126 std::vector<UIHandlePtr>
127 > DoDetailedHitTest(
128 const TrackPanelMouseState &state,
129 const AudacityProject *pProject, int currentTool, bool bMultiTool,
130 const std::shared_ptr<WaveTrack> &wt,
131 CommonTrackView &view);
132
133 std::vector< WaveTrackSubView::Type > GetDisplays() const;
134 void SetDisplay(Display display, bool exclusive = true);
135
137 { return mPlacements; }
139 { mPlacements = placements; }
140
141 // Return true if successful. Fails if you try to toggle off the only
142 // sub-view.
143 bool ToggleSubView( Display id );
144
145 // Get all the sub-views, in a sequence that is unspecified but in
146 // correspondence with the result of SavePlacements
147 std::vector< std::shared_ptr< WaveTrackSubView > > GetAllSubViews();
148
149 // Return cached height of rect in last call of GetSubViews
150 wxCoord GetLastHeight() const { return mLastHeight; }
151
152 bool GetMultiView() const { return mMultiView; }
153 void SetMultiView( bool value ) { mMultiView = value; }
154
155
156 std::weak_ptr<WaveClip> GetSelectedClip();
157
158 // Returns a visible subset of subviews, sorted in the same
159 // order as they are supposed to be displayed
160
161
162 // Get the visible sub-views,
163 // if rect is provided then result will contain
164 // y coordinate for each subview within this rect
165 Refinement GetSubViews(const wxRect* rect = nullptr);
166
167 unsigned CaptureKey
168 (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
169 AudacityProject* project) override;
170
171 unsigned KeyDown(wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
172 AudacityProject* project) override;
173
174 unsigned Char
175 (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
176 AudacityProject* project) override;
177
178 unsigned LoseFocus(AudacityProject *project) override;
179
180 static bool ClipDetailsVisible(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect);
181 static wxRect ClipHitTestArea(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect);
182 static bool HitTest(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& rect, const wxPoint& pos);
183
184 //FIXME: These functions do not push state to undo history
185 //because attempt to do so leads to a focus lose which, in
186 //turn finalizes text editing (state is saved after text
187 //editing was intentionally finished instead)
188
189 bool CutSelectedText(AudacityProject& project);
190 bool CopySelectedText(AudacityProject& project);
191 bool PasteText(AudacityProject& project);
192 bool SelectAllText(AudacityProject& project);
193
194private:
195 void BuildSubViews() const;
196 void DoSetDisplay(Display display, bool exclusive = true);
197 bool SelectNextClip(ViewInfo& viewInfo, AudacityProject* project, bool forward);
198
199 // TrackPanelDrawable implementation
200 void Draw(
202 const wxRect &rect, unsigned iPass ) override;
203
204 std::vector<UIHandlePtr> DetailedHitTest
205 (const TrackPanelMouseState &state,
206 const AudacityProject *pProject, int currentTool, bool bMultiTool)
207 override;
208
209 // TrackView implementation
210 Refinement GetSubViews(const wxRect& rect) override;
211
212protected:
213 std::shared_ptr<CommonTrackCell> GetAffordanceControls() override;
214
215 void DoSetMinimized( bool minimized ) override;
216
217 // Placements are in correspondence with the array of sub-views
218 // in the WaveTrackSubViews base class, though their sequence is
219 // unspecified and maybe different in different platforms.
221 mutable wxCoord mLastHeight{};
222
223 bool mMultiView{ false };
224
225private:
226 std::shared_ptr<CommonTrackCell> DoGetAffordance(const std::shared_ptr<Track>& track);
227
228 std::shared_ptr<CommonTrackCell> mpAffordanceCellControl;
229
230 std::weak_ptr<TrackPanelCell> mKeyEventDelegate;
231
232 std::weak_ptr<WaveTrackAffordanceHandle> mAffordanceHandle;
233};
234
235// Helper for drawing routines
236class SelectedRegion;
237class WaveClip;
238class ZoomInfo;
239
240struct AUDACITY_DLL_API ClipParameters
241{
242 // Do a bunch of calculations common to waveform and spectrum drawing.
244 bool spectrum, const SampleTrack *track,
245 const WaveClip *clip, const wxRect &rect,
246 const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo);
247
248 double tOffset;
249 double rate;
250 double h; // absolute time of left edge of display
251 double tpre; // offset corrected time of left edge of display
252 double h1;
253 double tpost; // offset corrected time of right edge of display
254
255 // Calculate actual selection bounds so that t0 > 0 and t1 < the
256 // end of the track
257 double t0;
258 double t1;
259
262
265
266 wxRect hiddenMid;
268
269 wxRect mid;
271
272 // returns a clip rectangle restricted by viewRect,
273 // and with clipOffsetX - clip horizontal origin offset within view rect
274 static wxRect GetClipRect(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect, bool* outShowSamples = nullptr);
275};
276
277#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
@ kChannelSeparatorThickness
std::vector< WaveTrackSubViewPlacement > WaveTrackSubViewPlacements
Definition: WaveTrackView.h:88
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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:225
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:101
Implements some features which are specific to Wave Clips.
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
std::weak_ptr< TrackPanelResizeHandle > mResizeHandle
Definition: WaveTrackView.h:76
std::weak_ptr< SubViewAdjustHandle > mAdjustHandle
Definition: WaveTrackView.h:77
std::weak_ptr< SubViewRearrangeHandle > mRearrangeHandle
Definition: WaveTrackView.h:78
virtual const Type & SubViewType() const =0
std::weak_ptr< WaveTrackView > mwWaveTrackView
Definition: WaveTrackView.h:81
std::weak_ptr< WaveClipTrimHandle > mClipTrimHandle
Definition: WaveTrackView.h:79
std::weak_ptr< CutlineHandle > mCutlineHandle
Definition: WaveTrackView.h:80
std::weak_ptr< SubViewCloseHandle > mCloseHandle
Definition: WaveTrackView.h:75
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 WaveTrackSubViewPlacements & SavePlacements() const
WaveTrackSubViewPlacements mPlacements
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:18
@ SkipCopying
ignore the source and leave empty
sampleCount ssel1
sampleCount ssel0
double averagePixelsPerSample
bool showIndividualSamples