Audacity 3.2.0
ChannelView.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5ChannelView.h
6
7Paul Licameli split from class Track
8
9**********************************************************************/
10
11#ifndef __AUDACITY_TRACK_VIEW__
12#define __AUDACITY_TRACK_VIEW__
13
14#include <memory>
15#include "CommonTrackPanelCell.h" // to inherit
17
18class Channel;
19class ChannelGroup;
20class TrackList;
22
23class AUDACITY_DLL_API ChannelView /* not final */ : public CommonChannelCell
24 , public std::enable_shared_from_this<ChannelView>
25{
26 ChannelView(const ChannelView&) = delete;
28
29public:
30 enum : unsigned { DefaultHeight = 150 };
31
35 static ChannelView &Get(Channel &channel);
39 static const ChannelView &Get(const Channel &channel);
44 static ChannelView *Find(Channel *pChannel);
48 static const ChannelView *Find(const Channel *pChannel);
49
50 explicit ChannelView(const std::shared_ptr<Channel> &pChannel);
51 virtual ~ChannelView() = 0;
52
53 void Reparent(const std::shared_ptr<Track> &parent, size_t iChannel)
54 override;
55
56 // some static conveniences, useful for summation over track iterator
57 // ranges
58 static int GetChannelGroupHeight(const Track *pTrack);
59 // Total height of the given channel and all previous ones (constant time!)
60 static int GetCumulativeHeight(const Channel *pChannel);
61 // Total height of all Channels of the the given track and all previous ones
62 // (constant time!)
63 static int GetCumulativeHeight(const Track *pTrack);
64 static int GetTotalHeight(const TrackList &list);
65
66 // Copy view state, for undo/redo purposes
67 void CopyTo(Track &track, size_t iChannel) const override;
68
69 bool GetMinimized() const { return mMinimized; }
70 void SetMinimized( bool minimized );
71
73 int GetCumulativeHeightBefore() const { return mY; }
74
76
77 int GetExpandedHeight() const { return mHeight; }
78
80
81 virtual int GetMinimizedHeight() const = 0;
82
84
92 int GetHeight() const;
93
95 void SetCumulativeHeightBefore(int y) { DoSetY( y ); }
96
101 void SetExpandedHeight(int height);
102
103 // Return another, associated TrackPanelCell object that implements the
104 // mouse actions for the vertical ruler
105 std::shared_ptr<ChannelVRulerControls> GetVRulerControls();
106 std::shared_ptr<const ChannelVRulerControls> GetVRulerControls() const;
107
108 // Returns cell that would be used at affordance area, by default returns nullptr,
109 // meaning that track has no such area.
110 virtual std::shared_ptr<CommonTrackCell> GetAffordanceControls();
111
112 void WriteXMLAttributes(XMLWriter &writer, size_t iChannel) const override;
114 const std::string_view& attr, const XMLAttributeValueView& valueView,
115 size_t iChannel) override;
116
117 // New virtual function. The default just returns a one-element array
118 // containing this. Overrides might refine the Y axis.
119 using Refinement = std::vector<
120 std::pair<wxCoord, std::shared_ptr<ChannelView>>
121 >;
122 virtual Refinement GetSubViews( const wxRect &rect );
123
124 // default is false
125 virtual bool IsSpectral() const;
126
127 virtual void DoSetMinimized( bool isMinimized );
128
129 mutable std::pair<int, int> vrulerSize;
130
131private:
132 void AdjustPositions();
133
134 // No need yet to make this virtual
135 void DoSetY(int y);
136
137 void DoSetHeight(int h);
138
139protected:
140 // Private factory to make appropriate object; class ChannelView handles
141 // memory management thereafter
142 virtual std::shared_ptr<ChannelVRulerControls> DoGetVRulerControls() = 0;
143
144 std::shared_ptr<ChannelVRulerControls> mpVRulerControls;
145
146private:
150 static ChannelView &GetFromChannelGroup(
151 ChannelGroup &group, size_t iChannel);
155 static ChannelView *FindFromChannelGroup(
156 ChannelGroup *pGroup, size_t iChannel = 0);
157
158 bool mMinimized{ false };
159 int mY{ 0 };
160 int mHeight{ DefaultHeight };
161};
162
164
165struct DoGetViewTag;
166
168
173 DoGetViewTag,
174 std::shared_ptr<ChannelView>,
175 Track,
176 size_t// channel index
177>;
179
180struct GetDefaultTrackHeightTag;
181
184 GetDefaultTrackHeightTag,
185 int,
186 Channel
187>;
189
190#endif
Utility for non-intrusive definition of a new method on a base class.
DECLARE_EXPORTED_ATTACHED_VIRTUAL(AUDACITY_DLL_API, DoGetView)
Class template generates single-dispatch, open method registry tables.
virtual void WriteXMLAttributes(XMLWriter &writer, size_t iChannel) const
Serialize persistent attributes.
virtual bool HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &valueView, size_t iChannel)
Deserialize an attribute, returning true if recognized.
virtual void CopyTo(Track &track, size_t iChannel) const
Copy state, for undo/redo purposes.
virtual std::shared_ptr< ChannelVRulerControls > DoGetVRulerControls()=0
std::shared_ptr< ChannelVRulerControls > mpVRulerControls
Definition: ChannelView.h:144
virtual int GetMinimizedHeight() const =0
bool GetMinimized() const
Definition: ChannelView.h:69
void SetCumulativeHeightBefore(int y)
Set cached value dependent on position within the track list.
Definition: ChannelView.h:95
int GetCumulativeHeightBefore() const
Definition: ChannelView.h:73
std::vector< std::pair< wxCoord, std::shared_ptr< ChannelView > > > Refinement
Definition: ChannelView.h:121
int GetExpandedHeight() const
Definition: ChannelView.h:77
std::pair< int, int > vrulerSize
Definition: ChannelView.h:129
ChannelView(const ChannelView &)=delete
ChannelView & operator=(const ChannelView &)=delete
void Reparent(const std::shared_ptr< Track > &parent, size_t iChannel) override
Object may be shared among tracks but hold a special back-pointer to one of them; reassign it.
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
A view into an attribute value. The class does not take the ownership of the data.
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
PROJECT_FILE_IO_API wxString Find(const FilePath &path)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:201