Audacity 3.2.0
NumericConverterFormats.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 @file NumericConverterFormats.cpp
7
8 Dmitry Vedenko
9
10 **********************************************************************/
11
15
16#include <cassert>
17#include <unordered_map>
18
19namespace
20{
21
22std::unordered_map<NumericConverterType, NumericFormatSymbol>& GetDefaultSymbols()
23{
24 static std::unordered_map<NumericConverterType, NumericFormatSymbol> symbols;
25 return symbols;
26}
27}
28
30{
32 const NumericConverterType& type, const NumericFormatSymbol& symbol)
33{
34 auto& defaultSymbols = GetDefaultSymbols();
35
36 if (defaultSymbols.find(type) != defaultSymbols.end())
37 {
38 // We do not allow to register multiple defaults
39 // for a single type
40 assert(false);
41 return;
42 }
43
44 defaultSymbols.emplace(type, symbol);
45}
46
48{
49 auto& defaultSymbols = GetDefaultSymbols();
50
51 auto it = defaultSymbols.find(type);
52
53 if (it != defaultSymbols.end())
54 return it->second;
55
56 // Fail the debug build early
57 assert(false);
58
59 return {};
60}
61
62NUMERIC_FORMATS_API NumericFormatSymbol Lookup(
63 const FormatterContext& context,
64 const NumericConverterType& type,
65 const NumericFormatID& formatIdentifier)
66{
67 if (formatIdentifier.empty())
68 return Default(type);
69
70 auto result = NumericConverterRegistry::Find(context, type, { formatIdentifier });
71
72 if (result == nullptr)
73 return Default(type);
74
75 return result->symbol;
76}
77
79{
80 return MillisecondsFormat();
81}
82
84{
85 /* i18n-hint: Name of time display format that shows time in hours,
86 * minutes, seconds and samples (at the current project sample rate) */
87 return { XO("hh:mm:ss + samples") };
88}
89
91{
92 /* i18n-hint: Name of time display format that shows time in seconds */
93 return { XO("seconds") };
94}
95
97{
98 /* i18n-hint: Name of time display format that shows time in hours, minutes
99 * and seconds */
100 return { XO("hh:mm:ss") };
101}
102
104{
105 /* i18n-hint: Name of time display format that shows time in hours,
106 * minutes, seconds and milliseconds (1/1000 second) */
107 return { XO("hh:mm:ss + milliseconds") };
108}
109
111{
112 /* i18n-hint: Name of time display format that shows time in hours,
113 * minutes, seconds and hundredths of a second (1/100 second) */
114 return { XO("hh:mm:ss + hundredths") };
115}
116
117NUMERIC_FORMATS_API NumericFormatSymbol HertzFormat()
118{
119 /* i18n-hint: Name of display format that shows frequency in hertz */
120 return { XO("Hz") };
121}
122
124{
125 /* i18n-hint: Name of display format that shows log of frequency
126 * in octaves */
127 return { XO("octaves") };
128}
129NUMERIC_FORMATS_API NumericFormatID
131{
132 return timeFormat;
133}
134} // namespace NumericConverterFormats
XO("Cut/Copy/Paste")
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
A context in which formatter operates.
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
bool empty() const
Definition: Identifier.h:61
NUMERIC_FORMATS_API NumericFormatSymbol HoursMinsSecondsFormat()
NUMERIC_FORMATS_API NumericFormatSymbol MillisecondsFormat()
NUMERIC_FORMATS_API NumericFormatSymbol HundredthsFormat()
NUMERIC_FORMATS_API NumericFormatSymbol DefaultSelectionFormat()
NUMERIC_FORMATS_API NumericFormatSymbol HertzFormat()
NUMERIC_FORMATS_API NumericFormatSymbol SecondsFormat()
NumericFormatSymbol Default(const NumericConverterType &type)
Returns the default format for the type or empty symbol, if no default symbol is registered.
NUMERIC_FORMATS_API NumericFormatSymbol OctavesFormat()
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.
NUMERIC_FORMATS_API NumericFormatID GetBestDurationFormat(const NumericFormatID &timeFormat)
Return the best duration format for the given time format. Currently is an identity function.
NUMERIC_FORMATS_API NumericFormatSymbol TimeAndSampleFormat()
std::unordered_map< NumericConverterType, NumericFormatSymbol > & GetDefaultSymbols()
DefaultFormatRegistrator(const NumericConverterType &type, const NumericFormatSymbol &symbol)
static const NumericConverterRegistryItem * Find(const FormatterContext &context, const NumericConverterType &type, const NumericFormatID &symbol)