Audacity  3.0.3
SelectedRegion.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 SelectedRegion.cpp
6 
7 Paul Licameli
8 
9 *******************************************************************/
10 
11 #include "SelectedRegion.h"
12 
13 
14 
15 #include "xml/XMLWriter.h"
16 
17 const wxChar *SelectedRegion::sDefaultT0Name = wxT("selStart");
18 const wxChar *SelectedRegion::sDefaultT1Name = wxT("selEnd");
19 
20 namespace {
21 const wxChar *sDefaultF0Name = wxT("selLow");
22 const wxChar *sDefaultF1Name = wxT("selHigh");
23 }
24 
26 (XMLWriter &xmlFile,
27  const wxChar *legacyT0Name, const wxChar *legacyT1Name) const
28 // may throw
29 {
30  xmlFile.WriteAttr(legacyT0Name, t0(), 10);
31  xmlFile.WriteAttr(legacyT1Name, t1(), 10);
32 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
33  if (f0() >= 0)
34  xmlFile.WriteAttr(sDefaultF0Name, f0(), 10);
35  if (f1() >= 0)
36  xmlFile.WriteAttr(sDefaultF1Name, f1(), 10);
37 #endif
38 }
39 
41 (const wxChar *attr, const wxChar *value,
42  const wxChar *legacyT0Name, const wxChar *legacyT1Name)
43 {
44  typedef bool (SelectedRegion::*Setter)(double, bool);
45  Setter setter = 0;
46  if (!wxStrcmp(attr, legacyT0Name))
47  setter = &SelectedRegion::setT0;
48  else if (!wxStrcmp(attr, legacyT1Name))
49  setter = &SelectedRegion::setT1;
50 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
51  else if (!wxStrcmp(attr, sDefaultF0Name))
52  setter = &SelectedRegion::setF0;
53  else if (!wxStrcmp(attr, sDefaultF1Name))
54  setter = &SelectedRegion::setF1;
55 #endif
56  else
57  return false;
58 
59  double dblValue;
60  if (!Internat::CompatibleToDouble(value, &dblValue))
61  return false;
62 
63  // False means don't flip time or frequency boundaries
64  (void)(this->*setter)(dblValue, false);
65  return true;
66 }
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
XMLWriter.h
SelectedRegion.h
SelectedRegion::WriteXMLAttributes
void WriteXMLAttributes(XMLWriter &xmlFile, const wxChar *legacyT0Name=sDefaultT0Name, const wxChar *legacyT1Name=sDefaultT1Name) const
Definition: SelectedRegion.cpp:26
SelectedRegion::setT0
bool setT0(double t, bool maySwap=true)
Definition: SelectedRegion.h:115
anonymous_namespace{SelectedRegion.cpp}::sDefaultF1Name
const wxChar * sDefaultF1Name
Definition: SelectedRegion.cpp:22
SelectedRegion::sDefaultT0Name
static const wxChar * sDefaultT0Name
Definition: SelectedRegion.h:209
anonymous_namespace{SelectedRegion.cpp}::sDefaultF0Name
const wxChar * sDefaultF0Name
Definition: SelectedRegion.cpp:21
SelectedRegion::HandleXMLAttribute
bool HandleXMLAttribute(const wxChar *attr, const wxChar *value, const wxChar *legacyT0Name=sDefaultT0Name, const wxChar *legacyT1Name=sDefaultT1Name)
Definition: SelectedRegion.cpp:41
SelectedRegion::sDefaultT1Name
static const wxChar * sDefaultT1Name
Definition: SelectedRegion.h:210
SelectedRegion::setT1
bool setT1(double t, bool maySwap=true)
Definition: SelectedRegion.h:127
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:38