Audacity  2.2.2
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 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 Attributes

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

Constructor & Destructor Documentation

SelectedRegion::SelectedRegion ( )
inline

Definition at line 45 of file SelectedRegion.h.

46  : mT0(0.0)
47  , mT1(0.0)
48 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
51 #endif
52  {}
static const int UndefinedFrequency
SelectedRegion::SelectedRegion ( double  t0,
double  t1 
)
inline

Definition at line 54 of file SelectedRegion.h.

55  : mT0(t0)
56  , mT1(t1)
57 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
60 #endif
61  { ensureOrdering(); }
double t0() const
double t1() const
static const int UndefinedFrequency
SelectedRegion::SelectedRegion ( const SelectedRegion x)
inline

Definition at line 69 of file SelectedRegion.h.

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

Member Function Documentation

void SelectedRegion::collapseToT0 ( )
inline
void SelectedRegion::collapseToT1 ( )
inline
double SelectedRegion::duration ( ) const
inline
bool SelectedRegion::ensureFrequencyOrdering ( )
inlineprivate

Definition at line 240 of file SelectedRegion.h.

241  {
242  if (mF1 < 0)
244  if (mF0 < 0)
246 
247  if (mF0 != UndefinedFrequency &&
248  mF1 != UndefinedFrequency &&
249  mF1 < mF0) {
250  const double t = mF1;
251  mF1 = mF0;
252  mF0 = t;
253  return true;
254  }
255  else
256  return false;
257  }
static const int UndefinedFrequency
bool SelectedRegion::ensureOrdering ( )
inline

Definition at line 225 of file SelectedRegion.h.

Referenced by SetLabelCommand::Apply().

226  {
227  if (mT1 < mT0) {
228  const double t = mT1;
229  mT1 = mT0;
230  mT0 = t;
231  return true;
232  }
233  else
234  return false;
235  }
double SelectedRegion::f0 ( ) const
inline
double SelectedRegion::f1 ( ) const
inline
double SelectedRegion::fc ( ) const
inline

Definition at line 101 of file SelectedRegion.h.

Referenced by SelectHandle::Click(), and SelectHandle::SnapCenterOnce().

101  {
102  if (mF0 == UndefinedFrequency ||
104  return UndefinedFrequency;
105  else
106  return sqrt(mF0 * mF1);
107  };
static const int UndefinedFrequency
bool SelectedRegion::HandleXMLAttribute ( const wxChar *  attr,
const wxChar *  value,
const wxChar *  legacyT0Name = sDefaultT0Name,
const wxChar *  legacyT1Name = sDefaultT1Name 
)

Definition at line 40 of file SelectedRegion.cpp.

References Internat::CompatibleToDouble(), setF0(), setF1(), setT0(), and setT1().

Referenced by LabelTrack::HandleXMLTag(), and ViewInfo::ReadXMLAttribute().

42 {
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 }
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:122
Defines a selected portion of a project.
bool setT1(double t, bool maySwap=true)
bool setF1(double f, bool maySwap=true)
bool setT0(double t, bool maySwap=true)
bool setF0(double f, bool maySwap=true)
bool SelectedRegion::isPoint ( ) const
inline
void SelectedRegion::move ( double  delta)
inline

Definition at line 154 of file SelectedRegion.h.

Referenced by TimeShiftHandle::Drag(), and AudacityProject::HandleAlign().

154  {
155  mT0 += delta;
156  mT1 += delta;
157  }
bool SelectedRegion::moveT0 ( double  delta,
bool  maySwap = true 
)
inline

Definition at line 145 of file SelectedRegion.h.

145  {
146  return setT0(mT0 + delta, maySwap);
147  }
bool setT0(double t, bool maySwap=true)
bool SelectedRegion::moveT1 ( double  delta,
bool  maySwap = true 
)
inline

Definition at line 150 of file SelectedRegion.h.

150  {
151  return setT1(mT1 + delta, maySwap);
152  }
bool setT1(double t, bool maySwap=true)
SelectedRegion& SelectedRegion::operator= ( const SelectedRegion x)
inline

Definition at line 78 of file SelectedRegion.h.

References mF0, mF1, mT0, and mT1.

79  {
80  if (this != &x) {
81  mT0 = x.mT0;
82  mT1 = x.mT1;
83 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
84  mF0 = x.mF0;
85  mF1 = x.mF1;
86 #endif
87  }
88  return *this;
89  }
bool SelectedRegion::setF0 ( double  f,
bool  maySwap = true 
)
inline

Definition at line 165 of file SelectedRegion.h.

Referenced by SelectHandle::AdjustFreqSelection(), HandleXMLAttribute(), and LabelDialog::OnChangeLfreq().

165  {
166  if (f < 0)
167  f = UndefinedFrequency;
168  mF0 = f;
169  if (maySwap)
170  return ensureFrequencyOrdering();
171  else {
172  if (mF1 >= 0 && mF1 < mF0)
173  mF1 = mF0;
174  return false;
175  }
176  }
bool ensureFrequencyOrdering()
static const int UndefinedFrequency
bool SelectedRegion::setF1 ( double  f,
bool  maySwap = true 
)
inline

Definition at line 179 of file SelectedRegion.h.

Referenced by SelectHandle::AdjustFreqSelection(), HandleXMLAttribute(), and LabelDialog::OnChangeHfreq().

179  {
180  if (f < 0)
181  f = UndefinedFrequency;
182  mF1 = f;
183  if (maySwap)
184  return ensureFrequencyOrdering();
185  else {
186  if (mF0 >= 0 && mF1 < mF0)
187  mF0 = mF1;
188  return false;
189  }
190  }
bool ensureFrequencyOrdering()
static const int UndefinedFrequency
bool SelectedRegion::setFrequencies ( double  f0,
double  f1 
)
inline
bool SelectedRegion::setT0 ( double  t,
bool  maySwap = true 
)
inline
bool SelectedRegion::setT1 ( double  t,
bool  maySwap = true 
)
inline
bool SelectedRegion::setTimes ( double  t0,
double  t1 
)
inline
double SelectedRegion::t0 ( ) const
inline

Definition at line 93 of file SelectedRegion.h.

Referenced by LabelTrack::AddLabel(), SetLabelCommand::Apply(), ExportCommand::Apply(), LabelTrack::Char(), AudacityProject::Clear(), CutlineHandle::Click(), TimeShiftHandle::Click(), AudacityProject::DialogForLabelName(), LabelTrack::DoCaptureKey(), AudacityProject::DoClipLeftOrRight(), AdornedRulerPanel::DoDrawSelection(), Effect::DoEffect(), AudacityProject::DoEffect(), EditCursorOverlay::DoGetRectangle(), AudacityProject::DoPlayStopSelect(), TrackArtist::DrawBackgroundWithSelection(), TrackArtist::DrawClipWaveform(), TrackArtist::DrawLabelTrack(), ExportMultiple::ExportMultipleByLabel(), LabelDialog::FindInitialRow(), LabelTrack::FindNextLabel(), LabelTrack::FindPrevLabel(), FreqWindow::GetAudio(), AudacityProject::GetRegionsByLabel(), CompareAudioCommand::GetSelection(), LabelStruct::getT0(), AudacityProject::GetUpdateFlags(), AudacityProject::GetZoomOfSelection(), AudacityProject::HandleAlign(), AudacityProject::HandlePasteText(), LabelTrack::HandleTextClick(), SelectHandle::HitTest(), LabelTrack::KeyDown(), AudacityProject::MoveWhenAudioInactive(), AudacityProject::OnBoundaryMove(), LabelDialog::OnChangeEtime(), AudacityProject::OnClipMove(), AudacityProject::OnCopy(), AudacityProject::OnCursorClipBoundary(), AudacityProject::OnCursorPositionStore(), AudacityProject::OnCursorSelStart(), AudacityProject::OnCursorTrackStart(), AudacityProject::OnCut(), AudacityProject::OnDisjoin(), AudacityProject::OnDuplicate(), AudacityProject::OnExportSelection(), EffectUIHost::OnFFwd(), ContrastDialog::OnGetBackground(), ContrastDialog::OnGetForeground(), AudacityProject::OnGoSelStart(), AudacityProject::OnJoin(), LabelTrack::OnKeyDown(), AudacityProject::OnPaste(), AudacityProject::OnPasteNewLabel(), AudacityProject::OnPasteOver(), EffectUIHost::OnPlay(), AudacityProject::OnPlayAfterSelectionStart(), EffectUIHost::OnPlayback(), AudacityProject::OnPlayBeforeAndAfterSelectionEnd(), AudacityProject::OnPlayBeforeAndAfterSelectionStart(), AudacityProject::OnPlayBeforeSelectionEnd(), AudacityProject::OnPlayBeforeSelectionStart(), AudacityProject::OnPlayToSelection(), EffectUIHost::OnRewind(), AudacityProject::OnSelectClip(), AudacityProject::OnSelectClipBoundary(), AudacityProject::OnSelectCursorStoredCursor(), AudacityProject::OnSelectionRestore(), AudacityProject::OnSetLeftSelection(), AudacityProject::OnSilence(), AudacityProject::OnSplit(), AudacityProject::OnSplitCut(), AudacityProject::OnSplitDelete(), AudacityProject::OnSplitNew(), AudacityProject::OnTrim(), AudacityProject::OnZeroCrossing(), AudacityProject::OnZoomSel(), ControlToolBar::PlayPlayRegion(), AudacityProject::SeekWhenAudioInactive(), ContrastDialog::SetStartAndEndTime(), AudacityProject::SnapSelection(), SelectHandle::StartSnappingFreqSelection(), AudacityProject::TP_DisplaySelection(), LabelDialog::TransferDataToWindow(), AudacityProject::Zoom(), and AudacityProject::ZoomInByFactor().

93 { return mT0; }
double SelectedRegion::t1 ( ) const
inline

Definition at line 94 of file SelectedRegion.h.

Referenced by SetLabelCommand::Apply(), ExportCommand::Apply(), LabelTrack::Char(), AudacityProject::Clear(), CutlineHandle::Click(), TimeShiftHandle::Click(), LabelTrack::DoCaptureKey(), AdornedRulerPanel::DoDrawSelection(), Effect::DoEffect(), TrackArtist::DrawBackgroundWithSelection(), TrackArtist::DrawClipWaveform(), TrackArtist::DrawLabelTrack(), ExportMultiple::ExportMultipleByLabel(), AudacityProject::FixScrollbars(), FreqWindow::GetAudio(), AudacityProject::GetRegionsByLabel(), CompareAudioCommand::GetSelection(), LabelStruct::getT1(), AudacityProject::GetUpdateFlags(), AudacityProject::GetZoomOfSelection(), AudacityProject::HandleAlign(), AudacityProject::HandlePasteText(), LabelTrack::HandleTextClick(), SelectHandle::HitTest(), LabelTrack::KeyDown(), AudacityProject::MoveWhenAudioInactive(), AudacityProject::OnBoundaryMove(), LabelDialog::OnChangeStime(), AudacityProject::OnCopy(), AudacityProject::OnCursorClipBoundary(), AudacityProject::OnCursorSelEnd(), AudacityProject::OnCursorTrackEnd(), AudacityProject::OnCut(), AudacityProject::OnDisjoin(), AudacityProject::OnDuplicate(), AudacityProject::OnExportSelection(), EffectUIHost::OnFFwd(), ContrastDialog::OnGetBackground(), ContrastDialog::OnGetForeground(), AudacityProject::OnGoSelEnd(), AudacityProject::OnJoin(), AudacityProject::OnPaste(), AudacityProject::OnPasteNewLabel(), EffectUIHost::OnPlay(), AudacityProject::OnPlayAfterSelectionEnd(), AudacityProject::OnPlayAfterSelectionStart(), AudacityProject::OnPlayBeforeAndAfterSelectionEnd(), AudacityProject::OnPlayBeforeAndAfterSelectionStart(), AudacityProject::OnPlayBeforeSelectionEnd(), AudacityProject::OnPlayToSelection(), AudacityProject::OnPunchAndRoll(), AudacityProject::OnSelectClip(), AudacityProject::OnSelectClipBoundary(), AudacityProject::OnSelectionRestore(), AudacityProject::OnSetRightSelection(), AudacityProject::OnSilence(), AudacityProject::OnSplit(), AudacityProject::OnSplitCut(), AudacityProject::OnSplitDelete(), AudacityProject::OnSplitNew(), AudacityProject::OnTrim(), AudacityProject::OnZeroCrossing(), ControlToolBar::PlayPlayRegion(), AudacityProject::SeekWhenAudioInactive(), ContrastDialog::SetStartAndEndTime(), AudacityProject::SnapSelection(), SelectHandle::StartSnappingFreqSelection(), AudacityProject::TP_DisplaySelection(), LabelDialog::TransferDataToWindow(), AudacityProject::Zoom(), and AudacityProject::ZoomInByFactor().

94 { return mT1; }
void SelectedRegion::WriteXMLAttributes ( XMLWriter xmlFile,
const wxChar *  legacyT0Name = sDefaultT0Name,
const wxChar *  legacyT1Name = sDefaultT1Name 
) const

Definition at line 25 of file SelectedRegion.cpp.

References XMLWriter::WriteAttr().

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 }
double t0() const
virtual void WriteAttr(const wxString &name, const wxString &value)
Definition: XMLWriter.cpp:131
double t1() const
double f0() const
double f1() const

Friends And Related Function Documentation

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

Definition at line 261 of file SelectedRegion.h.

262  {
263  return
264  lhs.mT0 == rhs.mT0
265  && lhs.mT1 == rhs.mT1
266 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
267  && lhs.mF0 == rhs.mF0
268  && lhs.mF1 == rhs.mF1
269 #endif
270  ;
271  }

Member Data Documentation

double SelectedRegion::mF0
private

Definition at line 276 of file SelectedRegion.h.

Referenced by operator=().

double SelectedRegion::mF1
private

Definition at line 277 of file SelectedRegion.h.

Referenced by operator=().

double SelectedRegion::mT0
private

Definition at line 273 of file SelectedRegion.h.

Referenced by operator=().

double SelectedRegion::mT1
private

Definition at line 274 of file SelectedRegion.h.

Referenced by operator=().

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

Definition at line 208 of file SelectedRegion.h.

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

Definition at line 209 of file SelectedRegion.h.

const int SelectedRegion::UndefinedFrequency = -1
static

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