Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
SelectedRegion Class Reference

Defines a selected portion of a project. More...

#include <SelectedRegion.h>

Public Member Functions

 SelectedRegion ()
 
 SelectedRegion (double t0, double t1)
 
 SelectedRegion (const SelectedRegion &x)
 
SelectedRegionoperator= (const SelectedRegion &x)
 
double t0 () const
 
double t1 () const
 
double duration () const
 
bool isPoint () const
 
double f0 () const
 
double f1 () const
 
double fc () const
 
bool setT0 (double t, bool maySwap=true)
 
bool setT1 (double t, bool maySwap=true)
 
bool setTimes (double t0, double t1)
 
bool moveT0 (double delta, bool maySwap=true)
 
bool moveT1 (double delta, bool maySwap=true)
 
void move (double delta)
 
void collapseToT0 ()
 
void collapseToT1 ()
 
bool setF0 (double f, bool maySwap=true)
 
bool setF1 (double f, bool maySwap=true)
 
bool setFrequencies (double f0, double f1)
 
void WriteXMLAttributes (XMLWriter &xmlFile, const char *legacyT0Name=sDefaultT0Name, const char *legacyT1Name=sDefaultT1Name) const
 
bool HandleXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &value, const char *legacyT0Name=sDefaultT0Name, const char *legacyT1Name=sDefaultT1Name)
 
bool ensureOrdering ()
 

Static Public Member Functions

static XMLMethodRegistryBase::Mutators< SelectedRegionMutators (const char *legacyT0Name, const char *legacyT1Name)
 

Static Public Attributes

static const int UndefinedFrequency = -1
 
static const char * sDefaultT0Name = "selStart"
 
static const char * sDefaultT1Name = "selEnd"
 

Private Member Functions

bool ensureFrequencyOrdering ()
 

Private Attributes

double mT0
 
double mT1
 
double mF0
 
double mF1
 

Friends

bool operator== (const SelectedRegion &lhs, const SelectedRegion &rhs)
 

Detailed Description

Defines a selected portion of a project.

This includes starting and ending times, and other optional information such as a frequency range, but not the set of selected tracks.

Maintains the invariants that ending time is not less than starting time and that starting and ending frequencies, when both defined, are also correctly ordered.

Definition at line 38 of file SelectedRegion.h.

Constructor & Destructor Documentation

◆ SelectedRegion() [1/3]

SelectedRegion::SelectedRegion ( )
inline

Definition at line 46 of file SelectedRegion.h.

47 : mT0(0.0)
48 , mT1(0.0)
51 {}
static const int UndefinedFrequency

◆ SelectedRegion() [2/3]

SelectedRegion::SelectedRegion ( double  t0,
double  t1 
)
inline

Definition at line 53 of file SelectedRegion.h.

54 : mT0(t0)
55 , mT1(t1)
58 { ensureOrdering(); }
double t1() const
double t0() const

◆ SelectedRegion() [3/3]

SelectedRegion::SelectedRegion ( const SelectedRegion x)
inline

Definition at line 66 of file SelectedRegion.h.

67 : mT0(x.mT0)
68 , mT1(x.mT1)
69 , mF0(x.mF0)
70 , mF1(x.mF1)
71 {}

Member Function Documentation

◆ collapseToT0()

void SelectedRegion::collapseToT0 ( )
inline

Definition at line 150 of file SelectedRegion.h.

150{ mT1 = mT0; }

Referenced by NotifyingSelectedRegion::collapseToT0().

Here is the caller graph for this function:

◆ collapseToT1()

void SelectedRegion::collapseToT1 ( )
inline

Definition at line 152 of file SelectedRegion.h.

152{ mT0 = mT1; }

Referenced by NotifyingSelectedRegion::collapseToT1().

Here is the caller graph for this function:

◆ duration()

double SelectedRegion::duration ( ) const
inline

Definition at line 88 of file SelectedRegion.h.

88{ return mT1 - mT0; }

◆ ensureFrequencyOrdering()

bool SelectedRegion::ensureFrequencyOrdering ( )
inlineprivate

Definition at line 237 of file SelectedRegion.h.

238 {
239 if (mF1 < 0)
241 if (mF0 < 0)
243
244 if (mF0 != UndefinedFrequency &&
246 mF1 < mF0) {
247 const double t = mF1;
248 mF1 = mF0;
249 mF0 = t;
250 return true;
251 }
252 else
253 return false;
254 }

◆ ensureOrdering()

bool SelectedRegion::ensureOrdering ( )
inline

Definition at line 223 of file SelectedRegion.h.

224 {
225 if (mT1 < mT0) {
226 const double t = mT1;
227 mT1 = mT0;
228 mT0 = t;
229 return true;
230 }
231 else
232 return false;
233 }

◆ f0()

double SelectedRegion::f0 ( ) const
inline

Definition at line 91 of file SelectedRegion.h.

91{ return mF0; }

Referenced by LabelStruct::Export(), LabelDialog::OnChangeHfreq(), NotifyingSelectedRegion::setF0(), NotifyingSelectedRegion::setFrequencies(), and LabelDialog::TransferDataToWindow().

Here is the caller graph for this function:

◆ f1()

double SelectedRegion::f1 ( ) const
inline

Definition at line 92 of file SelectedRegion.h.

92{ return mF1; }

Referenced by LabelStruct::Export(), LabelDialog::OnChangeLfreq(), NotifyingSelectedRegion::setF1(), NotifyingSelectedRegion::setFrequencies(), and LabelDialog::TransferDataToWindow().

Here is the caller graph for this function:

◆ fc()

double SelectedRegion::fc ( ) const
inline

Definition at line 93 of file SelectedRegion.h.

93 {
94 if (mF0 == UndefinedFrequency ||
96 return UndefinedFrequency;
97 else
98 return sqrt(mF0 * mF1);
99 };
__finl float_x4 __vecc sqrt(const float_x4 &a)

References staffpad::audio::simd::sqrt().

Here is the call graph for this function:

◆ HandleXMLAttribute()

bool SelectedRegion::HandleXMLAttribute ( const std::string_view &  attr,
const XMLAttributeValueView value,
const char *  legacyT0Name = sDefaultT0Name,
const char *  legacyT1Name = sDefaultT1Name 
)

Definition at line 37 of file SelectedRegion.cpp.

40{
41 // Keep this function consistent with the table in the next!
42 typedef bool (SelectedRegion::*Setter)(double, bool);
43 Setter setter = 0;
44 if (attr == legacyT0Name)
45 setter = &SelectedRegion::setT0;
46 else if (attr == legacyT1Name)
47 setter = &SelectedRegion::setT1;
48 else if (attr == sDefaultF0Name)
49 setter = &SelectedRegion::setF0;
50 else if (attr == sDefaultF1Name)
51 setter = &SelectedRegion::setF1;
52 else
53 return false;
54
55 double dblValue;
56
57 if (!value.TryGet(dblValue))
58 return false;
59
60 // False means don't flip time or frequency boundaries
61 (void)(this->*setter)(dblValue, false);
62 return true;
63}
Defines a selected portion of a project.
bool setF0(double f, bool maySwap=true)
bool setF1(double f, bool maySwap=true)
bool setT0(double t, bool maySwap=true)
bool setT1(double t, bool maySwap=true)
bool TryGet(bool &value) const noexcept
Try to get a boolean value from the view.

References anonymous_namespace{SelectedRegion.cpp}::sDefaultF0Name, anonymous_namespace{SelectedRegion.cpp}::sDefaultF1Name, setF0(), setF1(), setT0(), setT1(), and XMLAttributeValueView::TryGet().

Referenced by LabelTrack::HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPoint()

bool SelectedRegion::isPoint ( ) const
inline

Definition at line 89 of file SelectedRegion.h.

89{ return mT1 <= mT0; }

Referenced by ExportAudioDialog::UpdateLabelExportSettings().

Here is the caller graph for this function:

◆ move()

void SelectedRegion::move ( double  delta)
inline

Definition at line 145 of file SelectedRegion.h.

145 {
146 mT0 += delta;
147 mT1 += delta;
148 }

Referenced by NotifyingSelectedRegion::move().

Here is the caller graph for this function:

◆ moveT0()

bool SelectedRegion::moveT0 ( double  delta,
bool  maySwap = true 
)
inline

Definition at line 136 of file SelectedRegion.h.

136 {
137 return setT0(mT0 + delta, maySwap);
138 }

◆ moveT1()

bool SelectedRegion::moveT1 ( double  delta,
bool  maySwap = true 
)
inline

Definition at line 141 of file SelectedRegion.h.

141 {
142 return setT1(mT1 + delta, maySwap);
143 }

◆ Mutators()

XMLMethodRegistryBase::Mutators< SelectedRegion > SelectedRegion::Mutators ( const char *  legacyT0Name,
const char *  legacyT1Name 
)
static

Definition at line 66 of file SelectedRegion.cpp.

68{
69 // Keep this table consistent with the previous function!
70 return {
71 { legacyT0Name, [=](auto &selectedRegion, auto value){
72 selectedRegion
73 .HandleXMLAttribute(legacyT0Name, value,
74 legacyT0Name, legacyT1Name);
75 } },
76 { legacyT1Name, [=](auto &selectedRegion, auto value){
77 selectedRegion
78 .HandleXMLAttribute(legacyT1Name, value,
79 legacyT0Name, legacyT1Name);
80 } },
81 { sDefaultF0Name, [=](auto &selectedRegion, auto value){
82 selectedRegion
83 .HandleXMLAttribute(sDefaultF0Name, value, "", "");
84 } },
85 { sDefaultF1Name, [=](auto &selectedRegion, auto value){
86 selectedRegion
87 .HandleXMLAttribute(sDefaultF1Name, value, "", "");
88 } },
89 };
90};

References anonymous_namespace{SelectedRegion.cpp}::sDefaultF0Name, and anonymous_namespace{SelectedRegion.cpp}::sDefaultF1Name.

Referenced by NotifyingSelectedRegion::Mutators().

Here is the caller graph for this function:

◆ operator=()

SelectedRegion & SelectedRegion::operator= ( const SelectedRegion x)
inline

Definition at line 73 of file SelectedRegion.h.

74 {
75 if (this != &x) {
76 mT0 = x.mT0;
77 mT1 = x.mT1;
78 mF0 = x.mF0;
79 mF1 = x.mF1;
80 }
81 return *this;
82 }

References mF0, mF1, mT0, and mT1.

◆ setF0()

bool SelectedRegion::setF0 ( double  f,
bool  maySwap = true 
)
inline

Definition at line 155 of file SelectedRegion.h.

155 {
156 if (f < 0)
158 mF0 = f;
159 if (maySwap)
161 else {
162 if (mF1 >= 0 && mF1 < mF0)
163 mF1 = mF0;
164 return false;
165 }
166 }
bool ensureFrequencyOrdering()

Referenced by HandleXMLAttribute(), LabelDialog::OnChangeLfreq(), and NotifyingSelectedRegion::setF0().

Here is the caller graph for this function:

◆ setF1()

bool SelectedRegion::setF1 ( double  f,
bool  maySwap = true 
)
inline

Definition at line 169 of file SelectedRegion.h.

169 {
170 if (f < 0)
172 mF1 = f;
173 if (maySwap)
175 else {
176 if (mF0 >= 0 && mF1 < mF0)
177 mF0 = mF1;
178 return false;
179 }
180 }

Referenced by HandleXMLAttribute(), LabelDialog::OnChangeHfreq(), and NotifyingSelectedRegion::setF1().

Here is the caller graph for this function:

◆ setFrequencies()

bool SelectedRegion::setFrequencies ( double  f0,
double  f1 
)
inline

Definition at line 183 of file SelectedRegion.h.

184 {
185 mF0 = f0;
186 mF1 = f1;
188 }
double f0() const
double f1() const

Referenced by LabelStruct::Import(), and NotifyingSelectedRegion::setFrequencies().

Here is the caller graph for this function:

◆ setT0()

bool SelectedRegion::setT0 ( double  t,
bool  maySwap = true 
)
inline

Definition at line 105 of file SelectedRegion.h.

105 {
106 mT0 = t;
107 if (maySwap)
108 return ensureOrdering();
109 else {
110 if (mT1 < mT0)
111 mT1 = mT0;
112 return false;
113 }
114 }

Referenced by LabelStruct::AdjustEdge(), HandleXMLAttribute(), LabelDialog::OnChangeStime(), and NotifyingSelectedRegion::setT0().

Here is the caller graph for this function:

◆ setT1()

bool SelectedRegion::setT1 ( double  t,
bool  maySwap = true 
)
inline

Definition at line 117 of file SelectedRegion.h.

117 {
118 mT1 = t;
119 if (maySwap)
120 return ensureOrdering();
121 else {
122 if (mT1 < mT0)
123 mT0 = mT1;
124 return false;
125 }
126 }

Referenced by LabelStruct::AdjustEdge(), HandleXMLAttribute(), LabelDialog::OnChangeEtime(), and NotifyingSelectedRegion::setT1().

Here is the caller graph for this function:

◆ setTimes()

bool SelectedRegion::setTimes ( double  t0,
double  t1 
)
inline

Definition at line 129 of file SelectedRegion.h.

129 {
130 mT0 = t0;
131 mT1 = t1;
132 return ensureOrdering();
133 }

Referenced by LabelStruct::Import(), LabelStruct::LabelStruct(), LabelStruct::MoveLabel(), and NotifyingSelectedRegion::setTimes().

Here is the caller graph for this function:

◆ t0()

double SelectedRegion::t0 ( ) const
inline

◆ t1()

double SelectedRegion::t1 ( ) const
inline

◆ WriteXMLAttributes()

void SelectedRegion::WriteXMLAttributes ( XMLWriter xmlFile,
const char *  legacyT0Name = sDefaultT0Name,
const char *  legacyT1Name = sDefaultT1Name 
) const

Definition at line 24 of file SelectedRegion.cpp.

28{
29 xmlFile.WriteAttr(legacyT0Name, t0(), 10);
30 xmlFile.WriteAttr(legacyT1Name, t1(), 10);
31 if (f0() >= 0)
32 xmlFile.WriteAttr(sDefaultF0Name, f0(), 10);
33 if (f1() >= 0)
34 xmlFile.WriteAttr(sDefaultF1Name, f1(), 10);
35}
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36

References anonymous_namespace{SelectedRegion.cpp}::sDefaultF0Name, and anonymous_namespace{SelectedRegion.cpp}::sDefaultF1Name.

Friends And Related Function Documentation

◆ operator==

bool operator== ( const SelectedRegion lhs,
const SelectedRegion rhs 
)
friend

Definition at line 256 of file SelectedRegion.h.

258 {
259 return
260 lhs.mT0 == rhs.mT0
261 && lhs.mT1 == rhs.mT1
262 && lhs.mF0 == rhs.mF0
263 && lhs.mF1 == rhs.mF1
264 ;
265 }

Member Data Documentation

◆ mF0

double SelectedRegion::mF0
private

Definition at line 269 of file SelectedRegion.h.

Referenced by operator=().

◆ mF1

double SelectedRegion::mF1
private

Definition at line 270 of file SelectedRegion.h.

Referenced by operator=().

◆ mT0

double SelectedRegion::mT0
private

Definition at line 267 of file SelectedRegion.h.

Referenced by operator=().

◆ mT1

double SelectedRegion::mT1
private

Definition at line 268 of file SelectedRegion.h.

Referenced by operator=().

◆ sDefaultT0Name

const char * SelectedRegion::sDefaultT0Name = "selStart"
static

Definition at line 197 of file SelectedRegion.h.

◆ sDefaultT1Name

const char * SelectedRegion::sDefaultT1Name = "selEnd"
static

Definition at line 198 of file SelectedRegion.h.

◆ UndefinedFrequency

const int SelectedRegion::UndefinedFrequency = -1
static

The documentation for this class was generated from the following files: