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;
23
24class AUDACITY_DLL_API ChannelView /* not final */ : public CommonTrackCell
25 , public std::enable_shared_from_this<ChannelView>
26{
27 ChannelView(const ChannelView&) = delete;
29
30public:
31 enum : unsigned { DefaultHeight = 150 };
32
36 static ChannelView &Get(Channel &channel);
40 static const ChannelView &Get(const Channel &channel);
45 static ChannelView *Find(Channel *pChannel);
49 static const ChannelView *Find(const Channel *pChannel);
50
52 ChannelView(const std::shared_ptr<Track> &pTrack, size_t iChannel);
53 virtual ~ChannelView() = 0;
54
55 // some static conveniences, useful for summation over track iterator
56 // ranges
57 static int GetChannelGroupHeight(const Track *pTrack);
58 // Total height of the given channel and all previous ones (constant time!)
59 static int GetCumulativeHeight(const Channel *pChannel);
60 // Total height of all Channels of the the given track and all previous ones
61 // (constant time!)
62 static int GetCumulativeHeight(const Track *pTrack);
63 static int GetTotalHeight(const TrackList &list);
64
65 // Copy view state, for undo/redo purposes
66 void CopyTo(Track &track) const override;
67
68 bool GetMinimized() const { return mMinimized; }
69 void SetMinimized( bool minimized );
70
72 int GetCumulativeHeightBefore() const { return mY; }
73
75
76 int GetExpandedHeight() const { return mHeight; }
77
79
80 virtual int GetMinimizedHeight() const = 0;
81
83
91 int GetHeight() const;
92
94 void SetCumulativeHeightBefore(int y) { DoSetY( y ); }
95
100 void SetExpandedHeight(int height);
101
102 // Return another, associated TrackPanelCell object that implements the
103 // mouse actions for the vertical ruler
104 std::shared_ptr<ChannelVRulerControls> GetVRulerControls();
105 std::shared_ptr<const ChannelVRulerControls> GetVRulerControls() const;
106
107 // Returns cell that would be used at affordance area, by default returns nullptr,
108 // meaning that track has no such area.
109 virtual std::shared_ptr<CommonTrackCell> GetAffordanceControls();
110
111 void WriteXMLAttributes( XMLWriter & ) const override;
113 const std::string_view& attr, const XMLAttributeValueView& valueView )
114 override;
115
116 // New virtual function. The default just returns a one-element array
117 // containing this. Overrides might refine the Y axis.
118 using Refinement = std::vector<
119 std::pair<wxCoord, std::shared_ptr<ChannelView>>
120 >;
121 virtual Refinement GetSubViews( const wxRect &rect );
122
123 // default is false
124 virtual bool IsSpectral() const;
125
126 virtual void DoSetMinimized( bool isMinimized );
127
128 mutable std::pair<int, int> vrulerSize;
129
130private:
131
132 // No need yet to make this virtual
133 void DoSetY(int y);
134
135 void DoSetHeight(int h);
136
137protected:
138
139 // Private factory to make appropriate object; class ChannelView handles
140 // memory management thereafter
141 virtual std::shared_ptr<ChannelVRulerControls> DoGetVRulerControls() = 0;
142
143 std::shared_ptr<ChannelVRulerControls> mpVRulerControls;
144
145private:
149 static ChannelView &GetFromChannelGroup(
150 ChannelGroup &group, size_t iChannel = 0);
154 static const ChannelView &GetFromChannelGroup(
155 const ChannelGroup &group, size_t iChannel = 0);
159 static ChannelView *FindFromChannelGroup(
160 ChannelGroup *pGroup, size_t iChannel = 0);
161
162 bool mMinimized{ false };
163 int mY{ 0 };
164 int mHeight{ DefaultHeight };
165};
166
168
169struct DoGetViewTag;
170
172
177 DoGetViewTag,
178 std::shared_ptr<ChannelView>,
179 Track,
180 size_t// channel index
181>;
183
184struct GetDefaultTrackHeightTag;
185
188 GetDefaultTrackHeightTag,
189 int,
190 Track
191>;
193
194#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 std::shared_ptr< ChannelVRulerControls > DoGetVRulerControls()=0
std::shared_ptr< ChannelVRulerControls > mpVRulerControls
Definition: ChannelView.h:143
virtual int GetMinimizedHeight() const =0
bool GetMinimized() const
Definition: ChannelView.h:68
void SetCumulativeHeightBefore(int y)
Set cached value dependent on position within the track list.
Definition: ChannelView.h:94
int GetCumulativeHeightBefore() const
Definition: ChannelView.h:72
std::vector< std::pair< wxCoord, std::shared_ptr< ChannelView > > > Refinement
Definition: ChannelView.h:120
int GetExpandedHeight() const
Definition: ChannelView.h:76
std::pair< int, int > vrulerSize
Definition: ChannelView.h:128
ChannelView(const ChannelView &)=delete
ChannelView & operator=(const ChannelView &)=delete
virtual bool HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &valueView)
Deserialize an attribute, returning true if recognized.
virtual void CopyTo(Track &track) const
Copy state, for undo/redo purposes.
virtual void WriteXMLAttributes(XMLWriter &) const
Serialize persistent attributes.
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:975
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:196