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{
23 {
24 return std::make_shared<ProjectNumericFormats>(project);
25 }
26};
27
29{
30 return project.AttachedObjects::Get<ProjectNumericFormats&>(key);
31}
32
35{
36 return Get(const_cast<AudacityProject &>(project));
37}
38
40 : mProject { project }
41 , mSelectionFormat{
42 gPrefs->Read(wxT("/SelectionFormat"), wxT(""))
43 }
44 , mFrequencySelectionFormatName{
45 gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT(""))
46 }
47 , mBandwidthSelectionFormatName{
48 gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT(""))
49 }
50 , mAudioTimeFormat{
51 gPrefs->Read(wxT("/AudioTimeFormat"), wxT("hh:mm:ss"))
52 }
53{}
54
56
59{
61}
62
64 const NumericFormatID & formatName)
65{
66 if (mFrequencySelectionFormatName != formatName) {
70 };
72 Publish(e);
73 }
74}
75
78{
80}
81
83 const NumericConverterType& type, const wxString& identifier)
84{
87}
88
90 const NumericFormatID &formatName)
91{
92 if (mBandwidthSelectionFormatName != formatName) {
96 };
98 Publish(e);
99 }
100}
101
103{
104 if (mSelectionFormat != format) {
108 };
110 Publish(e);
111 }
112}
113
115{
116 return mSelectionFormat;
117}
118
120{
121 if (mAudioTimeFormat != format) {
125 };
127 Publish(e);
128 }
129}
130
132{
133 return mAudioTimeFormat;
134}
135
137[](const AudacityProject &project, XMLWriter &xmlFile){
138 auto &formats = ProjectNumericFormats::Get(project);
139 xmlFile.WriteAttr(wxT("selectionformat"),
140 formats.GetSelectionFormat().GET());
141 xmlFile.WriteAttr(wxT("frequencyformat"),
142 formats.GetFrequencySelectionFormatName().GET());
143 xmlFile.WriteAttr(wxT("bandwidthformat"),
144 formats.GetBandwidthSelectionFormatName().GET());
145}
146};
147
149// Just a pointer to function, but needing overload resolution as non-const:
151 // PRL: The following have persisted as per-project settings for long.
152 // Maybe that should be abandoned. Enough to save changes in the user
153 // preference file.
154 { "selectionformat", [](auto &formats, auto value){
155 formats.SetSelectionFormat(value.ToWString());
156 } },
157 { "frequencyformat", [](auto &formats, auto value){
158 formats.SetFrequencySelectionFormatName(value.ToWString());
159 } },
160 { "bandwidthformat", [](auto &formats, auto value){
161 formats.SetBandwidthSelectionFormatName(value.ToWString());
162 } },
163} };
wxT("CloseDown"))
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
static const AttachedProjectObjects::RegisteredFactory key
static ProjectFileIORegistry::AttributeWriterEntry entry
static ProjectFileIORegistry::AttributeReaderEntries entries
const auto project
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:275
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static FormatterContext ProjectContext(const AudacityProject &project)
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
CallbackReturn Publish(const ProjectNumericFormatsEvent &message)
Send a message to connected callbacks.
Definition: Observer.h:207
void SetBandwidthSelectionFormatName(const NumericFormatID &format)
NumericFormatID GetSelectionFormat() const
const AudacityProject & mProject
NumericFormatID mBandwidthSelectionFormatName
NumericFormatID mSelectionFormat
NumericFormatID GetFrequencySelectionFormatName() const
static ProjectNumericFormats & Get(AudacityProject &project)
NumericFormatID GetBandwidthSelectionFormatName() const
void SetFrequencySelectionFormatName(const NumericFormatID &format)
NumericFormatSymbol LookupFormat(const NumericConverterType &type, const wxString &identifier)
NumericFormatID mAudioTimeFormat
void SetSelectionFormat(const NumericFormatID &format)
NumericFormatID mFrequencySelectionFormatName
~ProjectNumericFormats() override
void SetAudioTimeFormat(const NumericFormatID &format)
ProjectNumericFormats(const AudacityProject &project)
NumericFormatID GetAudioTimeFormat() const
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 NumericFormatID &formatIdentifier)
Looks up the format, returns Default for the type if the format is not registered.
Typically statically constructed.