Audacity  3.2.0
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/weakref.h> // member variable
17 #include "SelectedRegion.h"
18 #include <memory>
19 #include "Observer.h"
20 #include "Prefs.h"
21 #include "XMLMethodRegistry.h"
22 #include "ZoomInfo.h" // to inherit
23 
25 
26 // This heavyweight wrapper of the SelectedRegion structure emits events
27 // on mutating operations, that other classes can listen for.
28 class SCREEN_GEOMETRY_API NotifyingSelectedRegion
29  : public Observer::Publisher<NotifyingSelectedRegionMessage>
30  , public wxTrackable
31 {
32 public:
33  // Expose SelectedRegion's const accessors
34  double t0 () const { return mRegion.t0(); }
35  double t1 () const { return mRegion.t1(); }
36  double f0 () const { return mRegion.f0(); }
37  double f1 () const { return mRegion.f1(); }
38  double fc () const { return mRegion.fc(); }
39  bool isPoint() const { return mRegion.isPoint(); }
40  double duration() const { return mRegion.duration(); }
41 
42  // Writing and reading of persistent fields -- the read is mutating but
43  // does not emit events
45  (XMLWriter &xmlFile,
46  const char *legacyT0Name, const char *legacyT1Name) const
47  { mRegion.WriteXMLAttributes(xmlFile, legacyT0Name, legacyT1Name); }
48 
51  Mutators(const char *legacyT0Name, const char *legacyT1Name);
52 
53  // const-only access allows assignment from this into a SelectedRegion
54  // or otherwise passing it into a function taking const SelectedRegion&
55  operator const SelectedRegion & () const { return mRegion; }
56 
57  // These are the event-emitting operations
59 
60  // Returns true iff the bounds got swapped
61  bool setTimes(double t0, double t1);
62 
63  // Returns true iff the bounds got swapped
64  bool setT0(double t, bool maySwap = true);
65 
66  // Returns true iff the bounds got swapped
67  bool setT1(double t, bool maySwap = true);
68 
69  void collapseToT0();
70 
71  void collapseToT1();
72 
73  void move(double delta);
74 
75  // Returns true iff the bounds got swapped
76  bool setFrequencies(double f0, double f1);
77 
78  // Returns true iff the bounds got swapped
79  bool setF0(double f, bool maySwap = true);
80 
81  // Returns true iff the bounds got swapped
82  bool setF1(double f, bool maySwap = true);
83 
84 private:
85  void Notify( bool delayed = false );
86 
88 };
89 
90 enum : int {
92 };
93 
94 enum : int {
95  kTrackInfoBtnSize = 18, // widely used dimension, usually height
100 };
101 
103 
104 class SCREEN_GEOMETRY_API PlayRegion
105  : public Observer::Publisher<PlayRegionMessage>
106 {
107 public:
108  PlayRegion() = default;
109 
110  PlayRegion( const PlayRegion& ) = delete;
112  {
113  mActive = that.mActive;
114  // Guarantee the equivalent un-swapped order of endpoints
115  mStart = that.GetStart();
116  mEnd = that.GetEnd();
117  mLastActiveStart = that.GetLastActiveStart();
118  mLastActiveEnd = that.GetLastActiveEnd();
119  return *this;
120  }
121 
122  bool Active() const { return mActive; }
123  void SetActive( bool active );
124 
125  bool Empty() const { return GetStart() == GetEnd(); }
126  double GetStart() const
127  {
128  if ( mEnd < 0 )
129  return mStart;
130  else
131  return std::min( mStart, mEnd );
132  }
133  double GetEnd() const
134  {
135  if ( mStart < 0 )
136  return mEnd;
137  else
138  return std::max( mStart, mEnd );
139  }
140  double GetLastActiveStart() const
141  {
142  if ( mLastActiveEnd < 0 )
143  return mLastActiveStart;
144  else
145  return std::min( mLastActiveStart, mLastActiveEnd );
146  }
147  double GetLastActiveEnd() const
148  {
149  if ( mLastActiveStart < 0 )
150  return mLastActiveEnd;
151  else
152  return std::max( mLastActiveStart, mLastActiveEnd );
153  }
154 
155  void SetStart( double start );
156  void SetEnd( double end );
157  void SetTimes( double start, double end );
158  // Set current and last active times the same regardless of activation:
159  void SetAllTimes( double start, double end );
160 
162  void Clear();
164  bool IsClear() const;
166  bool IsLastActiveRegionClear() const;
167 
168  void Order();
169 
170 private:
171  void Notify();
172 
173  // Times:
174  static constexpr auto invalidValue = std::numeric_limits<double>::min();
175 
176  double mStart { invalidValue };
177  double mEnd { invalidValue };
178  double mLastActiveStart { invalidValue };
179  double mLastActiveEnd { invalidValue };
180 
181  bool mActive{ false };
182 };
183 
184 extern SCREEN_GEOMETRY_API const TranslatableString LoopToggleText;
185 
186 class SCREEN_GEOMETRY_API ViewInfo final
187  : public ZoomInfo
188 {
189 public:
190  static ViewInfo &Get( AudacityProject &project );
191  static const ViewInfo &Get( const AudacityProject &project );
192 
193  ViewInfo(double start, double screenDuration, double pixelsPerSecond);
194  ViewInfo( const ViewInfo & ) PROHIBITED;
195  ViewInfo &operator=( const ViewInfo & ) PROHIBITED;
196 
197  int GetHeight() const { return mHeight; }
198  void SetHeight( int height ) { mHeight = height; }
199 
200  static int UpdateScrollPrefsID();
201  void UpdatePrefs() override;
202  void UpdateSelectedPrefs( int id ) override;
203 
204  double GetBeforeScreenWidth() const
205  {
206  return h * zoom;
207  }
208  void SetBeforeScreenWidth(wxInt64 beforeWidth, wxInt64 screenWidth, double lowerBoundTime = 0.0);
209 
210  double GetTotalWidth() const
211  { return total * zoom; }
212 
213  // Current selection
214 
217 
218  // Scroll info
219 
220  double total; // total width in secs
221  // Current horizontal scroll bar positions, in pixels
222  wxInt64 sbarH;
223  wxInt64 sbarScreen;
224  wxInt64 sbarTotal;
225 
226  // Internal wxScrollbar positions are only int in range, so multiply
227  // the above values with the following member to get the actual
228  // scroll bar positions as reported by the horizontal wxScrollbar's members
229  // i.e. units are scroll increments per pixel
230  double sbarScale;
231 
232  // Vertical scroll step
234 
235  // Other stuff, mainly states (true or false) related to autoscroll and
236  // drawing the waveform. Maybe this should be put somewhere else?
237 
239 
242 
243  void WriteXMLAttributes(XMLWriter &xmlFile) const;
244 
245 private:
246  int mHeight{ 0 };
247 
248  struct ProjectFileIORegistration;
249 };
250 
251 extern SCREEN_GEOMETRY_API BoolSetting ScrollingPreference;
252 #endif
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
XMLMethodRegistry.h
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
NotifyingSelectedRegion::WriteXMLAttributes
void WriteXMLAttributes(XMLWriter &xmlFile, const char *legacyT0Name, const char *legacyT1Name) const
Definition: ViewInfo.h:45
PlayRegion::GetLastActiveEnd
double GetLastActiveEnd() const
Definition: ViewInfo.h:147
PlayRegion::GetEnd
double GetEnd() const
Definition: ViewInfo.h:133
kTrackInfoSliderHeight
@ kTrackInfoSliderHeight
Definition: ViewInfo.h:96
PlayRegionMessage
Definition: ViewInfo.h:102
NotifyingSelectedRegion::duration
double duration() const
Definition: ViewInfo.h:40
ViewInfo::bUpdateTrackIndicator
bool bUpdateTrackIndicator
Definition: ViewInfo.h:238
ZoomInfo::UpdatePrefs
void UpdatePrefs() override
Definition: ZoomInfo.cpp:33
ViewInfo::playRegion
PlayRegion playRegion
Definition: ViewInfo.h:216
ZoomInfo
Definition: ZoomInfo.h:47
ViewInfo
Definition: ViewInfo.h:188
PlayRegion::GetStart
double GetStart() const
Definition: ViewInfo.h:126
Observer.h
BoolSetting
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Definition: Prefs.h:203
SelectedRegion.h
ViewInfo::sbarH
wxInt64 sbarH
Definition: ViewInfo.h:222
kTrackInfoBtnSize
@ kTrackInfoBtnSize
Definition: ViewInfo.h:95
XMLMethodRegistryBase::Mutators
std::vector< std::pair< std::string, Mutator< Substructure > > > Mutators
A helper type alias for a list of mutators, associated with tag strings.
Definition: XMLMethodRegistry.h:39
Observer::Publisher::operator=
Publisher & operator=(Publisher &&)=default
ViewInfo::sbarScreen
wxInt64 sbarScreen
Definition: ViewInfo.h:223
ViewInfo::sbarTotal
wxInt64 sbarTotal
Definition: ViewInfo.h:224
NotifyingSelectedRegion::t1
double t1() const
Definition: ViewInfo.h:35
ViewInfo::bScrollBeyondZero
bool bScrollBeyondZero
Definition: ViewInfo.h:240
ViewInfo::GetTotalWidth
double GetTotalWidth() const
Definition: ViewInfo.h:210
ViewInfo::scrollStep
int scrollStep
Definition: ViewInfo.h:233
PrefsListener::UpdateSelectedPrefs
virtual void UpdateSelectedPrefs(int id)
Definition: Prefs.cpp:124
ZoomInfo.h
Observer::Message
Default message type for Publisher.
Definition: Observer.h:26
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
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
kVerticalPadding
@ kVerticalPadding
Definition: ViewInfo.h:91
Observer::Publisher
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
PlayRegion
Definition: ViewInfo.h:106
NotifyingSelectedRegion::f0
double f0() const
Definition: ViewInfo.h:36
anonymous_namespace{ProjectSettings.cpp}::Notify
void Notify(AudacityProject &project, ProjectSettings::EventCode code, long previousValue)
Definition: ProjectSettings.cpp:26
ViewInfo::ViewInfo
ViewInfo(const ViewInfo &) PROHIBITED
PlayRegion::PlayRegion
PlayRegion(const PlayRegion &)=delete
kTrackInfoSliderExtra
@ kTrackInfoSliderExtra
Definition: ViewInfo.h:99
kTrackInfoSliderAllowance
@ kTrackInfoSliderAllowance
Definition: ViewInfo.h:98
NotifyingSelectedRegion::mRegion
SelectedRegion mRegion
Definition: ViewInfo.h:87
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
NotifyingSelectedRegion::f1
double f1() const
Definition: ViewInfo.h:37
PlayRegion::GetLastActiveStart
double GetLastActiveStart() const
Definition: ViewInfo.h:140
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
NotifyingSelectedRegion::fc
double fc() const
Definition: ViewInfo.h:38
PlayRegion::Empty
bool Empty() const
Definition: ViewInfo.h:125
ViewInfo::sbarScale
double sbarScale
Definition: ViewInfo.h:230
ViewInfo::SetHeight
void SetHeight(int height)
Definition: ViewInfo.h:198
PlayRegion::mActive
bool mActive
Definition: ViewInfo.h:181
PlayRegion::PlayRegion
PlayRegion()=default
ViewInfo::GetBeforeScreenWidth
double GetBeforeScreenWidth() const
Definition: ViewInfo.h:204
ViewInfo::bAdjustSelectionEdges
bool bAdjustSelectionEdges
Definition: ViewInfo.h:241
NotifyingSelectedRegion::isPoint
bool isPoint() const
Definition: ViewInfo.h:39
NotifyingSelectedRegion::t0
double t0() const
Definition: ViewInfo.h:34
Prefs.h
PlayRegion::Active
bool Active() const
Definition: ViewInfo.h:122
NotifyingSelectedRegionMessage
Definition: ViewInfo.h:24
ZoomInfo::zoom
double zoom
Definition: ZoomInfo.h:63
ViewInfo::GetHeight
int GetHeight() const
Definition: ViewInfo.h:197
ScrollingPreference
SCREEN_GEOMETRY_API BoolSetting ScrollingPreference
Definition: ViewInfo.cpp:338
ViewInfo::total
double total
Definition: ViewInfo.h:220
NotifyingSelectedRegion
Definition: ViewInfo.h:31
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:38
kTrackInfoSliderWidth
@ kTrackInfoSliderWidth
Definition: ViewInfo.h:97
LoopToggleText
SCREEN_GEOMETRY_API const TranslatableString LoopToggleText
Definition: ViewInfo.cpp:227