Audacity 3.2.0
ProjectNumericFormats.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file ProjectNumericFormats.cpp
6
7 Paul Licameli split from ProjectNumericFormats.cpp
8
9 **********************************************************************/
11#include "Prefs.h"
12#include "Project.h"
13
16
18#include "XMLWriter.h"
19
21{
22 [](AudacityProject &project)
23 {
24 return std::make_shared<ProjectNumericFormats>(project);
25 }
26};
27
29{
30 return project.AttachedObjects::Get<ProjectNumericFormats&>(key);
31}
32
34 const AudacityProject &project)
35{
36 return Get(const_cast<AudacityProject &>(project));
37}
38
40 : mProject { project }
41 , mSelectionFormat{ NumericConverterFormats::Lookup(
42 FormatterContext::ProjectContext(project),
44 gPrefs->Read(wxT("/SelectionFormat"), wxT("")))
45 }
46 , mFrequencySelectionFormatName{ NumericConverterFormats::Lookup(
47 FormatterContext::ProjectContext(project),
49 gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT("")) )
50 }
51 , mBandwidthSelectionFormatName{ NumericConverterFormats::Lookup(
52 FormatterContext::ProjectContext(project),
54 gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT("")) )
55 }
56 , mAudioTimeFormat{ NumericConverterFormats::Lookup(
57 FormatterContext::ProjectContext(project),
59 gPrefs->Read(wxT("/AudioTimeFormat"), wxT("hh:mm:ss")))
60 }
61{}
62
64
67{
69}
70
72 const NumericFormatSymbol & formatName)
73{
75}
76
79{
81}
82
84 const NumericConverterType& type, const wxString& identifier)
85{
88}
89
91 const NumericFormatSymbol & formatName)
92{
94}
95
98{
100}
101
103{
104 return mSelectionFormat;
105}
106
108{
110}
111
113{
114 return mAudioTimeFormat;
115}
116
118[](const AudacityProject &project, XMLWriter &xmlFile){
119 auto &formats = ProjectNumericFormats::Get(project);
120 xmlFile.WriteAttr(wxT("selectionformat"),
121 formats.GetSelectionFormat().Internal());
122 xmlFile.WriteAttr(wxT("frequencyformat"),
123 formats.GetFrequencySelectionFormatName().Internal());
124 xmlFile.WriteAttr(wxT("bandwidthformat"),
125 formats.GetBandwidthSelectionFormatName().Internal());
126}
127};
128
130// Just a pointer to function, but needing overload resolution as non-const:
132 // PRL: The following have persisted as per-project settings for long.
133 // Maybe that should be abandoned. Enough to save changes in the user
134 // preference file.
135 { "selectionformat", [](auto &formats, auto value){
136 formats.SetSelectionFormat(formats.LookupFormat(
137 NumericConverterType_TIME(), value.ToWString()));
138 } },
139 { "frequencyformat", [](auto &formats, auto value){
140 formats.SetFrequencySelectionFormatName(formats.LookupFormat(
141 NumericConverterType_FREQUENCY(), value.ToWString()));
142 } },
143 { "bandwidthformat", [](auto &formats, auto value){
144 formats.SetBandwidthSelectionFormatName(formats.LookupFormat(
145 NumericConverterType_BANDWIDTH(), value.ToWString()));
146 } },
147} };
wxT("CloseDown"))
int format
Definition: ExportPCM.cpp:53
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)
const NumericConverterType & NumericConverterType_BANDWIDTH()
const NumericConverterType & NumericConverterType_FREQUENCY()
const NumericConverterType & NumericConverterType_TIME()
FileConfig * gPrefs
Definition: Prefs.cpp:70
static const AttachedProjectObjects::RegisteredFactory key
static ProjectFileIORegistry::AttributeWriterEntry entry
static ProjectFileIORegistry::AttributeReaderEntries entries
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
A context in which formatter operates.
static FormatterContext ProjectContext(const AudacityProject &project)
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
void SetBandwidthSelectionFormatName(const NumericFormatSymbol &format)
const NumericFormatSymbol & GetFrequencySelectionFormatName() const
NumericFormatSymbol mFrequencySelectionFormatName
NumericFormatSymbol mBandwidthSelectionFormatName
const AudacityProject & mProject
const NumericFormatSymbol & GetSelectionFormat() const
void SetFrequencySelectionFormatName(const NumericFormatSymbol &format)
const NumericFormatSymbol & GetBandwidthSelectionFormatName() const
static ProjectNumericFormats & Get(AudacityProject &project)
void SetSelectionFormat(const NumericFormatSymbol &format)
NumericFormatSymbol LookupFormat(const NumericConverterType &type, const wxString &identifier)
NumericFormatSymbol mAudioTimeFormat
const NumericFormatSymbol & GetAudioTimeFormat() const
void SetAudioTimeFormat(const NumericFormatSymbol &format)
NumericFormatSymbol mSelectionFormat
~ProjectNumericFormats() override
ProjectNumericFormats(const AudacityProject &project)
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
NUMERIC_FORMATS_API NumericFormatSymbol Lookup(const FormatterContext &context, const NumericConverterType &type, const NumericFormatSymbol &formatIdentifier)
Looks up the format, returns Default for the type if the format is not registered.
Typically statically constructed.