Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | 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
 
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 ()
 
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 Attributes

double mT0
 
double mT1
 

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)
49#ifdef EXPERIMENTAL_SPECTRAL_EDITING
52#endif
53 {}
static const int UndefinedFrequency

◆ SelectedRegion() [2/3]

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

Definition at line 55 of file SelectedRegion.h.

56 : mT0(t0)
57 , mT1(t1)
58#ifdef EXPERIMENTAL_SPECTRAL_EDITING
61#endif
62 { ensureOrdering(); }
double t1() const
double t0() const

◆ SelectedRegion() [3/3]

SelectedRegion::SelectedRegion ( const SelectedRegion x)
inline

Definition at line 70 of file SelectedRegion.h.

71 : mT0(x.mT0)
72 , mT1(x.mT1)
73#ifdef EXPERIMENTAL_SPECTRAL_EDITING
74 , mF0(x.mF0)
75 , mF1(x.mF1)
76#endif
77 {}

Member Function Documentation

◆ collapseToT0()

void SelectedRegion::collapseToT0 ( )
inline

Definition at line 160 of file SelectedRegion.h.

160{ mT1 = mT0; }

Referenced by NotifyingSelectedRegion::collapseToT0().

Here is the caller graph for this function:

◆ collapseToT1()

void SelectedRegion::collapseToT1 ( )
inline

Definition at line 162 of file SelectedRegion.h.

162{ mT0 = mT1; }

Referenced by NotifyingSelectedRegion::collapseToT1().

Here is the caller graph for this function:

◆ duration()

double SelectedRegion::duration ( ) const
inline

Definition at line 96 of file SelectedRegion.h.

96{ return mT1 - mT0; }

◆ ensureOrdering()

bool SelectedRegion::ensureOrdering ( )
inline

Definition at line 235 of file SelectedRegion.h.

236 {
237 if (mT1 < mT0) {
238 const double t = mT1;
239 mT1 = mT0;
240 mT0 = t;
241 return true;
242 }
243 else
244 return false;
245 }

◆ HandleXMLAttribute()

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

Definition at line 39 of file SelectedRegion.cpp.

42{
43 // Keep this function consistent with the table in the next!
44 typedef bool (SelectedRegion::*Setter)(double, bool);
45 Setter setter = 0;
46 if (attr == legacyT0Name)
47 setter = &SelectedRegion::setT0;
48 else if (attr == legacyT1Name)
49 setter = &SelectedRegion::setT1;
50#ifdef EXPERIMENTAL_SPECTRAL_EDITING
51 else if (attr == sDefaultF0Name)
52 setter = &SelectedRegion::setF0;
53 else if (attr == sDefaultF1Name)
54 setter = &SelectedRegion::setF1;
55#endif
56 else
57 return false;
58
59 double dblValue;
60
61 if (!value.TryGet(dblValue))
62 return false;
63
64 // False means don't flip time or frequency boundaries
65 (void)(this->*setter)(dblValue, false);
66 return true;
67}
Defines a selected portion of a project.
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, 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 97 of file SelectedRegion.h.

97{ return mT1 <= mT0; }

Referenced by ExportMultipleDialog::ExportMultipleByLabel().

Here is the caller graph for this function:

◆ move()

void SelectedRegion::move ( double  delta)
inline

Definition at line 155 of file SelectedRegion.h.

155 {
156 mT0 += delta;
157 mT1 += delta;
158 }

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 146 of file SelectedRegion.h.

146 {
147 return setT0(mT0 + delta, maySwap);
148 }

◆ moveT1()

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

Definition at line 151 of file SelectedRegion.h.

151 {
152 return setT1(mT1 + delta, maySwap);
153 }

◆ Mutators()

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

Definition at line 70 of file SelectedRegion.cpp.

72{
73 // Keep this table consistent with the previous function!
74 return {
75 { legacyT0Name, [=](auto &selectedRegion, auto value){
76 selectedRegion
77 .HandleXMLAttribute(legacyT0Name, value,
78 legacyT0Name, legacyT1Name);
79 } },
80 { legacyT1Name, [=](auto &selectedRegion, auto value){
81 selectedRegion
82 .HandleXMLAttribute(legacyT1Name, value,
83 legacyT0Name, legacyT1Name);
84 } },
85#ifdef EXPERIMENTAL_SPECTRAL_EDITING
86 { sDefaultF0Name, [=](auto &selectedRegion, auto value){
87 selectedRegion
88 .HandleXMLAttribute(sDefaultF0Name, value, "", "");
89 } },
90 { sDefaultF1Name, [=](auto &selectedRegion, auto value){
91 selectedRegion
92 .HandleXMLAttribute(sDefaultF1Name, value, "", "");
93 } },
94#endif
95 };
96};

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 79 of file SelectedRegion.h.

80 {
81 if (this != &x) {
82 mT0 = x.mT0;
83 mT1 = x.mT1;
84#ifdef EXPERIMENTAL_SPECTRAL_EDITING
85 mF0 = x.mF0;
86 mF1 = x.mF1;
87#endif
88 }
89 return *this;
90 }

References mT0, and mT1.

◆ setT0()

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

Definition at line 115 of file SelectedRegion.h.

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

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 127 of file SelectedRegion.h.

127 {
128 mT1 = t;
129 if (maySwap)
130 return ensureOrdering();
131 else {
132 if (mT1 < mT0)
133 mT0 = mT1;
134 return false;
135 }
136 }

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 139 of file SelectedRegion.h.

139 {
140 mT0 = t0;
141 mT1 = t1;
142 return ensureOrdering();
143 }

Referenced by LabelStruct::Import(), LabelStruct::LabelStruct(), LabelStruct::MoveLabel(), EffectUIHost::OnPlay(), 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#ifdef EXPERIMENTAL_SPECTRAL_EDITING
32 if (f0() >= 0)
33 xmlFile.WriteAttr(sDefaultF0Name, f0(), 10);
34 if (f1() >= 0)
35 xmlFile.WriteAttr(sDefaultF1Name, f1(), 10);
36#endif
37}
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:37

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 270 of file SelectedRegion.h.

272 {
273 return
274 lhs.mT0 == rhs.mT0
275 && lhs.mT1 == rhs.mT1
276#ifdef EXPERIMENTAL_SPECTRAL_EDITING
277 && lhs.mF0 == rhs.mF0
278 && lhs.mF1 == rhs.mF1
279#endif
280 ;
281 }

Member Data Documentation

◆ mT0

double SelectedRegion::mT0
private

Definition at line 283 of file SelectedRegion.h.

Referenced by operator=().

◆ mT1

double SelectedRegion::mT1
private

Definition at line 284 of file SelectedRegion.h.

Referenced by operator=().

◆ sDefaultT0Name

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

Definition at line 209 of file SelectedRegion.h.

◆ sDefaultT1Name

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

Definition at line 210 of file SelectedRegion.h.

◆ UndefinedFrequency

const int SelectedRegion::UndefinedFrequency = -1
static

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