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 "ClientData.h"
18#include "SelectedRegion.h"
19#include <memory>
20#include "Observer.h"
21#include "Prefs.h"
22#include "XMLMethodRegistry.h"
23#include "ZoomInfo.h" // to inherit
24
26
27// This heavyweight wrapper of the SelectedRegion structure emits events
28// on mutating operations, that other classes can listen for.
29class TIME_FREQUENCY_SELECTION_API NotifyingSelectedRegion
30 : public Observer::Publisher<NotifyingSelectedRegionMessage>
31 , public wxTrackable
32{
33public:
34 // Expose SelectedRegion's const accessors
35 double t0 () const { return mRegion.t0(); }
36 double t1 () const { return mRegion.t1(); }
37 double f0 () const { return mRegion.f0(); }
38 double f1 () const { return mRegion.f1(); }
39 double fc () const { return mRegion.fc(); }
40 bool isPoint() const { return mRegion.isPoint(); }
41 double duration() const { return mRegion.duration(); }
42
43 // Writing and reading of persistent fields -- the read is mutating but
44 // does not emit events
46 (XMLWriter &xmlFile,
47 const char *legacyT0Name, const char *legacyT1Name) const
48 { mRegion.WriteXMLAttributes(xmlFile, legacyT0Name, legacyT1Name); }
49
52 Mutators(const char *legacyT0Name, const char *legacyT1Name);
53
54 // const-only access allows assignment from this into a SelectedRegion
55 // or otherwise passing it into a function taking const SelectedRegion&
56 operator const SelectedRegion & () const { return mRegion; }
57
58 // These are the event-emitting operations
60
61 // Returns true iff the bounds got swapped
62 bool setTimes(double t0, double t1);
63
64 // Returns true iff the bounds got swapped
65 bool setT0(double t, bool maySwap = true);
66
67 // Returns true iff the bounds got swapped
68 bool setT1(double t, bool maySwap = true);
69
70 void collapseToT0();
71
72 void collapseToT1();
73
74 void move(double delta);
75
76 // Returns true iff the bounds got swapped
77 bool setFrequencies(double f0, double f1);
78
79 // Returns true iff the bounds got swapped
80 bool setF0(double f, bool maySwap = true);
81
82 // Returns true iff the bounds got swapped
83 bool setF1(double f, bool maySwap = true);
84
85private:
86 void Notify( bool delayed = false );
87
89};
90
91enum : int {
93};
94
95enum : int {
96 kTrackInfoBtnSize = 18, // widely used dimension, usually height
102};
103
105
106class TIME_FREQUENCY_SELECTION_API PlayRegion
107 : public Observer::Publisher<PlayRegionMessage>
108{
109public:
110 PlayRegion() = default;
111
112 PlayRegion( const PlayRegion& ) = delete;
114 {
115 mActive = that.mActive;
116 // Guarantee the equivalent un-swapped order of endpoints
117 mStart = that.GetStart();
118 mEnd = that.GetEnd();
119 mLastActiveStart = that.GetLastActiveStart();
120 mLastActiveEnd = that.GetLastActiveEnd();
121 return *this;
122 }
123
124 bool Active() const { return mActive; }
125 void SetActive( bool active );
126
127 bool Empty() const { return GetStart() == GetEnd(); }
128 double GetStart() const
129 {
130 if ( mEnd < 0 )
131 return mStart;
132 else
133 return std::min( mStart, mEnd );
134 }
135 double GetEnd() const
136 {
137 if ( mStart < 0 )
138 return mEnd;
139 else
140 return std::max( mStart, mEnd );
141 }
142 double GetLastActiveStart() const
143 {
144 if ( mLastActiveEnd < 0 )
145 return mLastActiveStart;
146 else
147 return std::min( mLastActiveStart, mLastActiveEnd );
148 }
149 double GetLastActiveEnd() const
150 {
151 if ( mLastActiveStart < 0 )
152 return mLastActiveEnd;
153 else
154 return std::max( mLastActiveStart, mLastActiveEnd );
155 }
156
157 void SetStart( double start );
158 void SetEnd( double end );
159 void SetTimes( double start, double end );
160 // Set current and last active times the same regardless of activation:
161 void SetAllTimes( double start, double end );
162
164 void Clear();
166 bool IsClear() const;
168 bool IsLastActiveRegionClear() const;
169
170 void Order();
171
172private:
173 void Notify();
174
175 // Times:
176 static constexpr auto invalidValue = -std::numeric_limits<double>::infinity();
177
178 double mStart { invalidValue };
179 double mEnd { invalidValue };
180 double mLastActiveStart { invalidValue };
181 double mLastActiveEnd { invalidValue };
182
183 bool mActive{ false };
184};
185
186extern TIME_FREQUENCY_SELECTION_API const TranslatableString LoopToggleText;
187
188class TIME_FREQUENCY_SELECTION_API ViewInfo final
189 : public ZoomInfo
190 , public PrefsListener
191 , public ClientData::Base
192{
193public:
195 static const ViewInfo &Get( const AudacityProject &project );
196
197 ViewInfo(double start, double pixelsPerSecond);
198 ViewInfo( const ViewInfo & ) = delete;
199 ViewInfo &operator=( const ViewInfo & ) = delete;
200
201 int GetHeight() const { return mHeight; }
202 void SetHeight( int height ) { mHeight = height; }
203
204 static int UpdateScrollPrefsID();
205 void UpdatePrefs() override;
206 void UpdateSelectedPrefs( int id ) override;
207
208 double GetBeforeScreenWidth() const
209 {
210 return hpos * zoom;
211 }
212
213 // Current selection
214
217
218 // Scroll info
219
221 int vpos{ 0 };
222
223 // Other stuff, mainly states (true or false) related to autoscroll and
224 // drawing the waveform. Maybe this should be put somewhere else?
225
227
228 void WriteXMLAttributes(XMLWriter &xmlFile) const;
229
230private:
231 int mHeight{ 0 };
232
233 struct ProjectFileIORegistration;
234};
235
236#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
int min(int a, int b)
const auto project
TIME_FREQUENCY_SELECTION_API const TranslatableString LoopToggleText
Definition: ViewInfo.cpp:227
@ kTrackEffectsBtnHeight
Definition: ViewInfo.h:97
@ kTrackInfoSliderWidth
Definition: ViewInfo.h:99
@ kTrackInfoSliderExtra
Definition: ViewInfo.h:101
@ kTrackInfoSliderAllowance
Definition: ViewInfo.h:100
@ kTrackInfoBtnSize
Definition: ViewInfo.h:96
@ kTrackInfoSliderHeight
Definition: ViewInfo.h:98
@ kVerticalPadding
Definition: ViewInfo.h:92
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
double t1() const
Definition: ViewInfo.h:36
void WriteXMLAttributes(XMLWriter &xmlFile, const char *legacyT0Name, const char *legacyT1Name) const
Definition: ViewInfo.h:46
SelectedRegion mRegion
Definition: ViewInfo.h:88
double f1() const
Definition: ViewInfo.h:38
double duration() const
Definition: ViewInfo.h:41
double fc() const
Definition: ViewInfo.h:39
bool isPoint() const
Definition: ViewInfo.h:40
double f0() const
Definition: ViewInfo.h:37
double t0() const
Definition: ViewInfo.h:35
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:128
double GetEnd() const
Definition: ViewInfo.h:135
PlayRegion(const PlayRegion &)=delete
PlayRegion()=default
double GetLastActiveStart() const
Definition: ViewInfo.h:142
bool Empty() const
Definition: ViewInfo.h:127
double GetLastActiveEnd() const
Definition: ViewInfo.h:149
bool Active() const
Definition: ViewInfo.h:124
bool mActive
Definition: ViewInfo.h:183
A listener notified of changes in preferences.
Definition: Prefs.h:652
Defines a selected portion of a project.
Holds a msgid for the translation catalog; may also bind format arguments.
bool bUpdateTrackIndicator
Definition: ViewInfo.h:226
PlayRegion playRegion
Definition: ViewInfo.h:216
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
double GetBeforeScreenWidth() const
Definition: ViewInfo.h:208
int GetHeight() const
Definition: ViewInfo.h:201
ViewInfo(const ViewInfo &)=delete
ViewInfo & operator=(const ViewInfo &)=delete
void SetHeight(int height)
Definition: ViewInfo.h:202
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:25
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
A convenient default parameter for class template Site.
Definition: ClientData.h:28
Default message type for Publisher.
Definition: Observer.h:26