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 {
98 kTrackInfoBtnSize = 18, // widely used dimension, usually height
103};
104
106
107class TIME_FREQUENCY_SELECTION_API PlayRegion
108 : public Observer::Publisher<PlayRegionMessage>
109{
110public:
111 PlayRegion() = default;
112
113 PlayRegion( const PlayRegion& ) = delete;
115 {
116 mActive = that.mActive;
117 // Guarantee the equivalent un-swapped order of endpoints
118 mStart = that.GetStart();
119 mEnd = that.GetEnd();
120 mLastActiveStart = that.GetLastActiveStart();
121 mLastActiveEnd = that.GetLastActiveEnd();
122 return *this;
123 }
124
125 bool Active() const { return mActive; }
126 void SetActive( bool active );
127
128 bool Empty() const { return GetStart() == GetEnd(); }
129 double GetStart() const
130 {
131 if ( mEnd < 0 )
132 return mStart;
133 else
134 return std::min( mStart, mEnd );
135 }
136 double GetEnd() const
137 {
138 if ( mStart < 0 )
139 return mEnd;
140 else
141 return std::max( mStart, mEnd );
142 }
143 double GetLastActiveStart() const
144 {
145 if ( mLastActiveEnd < 0 )
146 return mLastActiveStart;
147 else
148 return std::min( mLastActiveStart, mLastActiveEnd );
149 }
150 double GetLastActiveEnd() const
151 {
152 if ( mLastActiveStart < 0 )
153 return mLastActiveEnd;
154 else
155 return std::max( mLastActiveStart, mLastActiveEnd );
156 }
157
158 void SetStart( double start );
159 void SetEnd( double end );
160 void SetTimes( double start, double end );
161 // Set current and last active times the same regardless of activation:
162 void SetAllTimes( double start, double end );
163
165 void Clear();
167 bool IsClear() const;
169 bool IsLastActiveRegionClear() const;
170
171 void Order();
172
173private:
174 void Notify();
175
176 // Times:
177 static constexpr auto invalidValue = -std::numeric_limits<double>::infinity();
178
179 double mStart { invalidValue };
180 double mEnd { invalidValue };
181 double mLastActiveStart { invalidValue };
182 double mLastActiveEnd { invalidValue };
183
184 bool mActive{ false };
185};
186
187extern TIME_FREQUENCY_SELECTION_API const TranslatableString LoopToggleText;
188
189class TIME_FREQUENCY_SELECTION_API ViewInfo final
190 : public ZoomInfo
191 , public PrefsListener
192 , public ClientData::Base
193{
194public:
196 static const ViewInfo &Get( const AudacityProject &project );
197
198 ViewInfo(double start, double pixelsPerSecond);
199 ViewInfo( const ViewInfo & ) = delete;
200 ViewInfo &operator=( const ViewInfo & ) = delete;
201
202 int GetHeight() const { return mHeight; }
203 void SetHeight( int height ) { mHeight = height; }
204
205 static int UpdateScrollPrefsID();
206 void UpdatePrefs() override;
207 void UpdateSelectedPrefs( int id ) override;
208
209 double GetBeforeScreenWidth() const
210 {
211 return hpos * zoom;
212 }
213
214 // Current selection
215
218
219 // Scroll info
220
222 int vpos{ 0 };
223
224 // Other stuff, mainly states (true or false) related to autoscroll and
225 // drawing the waveform. Maybe this should be put somewhere else?
226
228
229 void WriteXMLAttributes(XMLWriter &xmlFile) const;
230
231private:
232 int mHeight{ 0 };
233
234 struct ProjectFileIORegistration;
235};
236
237#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
@ kVerticalPadding
Definition: ViewInfo.h:92
@ kTrackInfoSliderWidth
Definition: ViewInfo.h:100
@ kTrackInfoTitleHeight
Definition: ViewInfo.h:96
@ kTrackInfoSliderExtra
Definition: ViewInfo.h:102
@ kTrackInfoSliderAllowance
Definition: ViewInfo.h:101
@ kTrackInfoBtnSize
Definition: ViewInfo.h:98
@ kTrackInfoTitleExtra
Definition: ViewInfo.h:97
@ kTrackInfoSliderHeight
Definition: ViewInfo.h:99
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:129
double GetEnd() const
Definition: ViewInfo.h:136
PlayRegion(const PlayRegion &)=delete
PlayRegion()=default
double GetLastActiveStart() const
Definition: ViewInfo.h:143
bool Empty() const
Definition: ViewInfo.h:128
double GetLastActiveEnd() const
Definition: ViewInfo.h:150
bool Active() const
Definition: ViewInfo.h:125
bool mActive
Definition: ViewInfo.h:184
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:227
PlayRegion playRegion
Definition: ViewInfo.h:217
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
double GetBeforeScreenWidth() const
Definition: ViewInfo.h:209
int GetHeight() const
Definition: ViewInfo.h:202
ViewInfo(const ViewInfo &)=delete
ViewInfo & operator=(const ViewInfo &)=delete
void SetHeight(int height)
Definition: ViewInfo.h:203
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:202
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
A convenient default parameter for class template Site.
Definition: ClientData.h:29
Default message type for Publisher.
Definition: Observer.h:26