Audacity 3.2.0
SelectedRegion.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5SelectedRegion.cpp
6
7Paul Licameli
8
9*******************************************************************/
10
11#include "SelectedRegion.h"
12
13#include "XMLWriter.h"
15
16const char* SelectedRegion::sDefaultT0Name = "selStart";
17const char *SelectedRegion::sDefaultT1Name = "selEnd";
18
19namespace {
20const char* sDefaultF0Name = "selLow";
21const char* sDefaultF1Name = "selHigh";
22}
23
25(XMLWriter &xmlFile,
26 const char *legacyT0Name, const char *legacyT1Name) const
27// may throw
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}
38
40(const std::string_view &attr, const XMLAttributeValueView &value,
41 const char *legacyT0Name, const char *legacyT1Name)
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}
68
71 const char *legacyT0Name, const char *legacyT1Name)
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};
Defines a selected portion of a project.
static XMLMethodRegistryBase::Mutators< SelectedRegion > Mutators(const char *legacyT0Name, const char *legacyT1Name)
void WriteXMLAttributes(XMLWriter &xmlFile, const char *legacyT0Name=sDefaultT0Name, const char *legacyT1Name=sDefaultT1Name) const
static const char * sDefaultT1Name
static const char * sDefaultT0Name
bool HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &value, const char *legacyT0Name=sDefaultT0Name, const char *legacyT1Name=sDefaultT1Name)
bool setT0(double t, bool maySwap=true)
bool setT1(double t, bool maySwap=true)
A view into an attribute value. The class does not take the ownership of the data.
bool TryGet(bool &value) const noexcept
Try to get a boolean value from the view.
std::vector< std::pair< std::string, Mutator< Substructure > > > Mutators
A helper type alias for a list of mutators, associated with tag strings.
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26