Audacity  3.0.3
ViewInfo.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ViewInfo.h
6 
7  Dominic Mazzoni
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_VIEWINFO__
12 #define __AUDACITY_VIEWINFO__
13 
14 #include <utility>
15 #include <vector>
16 #include <wx/event.h> // inherit wxEvtHandler
17 #include <wx/weakref.h> // member variable
18 #include "SelectedRegion.h"
19 #include "MemoryX.h"
20 #include "ZoomInfo.h" // to inherit
21 
22 
24 
25 struct SelectedRegionEvent : public wxEvent
26 {
27  SelectedRegionEvent( wxEventType commandType,
29 
30  wxEvent *Clone() const override;
31 
32  wxWeakRef< NotifyingSelectedRegion > pRegion;
33 };
34 
35 // To do: distinguish time changes from frequency changes perhaps?
36 wxDECLARE_EXPORTED_EVENT( AUDACITY_DLL_API,
37  EVT_SELECTED_REGION_CHANGE, SelectedRegionEvent );
38 
39 // This heavyweight wrapper of the SelectedRegion structure emits events
40 // on mutating operations, that other classes can listen for.
41 class NotifyingSelectedRegion : public wxEvtHandler
42 {
43 public:
44  // Expose SelectedRegion's const accessors
45  double t0 () const { return mRegion.t0(); }
46  double t1 () const { return mRegion.t1(); }
47  double f0 () const { return mRegion.f0(); }
48  double f1 () const { return mRegion.f1(); }
49  double fc () const { return mRegion.fc(); }
50  bool isPoint() const { return mRegion.isPoint(); }
51  double duration() const { return mRegion.duration(); }
52 
53  // Writing and reading of persistent fields -- the read is mutating but
54  // does not emit events
56  (XMLWriter &xmlFile,
57  const wxChar *legacyT0Name, const wxChar *legacyT1Name) const
58  { mRegion.WriteXMLAttributes(xmlFile, legacyT0Name, legacyT1Name); }
59 
61  (const wxChar *attr, const wxChar *value,
62  const wxChar *legacyT0Name, const wxChar *legacyT1Name);
63 
64  // const-only access allows assignment from this into a SelectedRegion
65  // or otherwise passing it into a function taking const SelectedRegion&
66  operator const SelectedRegion & () const { return mRegion; }
67 
68  // These are the event-emitting operations
70 
71  // Returns true iff the bounds got swapped
72  bool setTimes(double t0, double t1);
73 
74  // Returns true iff the bounds got swapped
75  bool setT0(double t, bool maySwap = true);
76 
77  // Returns true iff the bounds got swapped
78  bool setT1(double t, bool maySwap = true);
79 
80  void collapseToT0();
81 
82  void collapseToT1();
83 
84  void move(double delta);
85 
86  // Returns true iff the bounds got swapped
87  bool setFrequencies(double f0, double f1);
88 
89  // Returns true iff the bounds got swapped
90  bool setF0(double f, bool maySwap = true);
91 
92  // Returns true iff the bounds got swapped
93  bool setF1(double f, bool maySwap = true);
94 
95 private:
96  void Notify( bool delayed = false );
97 
99 };
100 
101 // See big pictorial comment in TrackPanel.cpp for explanation of these numbers
102 enum : int {
103  // constants related to y coordinates in the track panel
108 };
109 
110 enum : int {
111  kTrackInfoBtnSize = 18, // widely used dimension, usually height
116 };
117 
119 {
120 public:
121  PlayRegion() = default;
122 
123  PlayRegion( const PlayRegion& ) = delete;
125  {
126  mLocked = that.mLocked;
127  // Guarantee the equivalent un-swapped order of endpoints
128  mStart = that.GetStart();
129  mEnd = that.GetEnd();
130  return *this;
131  }
132 
133  bool Locked() const { return mLocked; }
134  void SetLocked( bool locked ) { mLocked = locked; }
135 
136  bool Empty() const { return GetStart() == GetEnd(); }
137  double GetStart() const
138  {
139  if ( mEnd < 0 )
140  return mStart;
141  else
142  return std::min( mStart, mEnd );
143  }
144  double GetEnd() const
145  {
146  if ( mStart < 0 )
147  return mEnd;
148  else
149  return std::max( mStart, mEnd );
150  }
151 
152  void SetStart( double start ) { mStart = start; }
153  void SetEnd( double end ) { mEnd = end; }
154  void SetTimes( double start, double end ) { mStart = start, mEnd = end; }
155 
156  void Order()
157  {
158  if ( mStart >= 0 && mEnd >= 0 && mStart > mEnd)
159  std::swap( mStart, mEnd );
160  }
161 
162 private:
163  // Times:
164  double mStart{ -1.0 };
165  double mEnd{ -1.0 };
166 
167  bool mLocked{ false };
168 };
169 
170 class AUDACITY_DLL_API ViewInfo final
171  : public wxEvtHandler, public ZoomInfo
172 {
173 public:
174  static ViewInfo &Get( AudacityProject &project );
175  static const ViewInfo &Get( const AudacityProject &project );
176 
177  ViewInfo(double start, double screenDuration, double pixelsPerSecond);
178  ViewInfo( const ViewInfo & ) PROHIBITED;
179  ViewInfo &operator=( const ViewInfo & ) PROHIBITED;
180 
181  int GetHeight() const { return mHeight; }
182  void SetHeight( int height ) { mHeight = height; }
183 
184  static int UpdateScrollPrefsID();
185  void UpdatePrefs() override;
186  void UpdateSelectedPrefs( int id ) override;
187 
188  double GetBeforeScreenWidth() const
189  {
190  return h * zoom;
191  }
192  void SetBeforeScreenWidth(wxInt64 beforeWidth, wxInt64 screenWidth, double lowerBoundTime = 0.0);
193 
194  double GetTotalWidth() const
195  { return total * zoom; }
196 
197  // Current selection
198 
201 
202  // Scroll info
203 
204  double total; // total width in secs
205  // Current horizontal scroll bar positions, in pixels
206  wxInt64 sbarH;
207  wxInt64 sbarScreen;
208  wxInt64 sbarTotal;
209 
210  // Internal wxScrollbar positions are only int in range, so multiply
211  // the above values with the following member to get the actual
212  // scroll bar positions as reported by the horizontal wxScrollbar's members
213  // i.e. units are scroll increments per pixel
214  double sbarScale;
215 
216  // Vertical scroll step
218 
219  // Other stuff, mainly states (true or false) related to autoscroll and
220  // drawing the waveform. Maybe this should be put somewhere else?
221 
223 
226 
227  // During timer update, grab the volatile stream time just once, so that
228  // various other drawing code can use the exact same value.
230 
231  void WriteXMLAttributes(XMLWriter &xmlFile) const;
232  bool ReadXMLAttribute(const wxChar *attr, const wxChar *value);
233 
234  // Receive track panel timer notifications
235  void OnTimer(wxCommandEvent &event);
236 
237 private:
238  int mHeight{ 0 };
239 };
240 
241 #endif
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
PlayRegion::Order
void Order()
Definition: ViewInfo.h:156
SelectedRegionEvent
Definition: ViewInfo.h:26
PlayRegion::GetEnd
double GetEnd() const
Definition: ViewInfo.h:144
kTrackInfoSliderHeight
@ kTrackInfoSliderHeight
Definition: ViewInfo.h:112
kShadowThickness
@ kShadowThickness
Definition: ZoomInfo.h:29
NotifyingSelectedRegion::duration
double duration() const
Definition: ViewInfo.h:51
ViewInfo::bUpdateTrackIndicator
bool bUpdateTrackIndicator
Definition: ViewInfo.h:222
NotifyingSelectedRegion::HandleXMLAttribute
bool HandleXMLAttribute(const wxChar *attr, const wxChar *value, const wxChar *legacyT0Name, const wxChar *legacyT1Name)
Definition: ViewInfo.cpp:38
ZoomInfo::UpdatePrefs
void UpdatePrefs() override
Definition: ZoomInfo.cpp:35
PlayRegion::SetLocked
void SetLocked(bool locked)
Definition: ViewInfo.h:134
SelectedRegion::t1
double t1() const
Definition: SelectedRegion.h:95
NotifyingSelectedRegion::setF0
bool setF0(double f, bool maySwap=true)
Definition: ViewInfo.cpp:122
SelectedRegion::isPoint
bool isPoint() const
Definition: SelectedRegion.h:97
ViewInfo::playRegion
PlayRegion playRegion
Definition: ViewInfo.h:200
ZoomInfo
Definition: ZoomInfo.h:47
ViewInfo
Definition: ViewInfo.h:172
PlayRegion::GetStart
double GetStart() const
Definition: ViewInfo.h:137
NotifyingSelectedRegion::collapseToT0
void collapseToT0()
Definition: ViewInfo.cpp:88
SelectedRegion.h
NotifyingSelectedRegion::setF1
bool setF1(double f, bool maySwap=true)
Definition: ViewInfo.cpp:132
ViewInfo::sbarH
wxInt64 sbarH
Definition: ViewInfo.h:206
kTrackInfoBtnSize
@ kTrackInfoBtnSize
Definition: ViewInfo.h:111
PlayRegion::mEnd
double mEnd
Definition: ViewInfo.h:165
ViewInfo::sbarScreen
wxInt64 sbarScreen
Definition: ViewInfo.h:207
SelectedRegionEvent::Clone
wxEvent * Clone() const override
Definition: ViewInfo.cpp:32
ViewInfo::sbarTotal
wxInt64 sbarTotal
Definition: ViewInfo.h:208
SelectedRegion::WriteXMLAttributes
void WriteXMLAttributes(XMLWriter &xmlFile, const wxChar *legacyT0Name=sDefaultT0Name, const wxChar *legacyT1Name=sDefaultT1Name) const
Definition: SelectedRegion.cpp:26
NotifyingSelectedRegion::t1
double t1() const
Definition: ViewInfo.h:46
ViewInfo::bScrollBeyondZero
bool bScrollBeyondZero
Definition: ViewInfo.h:224
PlayRegion::mStart
double mStart
Definition: ViewInfo.h:164
ViewInfo::GetTotalWidth
double GetTotalWidth() const
Definition: ViewInfo.h:194
ViewInfo::scrollStep
int scrollStep
Definition: ViewInfo.h:217
NotifyingSelectedRegion::setTimes
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:58
PrefsListener::UpdateSelectedPrefs
virtual void UpdateSelectedPrefs(int id)
Definition: Prefs.cpp:99
ZoomInfo.h
NotifyingSelectedRegion::Notify
void Notify(bool delayed=false)
Definition: ViewInfo.cpp:142
kBorderThickness
@ kBorderThickness
Definition: ZoomInfo.h:28
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:199
NotifyingSelectedRegion::collapseToT1
void collapseToT1()
Definition: ViewInfo.cpp:96
NotifyingSelectedRegion::setT1
bool setT1(double t, bool maySwap=true)
Definition: ViewInfo.cpp:78
ViewInfo::operator=
ViewInfo & operator=(const ViewInfo &) PROHIBITED
PlayRegion::Locked
bool Locked() const
Definition: ViewInfo.h:133
PlayRegion::SetTimes
void SetTimes(double start, double end)
Definition: ViewInfo.h:154
kTopInset
@ kTopInset
Definition: ViewInfo.h:104
PlayRegion::operator=
PlayRegion & operator=(const PlayRegion &that)
Definition: ViewInfo.h:124
PlayRegion::SetEnd
void SetEnd(double end)
Definition: ViewInfo.h:153
NotifyingSelectedRegion::WriteXMLAttributes
void WriteXMLAttributes(XMLWriter &xmlFile, const wxChar *legacyT0Name, const wxChar *legacyT1Name) const
Definition: ViewInfo.h:56
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:733
PlayRegion
Definition: ViewInfo.h:119
SelectedRegion::duration
double duration() const
Definition: SelectedRegion.h:96
wxDECLARE_EXPORTED_EVENT
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_SELECTED_REGION_CHANGE, SelectedRegionEvent)
kBottomMargin
@ kBottomMargin
Definition: ViewInfo.h:106
kTopMargin
@ kTopMargin
Definition: ViewInfo.h:105
kSeparatorThickness
@ kSeparatorThickness
Definition: ViewInfo.h:107
NotifyingSelectedRegion::f0
double f0() const
Definition: ViewInfo.h:47
ViewInfo::ViewInfo
ViewInfo(const ViewInfo &) PROHIBITED
PlayRegion::PlayRegion
PlayRegion(const PlayRegion &)=delete
kTrackInfoSliderExtra
@ kTrackInfoSliderExtra
Definition: ViewInfo.h:115
kTrackInfoSliderAllowance
@ kTrackInfoSliderAllowance
Definition: ViewInfo.h:114
NotifyingSelectedRegion::mRegion
SelectedRegion mRegion
Definition: ViewInfo.h:98
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
NotifyingSelectedRegion::f1
double f1() const
Definition: ViewInfo.h:48
SelectedRegion::t0
double t0() const
Definition: SelectedRegion.h:94
SelectedRegionEvent::SelectedRegionEvent
SelectedRegionEvent(wxEventType commandType, NotifyingSelectedRegion *pRegion)
Definition: ViewInfo.cpp:26
MemoryX.h
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
NotifyingSelectedRegion::operator=
NotifyingSelectedRegion & operator=(const SelectedRegion &other)
Definition: ViewInfo.cpp:49
NotifyingSelectedRegion::fc
double fc() const
Definition: ViewInfo.h:49
PlayRegion::Empty
bool Empty() const
Definition: ViewInfo.h:136
ViewInfo::sbarScale
double sbarScale
Definition: ViewInfo.h:214
ViewInfo::SetHeight
void SetHeight(int height)
Definition: ViewInfo.h:182
PlayRegion::SetStart
void SetStart(double start)
Definition: ViewInfo.h:152
PlayRegion::mLocked
bool mLocked
Definition: ViewInfo.h:167
NotifyingSelectedRegion::setT0
bool setT0(double t, bool maySwap=true)
Definition: ViewInfo.cpp:68
PlayRegion::PlayRegion
PlayRegion()=default
ViewInfo::GetBeforeScreenWidth
double GetBeforeScreenWidth() const
Definition: ViewInfo.h:188
ViewInfo::bAdjustSelectionEdges
bool bAdjustSelectionEdges
Definition: ViewInfo.h:225
NotifyingSelectedRegion::isPoint
bool isPoint() const
Definition: ViewInfo.h:50
NotifyingSelectedRegion::t0
double t0() const
Definition: ViewInfo.h:45
NotifyingSelectedRegion::move
void move(double delta)
Definition: ViewInfo.cpp:104
NotifyingSelectedRegion::setFrequencies
bool setFrequencies(double f0, double f1)
Definition: ViewInfo.cpp:112
ZoomInfo::zoom
double zoom
Definition: ZoomInfo.h:63
ViewInfo::GetHeight
int GetHeight() const
Definition: ViewInfo.h:181
ViewInfo::mRecentStreamTime
double mRecentStreamTime
Definition: ViewInfo.h:229
ViewInfo::total
double total
Definition: ViewInfo.h:204
SelectedRegionEvent::pRegion
wxWeakRef< NotifyingSelectedRegion > pRegion
Definition: ViewInfo.h:32
NotifyingSelectedRegion
Definition: ViewInfo.h:42
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:38
kTrackInfoSliderWidth
@ kTrackInfoSliderWidth
Definition: ViewInfo.h:113