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 #include "XMLWriter.h"
14 
15 const wxChar *SelectedRegion::sDefaultT0Name = wxT("selStart");
16 const wxChar *SelectedRegion::sDefaultT1Name = wxT("selEnd");
17 
18 namespace {
19 const wxChar *sDefaultF0Name = wxT("selLow");
20 const wxChar *sDefaultF1Name = wxT("selHigh");
21 }
22 
24 (XMLWriter &xmlFile,
25  const wxChar *legacyT0Name, const wxChar *legacyT1Name) const
26 // may throw
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 }
37 
39 (const wxChar *attr, const wxChar *value,
40  const wxChar *legacyT0Name, const wxChar *legacyT1Name)
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 }
66 
69  const wxString &legacyT0Name, const wxString &legacyT1Name)
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 };
XMLWriter
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:23
XMLMethodRegistryBase::Mutators
std::vector< std::pair< wxString, Mutator< Substructure > > > Mutators
A helper type alias for a list of mutators, associated with tag strings.
Definition: XMLMethodRegistry.h:36
XMLWriter.h
SelectedRegion.h
SelectedRegion::WriteXMLAttributes
void WriteXMLAttributes(XMLWriter &xmlFile, const wxChar *legacyT0Name=sDefaultT0Name, const wxChar *legacyT1Name=sDefaultT1Name) const
Definition: SelectedRegion.cpp:24
SelectedRegion::Mutators
static XMLMethodRegistryBase::Mutators< SelectedRegion > Mutators(const wxString &legacyT0Name, const wxString &legacyT1Name)
Definition: SelectedRegion.cpp:68
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::sDefaultT0Name
static const wxChar * sDefaultT0Name
Definition: SelectedRegion.h:206
anonymous_namespace{SelectedRegion.cpp}::sDefaultF0Name
const wxChar * sDefaultF0Name
Definition: SelectedRegion.cpp:19
SelectedRegion::HandleXMLAttribute
bool HandleXMLAttribute(const wxChar *attr, const wxChar *value, const wxChar *legacyT0Name=sDefaultT0Name, const wxChar *legacyT1Name=sDefaultT1Name)
Definition: SelectedRegion.cpp:39
SelectedRegion::sDefaultT1Name
static const wxChar * sDefaultT1Name
Definition: SelectedRegion.h:207
SelectedRegion::setT1
bool setT1(double t, bool maySwap=true)
Definition: SelectedRegion.h:124
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