Audacity 3.2.0
WaveChannelView.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5WaveChannelView.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/CommonChannelView.h"
15#include "ClientData.h"
16#include "SampleCount.h"
17namespace WaveChannelViewConstants{ enum Display : int; }
19
20class ClipTimes;
21class CutlineHandle;
23class SampleTrack;
24class WaveChannel;
25class WaveTrack;
26class WaveChannelView;
27class WaveClip;
29class ZoomInfo;
30
31
34
38
39class wxDC;
40
41class AUDACITY_DLL_API WaveChannelSubView : public CommonChannelView
42{
43public:
44
47
48 explicit
49 WaveChannelSubView(WaveChannelView &waveChannelView);
50
51 virtual const Type &SubViewType() const = 0;
52
53 // For undo and redo purpose
54 // Empty abstract method to be inherited, for copying the spectral data in SpectrumSubView
55 virtual void CopyToSubView(WaveChannelSubView *destSubView) const;
56
57 std::pair<
58 bool, // if true, hit-testing is finished
59 std::vector<UIHandlePtr>
60 > DoDetailedHitTest(
61 const TrackPanelMouseState &state,
62 const AudacityProject *pProject, int currentTool, bool bMultiTool,
63 const std::shared_ptr<WaveTrack> &wt );
64
65protected:
66 static void DrawBoldBoundaries(
67 TrackPanelDrawingContext &context, const WaveTrack &track,
68 const wxRect &rect);
69
70 std::weak_ptr<WaveChannelView> GetWaveChannelView() const;
71
72 std::vector<MenuItem> GetMenuItems(
73 const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject )
74 override;
75
76private:
77 std::weak_ptr<SubViewCloseHandle> mCloseHandle;
78 std::weak_ptr<TrackPanelResizeHandle> mResizeHandle;
79 std::weak_ptr<SubViewAdjustHandle> mAdjustHandle;
80 std::weak_ptr<SubViewRearrangeHandle> mRearrangeHandle;
81 std::weak_ptr<WaveClipAdjustBorderHandle> mClipBorderAdjustHandle;
82 std::weak_ptr<CutlineHandle> mCutlineHandle;
83 std::weak_ptr<WaveChannelView> mwWaveChannelView;
84};
85
87 int index;
88 float fraction;
89};
90using WaveChannelSubViewPlacements = std::vector<WaveChannelSubViewPlacement>;
91
92class WaveChannelView;
95>;
96
97class AUDACITY_DLL_API WaveChannelView final
98 : public CommonChannelView
99 , public WaveChannelSubViews
100{
103
104public:
105 static constexpr int kChannelSeparatorThickness{ 8 };
106
108
109 static WaveChannelView &Get(WaveChannel &channel);
110 static const WaveChannelView &Get(const WaveChannel &channel);
111 static WaveChannelView *Find(WaveChannel *pChannel);
112 static const WaveChannelView *Find(const WaveChannel *pChannel);
113
115
118 WaveChannelView(const std::shared_ptr<Track> &pTrack, size_t channel);
119 ~WaveChannelView() override;
120
121 // Preserve some view state too for undo/redo purposes
122 void CopyTo( Track &track ) const override;
123
124 std::shared_ptr<ChannelVRulerControls> DoGetVRulerControls() override;
125
126 // CommonChannelView implementation
127 void Reparent( const std::shared_ptr<Track> &parent ) override;
128
129 static std::pair<
130 bool, // if true, hit-testing is finished
131 std::vector<UIHandlePtr>
132 > DoDetailedHitTest(
133 const TrackPanelMouseState &state,
134 const AudacityProject *pProject, int currentTool, bool bMultiTool,
135 const std::shared_ptr<WaveTrack> &wt,
136 CommonChannelView &view);
137
138 std::vector<WaveChannelSubView::Type> GetDisplays() const;
139 void SetDisplay(Display display, bool exclusive = true);
140
142 { return DoGetPlacements(); }
144 { DoGetPlacements() = placements; }
145
146 // Return true if successful. Fails if you try to toggle off the only
147 // sub-view.
148 bool ToggleSubView( Display id );
149
150 // Get all the sub-views, in a sequence that is unspecified but in
151 // correspondence with the result of SavePlacements
152 std::vector<std::shared_ptr<WaveChannelSubView>> GetAllSubViews();
153
154 // Return cached height of rect in last call of GetSubViews
155 wxCoord GetLastHeight() const { return mLastHeight; }
156
157 bool GetMultiView() const { return DoGetMultiView(); }
158 void SetMultiView( bool value ) { DoGetMultiView() = value; }
159
160
161 std::weak_ptr<WaveClip> GetSelectedClip();
162
163 // Returns a visible subset of subviews, sorted in the same
164 // order as they are supposed to be displayed
165
166
167 // Get the visible sub-views,
168 // if rect is provided then result will contain
169 // y coordinate for each subview within this rect
170 Refinement GetSubViews(const wxRect* rect = nullptr);
171
172 unsigned CaptureKey
173 (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
174 AudacityProject* project) override;
175
176 unsigned KeyDown(wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
177 AudacityProject* project) override;
178
179 unsigned Char
180 (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent,
181 AudacityProject* project) override;
182
183 unsigned LoseFocus(AudacityProject *project) override;
184
185 static bool ClipDetailsVisible(
186 const ClipTimes& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect);
187 static wxRect ClipHitTestArea(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& viewRect);
188 static bool HitTest(const WaveClip& clip, const ZoomInfo& zoomInfo, const wxRect& rect, const wxPoint& pos);
189
190 //FIXME: These functions do not push state to undo history
191 //because attempt to do so leads to a focus lose which, in
192 //turn finalizes text editing (state is saved after text
193 //editing was intentionally finished instead)
194
195 bool CutSelectedText(AudacityProject& project);
196 bool CopySelectedText(AudacityProject& project);
197 bool PasteText(AudacityProject& project);
198 bool SelectAllText(AudacityProject& project);
199
200private:
201 void BuildSubViews() const;
202 void DoSetDisplay(Display display, bool exclusive = true);
203 bool SelectNextClip(ViewInfo& viewInfo, AudacityProject* project, bool forward);
204
205 // TrackPanelDrawable implementation
206 void Draw(
208 const wxRect &rect, unsigned iPass ) override;
209
210 std::vector<UIHandlePtr> DetailedHitTest
211 (const TrackPanelMouseState &state,
212 const AudacityProject *pProject, int currentTool, bool bMultiTool)
213 override;
214
215 // ChannelView implementation
216 Refinement GetSubViews(const wxRect& rect) override;
217
218private:
219 std::shared_ptr<CommonTrackCell> GetAffordanceControls() override;
220
221 void DoSetMinimized( bool minimized ) override;
222
223 // Placements are in correspondence with the array of sub-views
224 // in the WaveChannelSubViews base class, though their sequence is
225 // unspecified and maybe different in different platforms.
226 WaveChannelSubViewPlacements &DoGetPlacements();
227 const WaveChannelSubViewPlacements &DoGetPlacements() const;
228 mutable wxCoord mLastHeight{};
229
230 bool &DoGetMultiView();
231 bool DoGetMultiView() const;
232
233 std::shared_ptr<CommonTrackCell> DoGetAffordance(const std::shared_ptr<Track>& track);
234
235 std::shared_ptr<CommonTrackCell> mpAffordanceCellControl;
236
237 std::weak_ptr<TrackPanelCell> mKeyEventDelegate;
238
239 std::weak_ptr<WaveTrackAffordanceHandle> mAffordanceHandle;
240};
241
242// Helper for drawing routines
243class SelectedRegion;
244class WaveClip;
245class ZoomInfo;
246
247struct AUDACITY_DLL_API ClipParameters
248{
249 // Do a bunch of calculations common to waveform and spectrum drawing.
251 const ClipTimes &clip, const wxRect& rect, const ZoomInfo& zoomInfo);
252
253 const double trackRectT0; // absolute time of left edge of track
254
255 // Lower and upper visible time boundaries (relative to clip). If completely
256 // off-screen, `t0 == t1`.
257 double t0;
258 double t1;
259
262
263 wxRect hiddenMid;
265
266 wxRect mid;
268
269 // returns a clip rectangle restricted by viewRect,
270 // and with clipOffsetX - clip horizontal origin offset within view rect
271 static wxRect GetClipRect(
272 const ClipTimes& clip, const ZoomInfo& zoomInfo,
273 const wxRect& viewRect, bool* outShowSamples = nullptr);
274};
275
276#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
const auto project
@ kChannelSeparatorThickness
std::vector< WaveChannelSubViewPlacement > WaveChannelSubViewPlacements
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
virtual std::shared_ptr< ChannelVRulerControls > DoGetVRulerControls()=0
static ChannelView * Find(Channel *pChannel)
static ChannelView & Get(Channel &channel)
virtual std::shared_ptr< CommonTrackCell > GetAffordanceControls()
virtual void DoSetMinimized(bool isMinimized)
virtual Refinement GetSubViews(const wxRect &rect)
void CopyTo(Track &track) const override
Copy state, for undo/redo purposes.
Definition: ChannelView.cpp:60
Utility to register hooks into a host class that attach client data.
Definition: ClientData.h:228
Implements some hit-testing shared by many ChannelView subtypes.
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &, const AudacityProject *pProject) final
virtual std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &, const AudacityProject *pProject, int currentTool, bool bMultiTool)=0
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)
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:122
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)
Constructed from one channel, but changes height of all channels in a track.
Holds a msgid for the translation catalog; may also bind format arguments.
std::weak_ptr< SubViewAdjustHandle > mAdjustHandle
virtual const Type & SubViewType() const =0
std::weak_ptr< CutlineHandle > mCutlineHandle
std::weak_ptr< TrackPanelResizeHandle > mResizeHandle
std::weak_ptr< WaveChannelView > mwWaveChannelView
std::weak_ptr< WaveClipAdjustBorderHandle > mClipBorderAdjustHandle
std::weak_ptr< SubViewCloseHandle > mCloseHandle
std::weak_ptr< SubViewRearrangeHandle > mRearrangeHandle
void SetMultiView(bool value)
const WaveChannelSubViewPlacements & SavePlacements() const
bool GetMultiView() const
std::weak_ptr< WaveTrackAffordanceHandle > mAffordanceHandle
WaveChannelView & operator=(const WaveChannelView &)=delete
std::shared_ptr< CommonTrackCell > mpAffordanceCellControl
WaveChannelView(const WaveChannelView &)=delete
std::weak_ptr< TrackPanelCell > mKeyEventDelegate
wxCoord GetLastHeight() const
void RestorePlacements(const WaveChannelSubViewPlacements &placements)
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:103
Implements some features which are specific to Wave Clips.
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
@ SkipCopying
ignore the source and leave empty
const double trackRectT0
const double averagePixelsPerSecond
const bool showIndividualSamples