Audacity  3.0.3
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 wxChar *legacyT0Name=sDefaultT0Name, const wxChar *legacyT1Name=sDefaultT1Name) const
 
bool HandleXMLAttribute (const wxChar *attr, const wxChar *value, const wxChar *legacyT0Name=sDefaultT0Name, const wxChar *legacyT1Name=sDefaultT1Name)
 
bool ensureOrdering ()
 

Static Public Member Functions

static XMLMethodRegistryBase::Mutators< SelectedRegionMutators (const wxString &legacyT0Name, const wxString &legacyT1Name)
 

Static Public Attributes

static const int UndefinedFrequency = -1
 
static const wxChar * sDefaultT0Name = wxT("selStart")
 
static const wxChar * sDefaultT1Name = wxT("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 35 of file SelectedRegion.h.

Constructor & Destructor Documentation

◆ SelectedRegion() [1/3]

SelectedRegion::SelectedRegion ( )
inline

Definition at line 43 of file SelectedRegion.h.

44  : mT0(0.0)
45  , mT1(0.0)
46 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
47  , mF0(UndefinedFrequency)
48  , mF1(UndefinedFrequency)
49 #endif
50  {}

◆ SelectedRegion() [2/3]

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

Definition at line 52 of file SelectedRegion.h.

53  : mT0(t0)
54  , mT1(t1)
55 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
56  , mF0(UndefinedFrequency)
57  , mF1(UndefinedFrequency)
58 #endif
59  { ensureOrdering(); }

◆ SelectedRegion() [3/3]

SelectedRegion::SelectedRegion ( const SelectedRegion x)
inline

Definition at line 67 of file SelectedRegion.h.

68  : mT0(x.mT0)
69  , mT1(x.mT1)
70 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
71  , mF0(x.mF0)
72  , mF1(x.mF1)
73 #endif
74  {}

Member Function Documentation

◆ collapseToT0()

void SelectedRegion::collapseToT0 ( )
inline

Definition at line 157 of file SelectedRegion.h.

157 { mT1 = mT0; }

Referenced by NotifyingSelectedRegion::collapseToT0().

Here is the caller graph for this function:

◆ collapseToT1()

void SelectedRegion::collapseToT1 ( )
inline

Definition at line 159 of file SelectedRegion.h.

159 { mT0 = mT1; }

Referenced by NotifyingSelectedRegion::collapseToT1().

Here is the caller graph for this function:

◆ duration()

double SelectedRegion::duration ( ) const
inline

Definition at line 93 of file SelectedRegion.h.

93 { return mT1 - mT0; }

◆ ensureOrdering()

bool SelectedRegion::ensureOrdering ( )
inline

Definition at line 232 of file SelectedRegion.h.

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

◆ HandleXMLAttribute()

bool SelectedRegion::HandleXMLAttribute ( const wxChar *  attr,
const wxChar *  value,
const wxChar *  legacyT0Name = sDefaultT0Name,
const wxChar *  legacyT1Name = sDefaultT1Name 
)

Definition at line 38 of file SelectedRegion.cpp.

41 {
42  // Keep this function consistent with the table in the next!
43  typedef bool (SelectedRegion::*Setter)(double, bool);
44  Setter setter = 0;
45  if (!wxStrcmp(attr, legacyT0Name))
46  setter = &SelectedRegion::setT0;
47  else if (!wxStrcmp(attr, legacyT1Name))
48  setter = &SelectedRegion::setT1;
49 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
50  else if (!wxStrcmp(attr, sDefaultF0Name))
51  setter = &SelectedRegion::setF0;
52  else if (!wxStrcmp(attr, sDefaultF1Name))
53  setter = &SelectedRegion::setF1;
54 #endif
55  else
56  return false;
57 
58  double dblValue;
59  if (!Internat::CompatibleToDouble(value, &dblValue))
60  return false;
61 
62  // False means don't flip time or frequency boundaries
63  (void)(this->*setter)(dblValue, false);
64  return true;
65 }

References Internat::CompatibleToDouble(), anonymous_namespace{SelectedRegion.cpp}::sDefaultF0Name, anonymous_namespace{SelectedRegion.cpp}::sDefaultF1Name, setT0(), and setT1().

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

94 { 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 152 of file SelectedRegion.h.

152  {
153  mT0 += delta;
154  mT1 += delta;
155  }

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

143  {
144  return setT0(mT0 + delta, maySwap);
145  }

◆ moveT1()

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

Definition at line 148 of file SelectedRegion.h.

148  {
149  return setT1(mT1 + delta, maySwap);
150  }

◆ Mutators()

XMLMethodRegistryBase::Mutators< SelectedRegion > SelectedRegion::Mutators ( const wxString &  legacyT0Name,
const wxString &  legacyT1Name 
)
static

Definition at line 68 of file SelectedRegion.cpp.

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

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

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

References mT0, and mT1.

◆ setT0()

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

Definition at line 112 of file SelectedRegion.h.

112  {
113  mT0 = t;
114  if (maySwap)
115  return ensureOrdering();
116  else {
117  if (mT1 < mT0)
118  mT1 = mT0;
119  return false;
120  }
121  }

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

124  {
125  mT1 = t;
126  if (maySwap)
127  return ensureOrdering();
128  else {
129  if (mT1 < mT0)
130  mT0 = mT1;
131  return false;
132  }
133  }

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

136  {
137  mT0 = t0;
138  mT1 = t1;
139  return ensureOrdering();
140  }

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 wxChar *  legacyT0Name = sDefaultT0Name,
const wxChar *  legacyT1Name = sDefaultT1Name 
) const

Definition at line 23 of file SelectedRegion.cpp.

27 {
28  xmlFile.WriteAttr(legacyT0Name, t0(), 10);
29  xmlFile.WriteAttr(legacyT1Name, t1(), 10);
30 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
31  if (f0() >= 0)
32  xmlFile.WriteAttr(sDefaultF0Name, f0(), 10);
33  if (f1() >= 0)
34  xmlFile.WriteAttr(sDefaultF1Name, f1(), 10);
35 #endif
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 267 of file SelectedRegion.h.

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

Member Data Documentation

◆ mT0

double SelectedRegion::mT0
private

Definition at line 280 of file SelectedRegion.h.

Referenced by operator=().

◆ mT1

double SelectedRegion::mT1
private

Definition at line 281 of file SelectedRegion.h.

Referenced by operator=().

◆ sDefaultT0Name

const wxChar * SelectedRegion::sDefaultT0Name = wxT("selStart")
static

Definition at line 206 of file SelectedRegion.h.

◆ sDefaultT1Name

const wxChar * SelectedRegion::sDefaultT1Name = wxT("selEnd")
static

Definition at line 207 of file SelectedRegion.h.

◆ UndefinedFrequency

const int SelectedRegion::UndefinedFrequency = -1
static

The documentation for this class was generated from the following files:
SelectedRegion::t1
double t1() const
Definition: SelectedRegion.h:92
SelectedRegion::UndefinedFrequency
static const int UndefinedFrequency
Definition: SelectedRegion.h:41
SelectedRegion::setT0
bool setT0(double t, bool maySwap=true)
Definition: SelectedRegion.h:112
anonymous_namespace{SelectedRegion.cpp}::sDefaultF1Name
const wxChar * sDefaultF1Name
Definition: SelectedRegion.cpp:20
SelectedRegion::ensureOrdering
bool ensureOrdering()
Definition: SelectedRegion.h:232
SelectedRegion::t0
double t0() const
Definition: SelectedRegion.h:91
anonymous_namespace{SelectedRegion.cpp}::sDefaultF0Name
const wxChar * sDefaultF0Name
Definition: SelectedRegion.cpp:19
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
SelectedRegion::mT1
double mT1
Definition: SelectedRegion.h:281
SelectedRegion::setT1
bool setT1(double t, bool maySwap=true)
Definition: SelectedRegion.h:124
SelectedRegion::mT0
double mT0
Definition: SelectedRegion.h:280
Internat::CompatibleToDouble
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:134
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35