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 <memory>
20 #include "Prefs.h"
21 #include "XMLMethodRegistry.h"
22 #include "ZoomInfo.h" // to inherit
23 
24 
26 
27 struct SelectedRegionEvent : public wxEvent
28 {
29  SelectedRegionEvent( wxEventType commandType,
31 
32  wxEvent *Clone() const override;
33 
34  wxWeakRef< NotifyingSelectedRegion > pRegion;
35 };
36 
37 // To do: distinguish time changes from frequency changes perhaps?
38 wxDECLARE_EXPORTED_EVENT( SCREEN_GEOMETRY_API,
39  EVT_SELECTED_REGION_CHANGE, SelectedRegionEvent );
40 
41 // This heavyweight wrapper of the SelectedRegion structure emits events
42 // on mutating operations, that other classes can listen for.
43 class SCREEN_GEOMETRY_API NotifyingSelectedRegion : public wxEvtHandler
44 {
45 public:
46  // Expose SelectedRegion's const accessors
47  double t0 () const { return mRegion.t0(); }
48  double t1 () const { return mRegion.t1(); }
49  double f0 () const { return mRegion.f0(); }
50  double f1 () const { return mRegion.f1(); }
51  double fc () const { return mRegion.fc(); }
52  bool isPoint() const { return mRegion.isPoint(); }
53  double duration() const { return mRegion.duration(); }
54 
55  // Writing and reading of persistent fields -- the read is mutating but
56  // does not emit events
58  (XMLWriter &xmlFile,
59  const wxChar *legacyT0Name, const wxChar *legacyT1Name) const
60  { mRegion.WriteXMLAttributes(xmlFile, legacyT0Name, legacyT1Name); }
61 
64  Mutators(const wxString &legacyT0Name, const wxString &legacyT1Name);
65 
66  // const-only access allows assignment from this into a SelectedRegion
67  // or otherwise passing it into a function taking const SelectedRegion&
68  operator const SelectedRegion & () const { return mRegion; }
69 
70  // These are the event-emitting operations
71  NotifyingSelectedRegion& operator = ( const SelectedRegion &other );
72 
73  // Returns true iff the bounds got swapped
74  bool setTimes(double t0, double t1);
75 
76  // Returns true iff the bounds got swapped
77  bool setT0(double t, bool maySwap = true);
78 
79  // Returns true iff the bounds got swapped
80  bool setT1(double t, bool maySwap = true);
81 
82  void collapseToT0();
83 
84  void collapseToT1();
85 
86  void move(double delta);
87 
88  // Returns true iff the bounds got swapped
89  bool setFrequencies(double f0, double f1);
90 
91  // Returns true iff the bounds got swapped
92  bool setF0(double f, bool maySwap = true);
93 
94  // Returns true iff the bounds got swapped
95  bool setF1(double f, bool maySwap = true);
96 
97 private:
98  void Notify( bool delayed = false );
99 
101 };
102 
103 enum : int {
105 };
106 
107 enum : int {
108  kTrackInfoBtnSize = 18, // widely used dimension, usually height
113 };
114 
116 {
117 public:
118  PlayRegion() = default;
119 
120  PlayRegion( const PlayRegion& ) = delete;
122  {
123  mLocked = that.mLocked;
124  // Guarantee the equivalent un-swapped order of endpoints
125  mStart = that.GetStart();
126  mEnd = that.GetEnd();
127  return *this;
128  }
129 
130  bool Locked() const { return mLocked; }
131  void SetLocked( bool locked ) { mLocked = locked; }
132 
133  bool Empty() const { return GetStart() == GetEnd(); }
134  double GetStart() const
135  {
136  if ( mEnd < 0 )
137  return mStart;
138  else
139  return std::min( mStart, mEnd );
140  }
141  double GetEnd() const
142  {
143  if ( mStart < 0 )
144  return mEnd;
145  else
146  return std::max( mStart, mEnd );
147  }
148 
149  void SetStart( double start ) { mStart = start; }
150  void SetEnd( double end ) { mEnd = end; }
151  void SetTimes( double start, double end ) { mStart = start, mEnd = end; }
152 
153  void Order()
154  {
155  if ( mStart >= 0 && mEnd >= 0 && mStart > mEnd)
156  std::swap( mStart, mEnd );
157  }
158 
159 private:
160  // Times:
161  double mStart{ -1.0 };
162  double mEnd{ -1.0 };
163 
164  bool mLocked{ false };
165 };
166 
167 class SCREEN_GEOMETRY_API ViewInfo final
168  : public wxEvtHandler, public ZoomInfo
169 {
170 public:
171  static ViewInfo &Get( AudacityProject &project );
172  static const ViewInfo &Get( const AudacityProject &project );
173 
174  ViewInfo(double start, double screenDuration, double pixelsPerSecond);
175  ViewInfo( const ViewInfo & ) PROHIBITED;
176  ViewInfo &operator=( const ViewInfo & ) PROHIBITED;
177 
178  int GetHeight() const { return mHeight; }
179  void SetHeight( int height ) { mHeight = height; }
180 
181  static int UpdateScrollPrefsID();
182  void UpdatePrefs() override;
183  void UpdateSelectedPrefs( int id ) override;
184 
185  double GetBeforeScreenWidth() const
186  {
187  return h * zoom;
188  }
189  void SetBeforeScreenWidth(wxInt64 beforeWidth, wxInt64 screenWidth, double lowerBoundTime = 0.0);
190 
191  double GetTotalWidth() const
192  { return total * zoom; }
193 
194  // Current selection
195 
198 
199  // Scroll info
200 
201  double total; // total width in secs
202  // Current horizontal scroll bar positions, in pixels
203  wxInt64 sbarH;
204  wxInt64 sbarScreen;
205  wxInt64 sbarTotal;
206 
207  // Internal wxScrollbar positions are only int in range, so multiply
208  // the above values with the following member to get the actual
209  // scroll bar positions as reported by the horizontal wxScrollbar's members
210  // i.e. units are scroll increments per pixel
211  double sbarScale;
212 
213  // Vertical scroll step
215 
216  // Other stuff, mainly states (true or false) related to autoscroll and
217  // drawing the waveform. Maybe this should be put somewhere else?
218 
220 
223 
224  void WriteXMLAttributes(XMLWriter &xmlFile) const;
225 
226 private:
227  int mHeight{ 0 };
228 
229  struct ProjectFileIORegistration;
230 };
231 
232 extern SCREEN_GEOMETRY_API BoolSetting ScrollingPreference;
233 #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:153
XMLMethodRegistry.h
SelectedRegionEvent
Definition: ViewInfo.h:28
XMLMethodRegistryBase::Mutators
std::vector< std::pair< wxString, Mutator< Substructure > > > Mutators
A helper type alias for a list of mutators, associated with tag strings.
Definition: XMLMethodRegistry.h:36
PlayRegion::GetEnd
double GetEnd() const
Definition: ViewInfo.h:141
kTrackInfoSliderHeight
@ kTrackInfoSliderHeight
Definition: ViewInfo.h:109
NotifyingSelectedRegion::duration
double duration() const
Definition: ViewInfo.h:53
ViewInfo::bUpdateTrackIndicator
bool bUpdateTrackIndicator
Definition: ViewInfo.h:219
ZoomInfo::UpdatePrefs
void UpdatePrefs() override
Definition: ZoomInfo.cpp:31
wxDECLARE_EXPORTED_EVENT
wxDECLARE_EXPORTED_EVENT(SCREEN_GEOMETRY_API, EVT_SELECTED_REGION_CHANGE, SelectedRegionEvent)
PlayRegion::SetLocked
void SetLocked(bool locked)
Definition: ViewInfo.h:131
ViewInfo::playRegion
PlayRegion playRegion
Definition: ViewInfo.h:197
ZoomInfo
Definition: ZoomInfo.h:47
ViewInfo
Definition: ViewInfo.h:169
PlayRegion::GetStart
double GetStart() const
Definition: ViewInfo.h:134
BoolSetting
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Definition: Prefs.h:204
SelectedRegion.h
ViewInfo::sbarH
wxInt64 sbarH
Definition: ViewInfo.h:203
kTrackInfoBtnSize
@ kTrackInfoBtnSize
Definition: ViewInfo.h:108
PlayRegion::mEnd
double mEnd
Definition: ViewInfo.h:162
ViewInfo::sbarScreen
wxInt64 sbarScreen
Definition: ViewInfo.h:204
SelectedRegionEvent::Clone
wxEvent * Clone() const override
Definition: ViewInfo.cpp:29
ViewInfo::sbarTotal
wxInt64 sbarTotal
Definition: ViewInfo.h:205
NotifyingSelectedRegion::t1
double t1() const
Definition: ViewInfo.h:48
ViewInfo::bScrollBeyondZero
bool bScrollBeyondZero
Definition: ViewInfo.h:221
PlayRegion::mStart
double mStart
Definition: ViewInfo.h:161
ViewInfo::GetTotalWidth
double GetTotalWidth() const
Definition: ViewInfo.h:191
ViewInfo::scrollStep
int scrollStep
Definition: ViewInfo.h:214
PrefsListener::UpdateSelectedPrefs
virtual void UpdateSelectedPrefs(int id)
Definition: Prefs.cpp:127
anonymous_namespace{ProjectSettings.cpp}::Notify
void Notify(AudacityProject &project, ProjectSettings::EventCode code)
Definition: ProjectSettings.cpp:25
ZoomInfo.h
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:196
ViewInfo::operator=
ViewInfo & operator=(const ViewInfo &) PROHIBITED
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
PlayRegion::Locked
bool Locked() const
Definition: ViewInfo.h:130
PlayRegion::SetTimes
void SetTimes(double start, double end)
Definition: ViewInfo.h:151
PlayRegion::operator=
PlayRegion & operator=(const PlayRegion &that)
Definition: ViewInfo.h:121
kVerticalPadding
@ kVerticalPadding
Definition: ViewInfo.h:104
PlayRegion::SetEnd
void SetEnd(double end)
Definition: ViewInfo.h:150
NotifyingSelectedRegion::WriteXMLAttributes
void WriteXMLAttributes(XMLWriter &xmlFile, const wxChar *legacyT0Name, const wxChar *legacyT1Name) const
Definition: ViewInfo.h:58
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:735
PlayRegion
Definition: ViewInfo.h:116
NotifyingSelectedRegion::f0
double f0() const
Definition: ViewInfo.h:49
ViewInfo::ViewInfo
ViewInfo(const ViewInfo &) PROHIBITED
PlayRegion::PlayRegion
PlayRegion(const PlayRegion &)=delete
kTrackInfoSliderExtra
@ kTrackInfoSliderExtra
Definition: ViewInfo.h:112
kTrackInfoSliderAllowance
@ kTrackInfoSliderAllowance
Definition: ViewInfo.h:111
NotifyingSelectedRegion::mRegion
SelectedRegion mRegion
Definition: ViewInfo.h:100
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
NotifyingSelectedRegion::f1
double f1() const
Definition: ViewInfo.h:50
SelectedRegionEvent::SelectedRegionEvent
SelectedRegionEvent(wxEventType commandType, NotifyingSelectedRegion *pRegion)
Definition: ViewInfo.cpp:23
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
NotifyingSelectedRegion::fc
double fc() const
Definition: ViewInfo.h:51
PlayRegion::Empty
bool Empty() const
Definition: ViewInfo.h:133
ViewInfo::sbarScale
double sbarScale
Definition: ViewInfo.h:211
ViewInfo::SetHeight
void SetHeight(int height)
Definition: ViewInfo.h:179
PlayRegion::SetStart
void SetStart(double start)
Definition: ViewInfo.h:149
PlayRegion::mLocked
bool mLocked
Definition: ViewInfo.h:164
PlayRegion::PlayRegion
PlayRegion()=default
ViewInfo::GetBeforeScreenWidth
double GetBeforeScreenWidth() const
Definition: ViewInfo.h:185
ViewInfo::bAdjustSelectionEdges
bool bAdjustSelectionEdges
Definition: ViewInfo.h:222
NotifyingSelectedRegion::isPoint
bool isPoint() const
Definition: ViewInfo.h:52
NotifyingSelectedRegion::t0
double t0() const
Definition: ViewInfo.h:47
Prefs.h
ZoomInfo::zoom
double zoom
Definition: ZoomInfo.h:63
ViewInfo::GetHeight
int GetHeight() const
Definition: ViewInfo.h:178
ScrollingPreference
SCREEN_GEOMETRY_API BoolSetting ScrollingPreference
Definition: ViewInfo.cpp:266
ViewInfo::total
double total
Definition: ViewInfo.h:201
SelectedRegionEvent::pRegion
wxWeakRef< NotifyingSelectedRegion > pRegion
Definition: ViewInfo.h:34
NotifyingSelectedRegion
Definition: ViewInfo.h:44
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35
kTrackInfoSliderWidth
@ kTrackInfoSliderWidth
Definition: ViewInfo.h:110