Audacity  3.0.3
TrackView.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 TrackView.h
6 
7 Paul 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
16 
17 class Track;
18 class TrackList;
21 
22 class AUDACITY_DLL_API TrackView /* not final */ : public CommonTrackCell
23  , public std::enable_shared_from_this<TrackView>
24 {
25  TrackView( const TrackView& ) = delete;
26  TrackView &operator=( const TrackView& ) = delete;
27 
28 public:
29  enum : unsigned { DefaultHeight = 150 };
30 
31  explicit
32  TrackView( const std::shared_ptr<Track> &pTrack );
33  virtual ~TrackView() = 0;
34 
35  // some static conveniences, useful for summation over track iterator
36  // ranges
37  static int GetTrackHeight( const Track *pTrack );
38  static int GetChannelGroupHeight( const Track *pTrack );
39  // Total height of the given track and all previous ones (constant time!)
40  static int GetCumulativeHeight( const Track *pTrack );
41  static int GetTotalHeight( const TrackList &list );
42 
43  // Copy view state, for undo/redo purposes
44  void CopyTo( Track &track ) const override;
45 
46  static TrackView &Get( Track & );
47  static const TrackView &Get( const Track & );
48 
49  bool GetMinimized() const { return mMinimized; }
50  void SetMinimized( bool minimized );
51 
53  int GetCumulativeHeightBefore() const { return mY; }
54 
56 
57  int GetExpandedHeight() const { return mHeight; }
58 
60 
61  virtual int GetMinimizedHeight() const = 0;
62 
64 
72  int GetHeight() const;
73 
75  void SetCumulativeHeightBefore(int y) { DoSetY( y ); }
76 
81  void SetExpandedHeight(int height);
82 
83  // Return another, associated TrackPanelCell object that implements the
84  // mouse actions for the vertical ruler
85  std::shared_ptr<TrackVRulerControls> GetVRulerControls();
86  std::shared_ptr<const TrackVRulerControls> GetVRulerControls() const;
87 
88  // Returns cell that would be used at affordance area, by default returns nullptr,
89  // meaning that track has no such area.
90  virtual std::shared_ptr<CommonTrackCell> GetAffordanceControls();
91 
92  void WriteXMLAttributes( XMLWriter & ) const override;
93  bool HandleXMLAttribute( const wxChar *attr, const wxChar *value ) override;
94 
95  // New virtual function. The default just returns a one-element array
96  // containing this. Overrides might refine the Y axis.
97  using Refinement = std::vector< std::pair<
98  wxCoord, std::shared_ptr< TrackView >
99  > >;
100  virtual Refinement GetSubViews( const wxRect &rect );
101 
102  // default is false
103  virtual bool IsSpectral() const;
104 
105  virtual void DoSetMinimized( bool isMinimized );
106 
107 private:
108 
109  // No need yet to make this virtual
110  void DoSetY(int y);
111 
112  void DoSetHeight(int h);
113 
114 protected:
115 
116  // Private factory to make appropriate object; class TrackView handles
117  // memory management thereafter
118  virtual std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() = 0;
119 
120  std::shared_ptr<TrackVRulerControls> mpVRulerControls;
121 
122 private:
123  bool mMinimized{ false };
124  int mY{ 0 };
125  int mHeight{ DefaultHeight };
126 };
127 
128 #include "AttachedVirtualFunction.h"
129 
130 struct DoGetViewTag;
131 
132 using DoGetView =
134  DoGetViewTag,
135  std::shared_ptr< TrackView >,
136  Track
137 >;
139 
140 struct GetDefaultTrackHeightTag;
141 
144  GetDefaultTrackHeightTag,
145  int,
146  Track
147 >;
149 
150 #endif
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
TrackView::TrackView
TrackView(const TrackView &)=delete
CommonTrackCell::CopyTo
virtual void CopyTo(Track &track) const
Definition: CommonTrackPanelCell.cpp:138
TrackView::GetCumulativeHeightBefore
int GetCumulativeHeightBefore() const
Definition: TrackView.h:53
AttachedVirtualFunction
Class template generates single-dispatch, open method registry tables.
Definition: AttachedVirtualFunction.h:159
TrackView::GetMinimized
bool GetMinimized() const
Definition: TrackView.h:49
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1280
TrackView::Refinement
std::vector< std::pair< wxCoord, std::shared_ptr< TrackView > > > Refinement
Definition: TrackView.h:99
TrackView::operator=
TrackView & operator=(const TrackView &)=delete
TrackView::SetCumulativeHeightBefore
void SetCumulativeHeightBefore(int y)
Set cached value dependent on position within the track list.
Definition: TrackView.h:75
TrackVRulerControls
Definition: TrackVRulerControls.h:25
CommonTrackCell::WriteXMLAttributes
virtual void WriteXMLAttributes(XMLWriter &) const
Definition: CommonTrackPanelCell.cpp:152
CommonTrackPanelCell.h
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
TrackView::mpVRulerControls
std::shared_ptr< TrackVRulerControls > mpVRulerControls
Definition: TrackView.h:120
TrackView::GetExpandedHeight
int GetExpandedHeight() const
Definition: TrackView.h:57
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
TrackView
Definition: TrackView.h:24
TrackPanelResizerCell
Definition: TrackPanelResizerCell.h:24
CommonTrackCell::HandleXMLAttribute
virtual bool HandleXMLAttribute(const wxChar *attr, const wxChar *value)
Definition: CommonTrackPanelCell.cpp:156
TrackView::GetMinimizedHeight
virtual int GetMinimizedHeight() const =0
AttachedVirtualFunction.h
Utility for non-intrusive definition of a new method on a base class.
DECLARE_EXPORTED_ATTACHED_VIRTUAL
DECLARE_EXPORTED_ATTACHED_VIRTUAL(AUDACITY_DLL_API, DoGetView)
CommonTrackCell
Definition: CommonTrackPanelCell.h:99
TrackView::DoGetVRulerControls
virtual std::shared_ptr< TrackVRulerControls > DoGetVRulerControls()=0