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 #include "XMLAttributeValueView.h" 17 18 class Track; 19 class TrackList; 20 class TrackVRulerControls; 21 class TrackPanelResizerCell; 22 23 class AUDACITY_DLL_API TrackView /* not final */ : public CommonTrackCell 24 , public std::enable_shared_from_this<TrackView> 25 { 26 TrackView( const TrackView& ) = delete; 27 TrackView &operator=( const TrackView& ) = delete; 28 29 public: 30 enum : unsigned { DefaultHeight = 150 }; 31 32 explicit 33 TrackView( const std::shared_ptr<Track> &pTrack ); 34 virtual ~TrackView() = 0; 35 36 // some static conveniences, useful for summation over track iterator 37 // ranges 38 static int GetTrackHeight( const Track *pTrack ); 39 static int GetChannelGroupHeight( const Track *pTrack ); 40 // Total height of the given track and all previous ones (constant time!) 41 static int GetCumulativeHeight( const Track *pTrack ); 42 static int GetTotalHeight( const TrackList &list ); 43 44 // Copy view state, for undo/redo purposes 45 void CopyTo( Track &track ) const override; 46 47 static TrackView &Get( Track & ); 48 static const TrackView &Get( const Track & ); 49 GetMinimized()50 bool GetMinimized() const { return mMinimized; } 51 void SetMinimized( bool minimized ); 52 53 //! @return cached sum of `GetHeight()` of all preceding tracks GetCumulativeHeightBefore()54 int GetCumulativeHeightBefore() const { return mY; } 55 56 //! @return height of the track when expanded 57 /*! See other comments for GetHeight */ GetExpandedHeight()58 int GetExpandedHeight() const { return mHeight; } 59 60 //! @return height of the track when collapsed 61 /*! See other comments for GetHeight */ 62 virtual int GetMinimizedHeight() const = 0; 63 64 //! @return height of the track as it now appears, expanded or collapsed 65 /*! 66 Total "height" of channels of a track includes padding areas above and 67 below it, and is pixel-accurate for the channel group. 68 The "heights" of channels within a group determine the proportions of 69 heights of the track data shown -- but the actual total pixel heights 70 may differ when other fixed-height adornments and paddings are added, 71 according to other rules for allocation of height. 72 */ 73 int GetHeight() const; 74 75 //! Set cached value dependent on position within the track list SetCumulativeHeightBefore(int y)76 void SetCumulativeHeightBefore(int y) { DoSetY( y ); } 77 78 /*! Sets height for expanded state. 79 Does not expand a track if it is now collapsed. 80 See other comments for GetHeight 81 */ 82 void SetExpandedHeight(int height); 83 84 // Return another, associated TrackPanelCell object that implements the 85 // mouse actions for the vertical ruler 86 std::shared_ptr<TrackVRulerControls> GetVRulerControls(); 87 std::shared_ptr<const TrackVRulerControls> GetVRulerControls() const; 88 89 // Returns cell that would be used at affordance area, by default returns nullptr, 90 // meaning that track has no such area. 91 virtual std::shared_ptr<CommonTrackCell> GetAffordanceControls(); 92 93 void WriteXMLAttributes( XMLWriter & ) const override; 94 bool HandleXMLAttribute( const std::string_view& attr, const XMLAttributeValueView& valueView ) override; 95 96 // New virtual function. The default just returns a one-element array 97 // containing this. Overrides might refine the Y axis. 98 using Refinement = std::vector< std::pair< 99 wxCoord, std::shared_ptr< TrackView > 100 > >; 101 virtual Refinement GetSubViews( const wxRect &rect ); 102 103 // default is false 104 virtual bool IsSpectral() const; 105 106 virtual void DoSetMinimized( bool isMinimized ); 107 108 private: 109 110 // No need yet to make this virtual 111 void DoSetY(int y); 112 113 void DoSetHeight(int h); 114 115 protected: 116 117 // Private factory to make appropriate object; class TrackView handles 118 // memory management thereafter 119 virtual std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() = 0; 120 121 std::shared_ptr<TrackVRulerControls> mpVRulerControls; 122 123 private: 124 bool mMinimized{ false }; 125 int mY{ 0 }; 126 int mHeight{ DefaultHeight }; 127 }; 128 129 #include "AttachedVirtualFunction.h" 130 131 struct DoGetViewTag; 132 133 using DoGetView = 134 AttachedVirtualFunction< 135 DoGetViewTag, 136 std::shared_ptr< TrackView >, 137 Track 138 >; 139 DECLARE_EXPORTED_ATTACHED_VIRTUAL(AUDACITY_DLL_API, DoGetView); 140 141 struct GetDefaultTrackHeightTag; 142 143 using GetDefaultTrackHeight = 144 AttachedVirtualFunction< 145 GetDefaultTrackHeightTag, 146 int, 147 Track 148 >; 149 DECLARE_EXPORTED_ATTACHED_VIRTUAL(AUDACITY_DLL_API, GetDefaultTrackHeight); 150 151 #endif 152