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.
28class SCREEN_GEOMETRY_API NotifyingSelectedRegion
29 : public Observer::Publisher<NotifyingSelectedRegionMessage>
30 , public wxTrackable
31{
32public:
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
84private:
85 void Notify( bool delayed = false );
86
88};
89
90enum : int {
92};
93
94enum : int {
95 kTrackInfoBtnSize = 18, // widely used dimension, usually height
101};
102
104
105class SCREEN_GEOMETRY_API PlayRegion
106 : public Observer::Publisher<PlayRegionMessage>
107{
108public:
109 PlayRegion() = default;
110
111 PlayRegion( const PlayRegion& ) = delete;
113 {
114 mActive = that.mActive;
115 // Guarantee the equivalent un-swapped order of endpoints
116 mStart = that.GetStart();
117 mEnd = that.GetEnd();
118 mLastActiveStart = that.GetLastActiveStart();
119 mLastActiveEnd = that.GetLastActiveEnd();
120 return *this;
121 }
122
123 bool Active() const { return mActive; }
124 void SetActive( bool active );
125
126 bool Empty() const { return GetStart() == GetEnd(); }
127 double GetStart() const
128 {
129 if ( mEnd < 0 )
130 return mStart;
131 else
132 return std::min( mStart, mEnd );
133 }
134 double GetEnd() const
135 {
136 if ( mStart < 0 )
137 return mEnd;
138 else
139 return std::max( mStart, mEnd );
140 }
141 double GetLastActiveStart() const
142 {
143 if ( mLastActiveEnd < 0 )
144 return mLastActiveStart;
145 else
146 return std::min( mLastActiveStart, mLastActiveEnd );
147 }
148 double GetLastActiveEnd() const
149 {
150 if ( mLastActiveStart < 0 )
151 return mLastActiveEnd;
152 else
153 return std::max( mLastActiveStart, mLastActiveEnd );
154 }
155
156 void SetStart( double start );
157 void SetEnd( double end );
158 void SetTimes( double start, double end );
159 // Set current and last active times the same regardless of activation:
160 void SetAllTimes( double start, double end );
161
163 void Clear();
165 bool IsClear() const;
167 bool IsLastActiveRegionClear() const;
168
169 void Order();
170
171private:
172 void Notify();
173
174 // Times:
175 static constexpr auto invalidValue = std::numeric_limits<double>::min();
176
177 double mStart { invalidValue };
178 double mEnd { invalidValue };
179 double mLastActiveStart { invalidValue };
180 double mLastActiveEnd { invalidValue };
181
182 bool mActive{ false };
183};
184
185extern SCREEN_GEOMETRY_API const TranslatableString LoopToggleText;
186
187class SCREEN_GEOMETRY_API ViewInfo final
188 : public ZoomInfo
189{
190public:
191 static ViewInfo &Get( AudacityProject &project );
192 static const ViewInfo &Get( const AudacityProject &project );
193
194 ViewInfo(double start, double screenDuration, double pixelsPerSecond);
195 ViewInfo( const ViewInfo & ) PROHIBITED;
196 ViewInfo &operator=( const ViewInfo & ) PROHIBITED;
197
198 int GetHeight() const { return mHeight; }
199 void SetHeight( int height ) { mHeight = height; }
200
201 static int UpdateScrollPrefsID();
202 void UpdatePrefs() override;
203 void UpdateSelectedPrefs( int id ) override;
204
205 double GetBeforeScreenWidth() const
206 {
207 return h * zoom;
208 }
209 void SetBeforeScreenWidth(wxInt64 beforeWidth, wxInt64 screenWidth, double lowerBoundTime = 0.0);
210
211 double GetTotalWidth() const
212 { return total * zoom; }
213
214 // Current selection
215
218
219 // Scroll info
220
221 double total; // total width in secs
222 // Current horizontal scroll bar positions, in pixels
223 wxInt64 sbarH;
224 wxInt64 sbarScreen;
225 wxInt64 sbarTotal;
226
227 // Internal wxScrollbar positions are only int in range, so multiply
228 // the above values with the following member to get the actual
229 // scroll bar positions as reported by the horizontal wxScrollbar's members
230 // i.e. units are scroll increments per pixel
231 double sbarScale;
232
233 // Vertical scroll step
235
236 // Other stuff, mainly states (true or false) related to autoscroll and
237 // drawing the waveform. Maybe this should be put somewhere else?
238
240
243
244 void WriteXMLAttributes(XMLWriter &xmlFile) const;
245
246private:
247 int mHeight{ 0 };
248
249 struct ProjectFileIORegistration;
250};
251
252extern SCREEN_GEOMETRY_API BoolSetting ScrollingPreference;
253#endif
int min(int a, int b)
SCREEN_GEOMETRY_API const TranslatableString LoopToggleText
Definition: ViewInfo.cpp:227
@ kVerticalPadding
Definition: ViewInfo.h:91
SCREEN_GEOMETRY_API BoolSetting ScrollingPreference
Definition: ViewInfo.cpp:338
@ kTrackEffectsBtnHeight
Definition: ViewInfo.h:96
@ kTrackInfoSliderWidth
Definition: ViewInfo.h:98
@ kTrackInfoSliderExtra
Definition: ViewInfo.h:100
@ kTrackInfoSliderAllowance
Definition: ViewInfo.h:99
@ kTrackInfoBtnSize
Definition: ViewInfo.h:95
@ kTrackInfoSliderHeight
Definition: ViewInfo.h:97
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Definition: Prefs.h:339
double t1() const
Definition: ViewInfo.h:35
void WriteXMLAttributes(XMLWriter &xmlFile, const char *legacyT0Name, const char *legacyT1Name) const
Definition: ViewInfo.h:45
SelectedRegion mRegion
Definition: ViewInfo.h:87
double f1() const
Definition: ViewInfo.h:37
double duration() const
Definition: ViewInfo.h:40
double fc() const
Definition: ViewInfo.h:38
bool isPoint() const
Definition: ViewInfo.h:39
double f0() const
Definition: ViewInfo.h:36
double t0() const
Definition: ViewInfo.h:34
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
Publisher & operator=(Publisher &&)=default
double GetStart() const
Definition: ViewInfo.h:127
double GetEnd() const
Definition: ViewInfo.h:134
PlayRegion(const PlayRegion &)=delete
PlayRegion()=default
double GetLastActiveStart() const
Definition: ViewInfo.h:141
bool Empty() const
Definition: ViewInfo.h:126
double GetLastActiveEnd() const
Definition: ViewInfo.h:148
bool Active() const
Definition: ViewInfo.h:123
bool mActive
Definition: ViewInfo.h:182
Defines a selected portion of a project.
Holds a msgid for the translation catalog; may also bind format arguments.
ViewInfo & operator=(const ViewInfo &) PROHIBITED
ViewInfo(const ViewInfo &) PROHIBITED
bool bUpdateTrackIndicator
Definition: ViewInfo.h:239
PlayRegion playRegion
Definition: ViewInfo.h:217
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
wxInt64 sbarTotal
Definition: ViewInfo.h:225
double GetBeforeScreenWidth() const
Definition: ViewInfo.h:205
double total
Definition: ViewInfo.h:221
wxInt64 sbarScreen
Definition: ViewInfo.h:224
int GetHeight() const
Definition: ViewInfo.h:198
double GetTotalWidth() const
Definition: ViewInfo.h:211
wxInt64 sbarH
Definition: ViewInfo.h:223
double sbarScale
Definition: ViewInfo.h:231
bool bScrollBeyondZero
Definition: ViewInfo.h:241
int scrollStep
Definition: ViewInfo.h:234
void SetHeight(int height)
Definition: ViewInfo.h:199
bool bAdjustSelectionEdges
Definition: ViewInfo.h:242
std::vector< std::pair< std::string, Mutator< Substructure > > > Mutators
A helper type alias for a list of mutators, associated with tag strings.
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:194
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
void Notify(AudacityProject &project, ProjectSettings::EventCode code, long previousValue)
Default message type for Publisher.
Definition: Observer.h:26