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 if (f0() >= 0)
32 xmlFile.WriteAttr(sDefaultF0Name, f0(), 10);
33 if (f1() >= 0)
34 xmlFile.WriteAttr(sDefaultF1Name, f1(), 10);
35}
36
38(const std::string_view &attr, const XMLAttributeValueView &value,
39 const char *legacyT0Name, const char *legacyT1Name)
40{
41 // Keep this function consistent with the table in the next!
42 typedef bool (SelectedRegion::*Setter)(double, bool);
43 Setter setter = 0;
44 if (attr == legacyT0Name)
45 setter = &SelectedRegion::setT0;
46 else if (attr == legacyT1Name)
47 setter = &SelectedRegion::setT1;
48 else if (attr == sDefaultF0Name)
49 setter = &SelectedRegion::setF0;
50 else if (attr == sDefaultF1Name)
51 setter = &SelectedRegion::setF1;
52 else
53 return false;
54
55 double dblValue;
56
57 if (!value.TryGet(dblValue))
58 return false;
59
60 // False means don't flip time or frequency boundaries
61 (void)(this->*setter)(dblValue, false);
62 return true;
63}
64
67 const char *legacyT0Name, const char *legacyT1Name)
68{
69 // Keep this table consistent with the previous function!
70 return {
71 { legacyT0Name, [=](auto &selectedRegion, auto value){
72 selectedRegion
73 .HandleXMLAttribute(legacyT0Name, value,
74 legacyT0Name, legacyT1Name);
75 } },
76 { legacyT1Name, [=](auto &selectedRegion, auto value){
77 selectedRegion
78 .HandleXMLAttribute(legacyT1Name, value,
79 legacyT0Name, legacyT1Name);
80 } },
81 { sDefaultF0Name, [=](auto &selectedRegion, auto value){
82 selectedRegion
83 .HandleXMLAttribute(sDefaultF0Name, value, "", "");
84 } },
85 { sDefaultF1Name, [=](auto &selectedRegion, auto value){
86 selectedRegion
87 .HandleXMLAttribute(sDefaultF1Name, value, "", "");
88 } },
89 };
90};
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
bool setF0(double f, bool maySwap=true)
bool setF1(double f, bool maySwap=true)
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:25