File: NumericConverterFormats.cpp

package info (click to toggle)
audacity 3.7.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 125,252 kB
  • sloc: cpp: 358,238; ansic: 75,458; lisp: 7,761; sh: 3,410; python: 1,503; xml: 1,385; perl: 854; makefile: 122
file content (134 lines) | stat: -rw-r--r-- 3,485 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*  SPDX-License-Identifier: GPL-2.0-or-later */
/**********************************************************************

 Audacity: A Digital Audio Editor

 @file NumericConverterFormats.cpp

 Dmitry Vedenko

 **********************************************************************/

#include "NumericConverterFormats.h"
#include "NumericConverterRegistry.h"
#include "NumericConverterFormatterContext.h"

#include <cassert>
#include <unordered_map>

namespace
{

std::unordered_map<NumericConverterType, NumericFormatSymbol>& GetDefaultSymbols()
{
   static std::unordered_map<NumericConverterType, NumericFormatSymbol> symbols;
   return symbols;
}
}

namespace NumericConverterFormats
{
DefaultFormatRegistrator::DefaultFormatRegistrator(
   const NumericConverterType& type, const NumericFormatSymbol& symbol)
{
   auto& defaultSymbols = GetDefaultSymbols();
   
   if (defaultSymbols.find(type) != defaultSymbols.end())
   {
      // We do not allow to register multiple defaults
      // for a single type
      assert(false);
      return;
   }

   defaultSymbols.emplace(type, symbol);
}

NumericFormatSymbol Default(const NumericConverterType& type)
{
   auto& defaultSymbols = GetDefaultSymbols();
   
   auto it = defaultSymbols.find(type);

   if (it != defaultSymbols.end())
      return it->second;

   // Fail the debug build early
   assert(false);
   
   return {};
}

NUMERIC_FORMATS_API NumericFormatSymbol Lookup(
   const FormatterContext& context, 
   const NumericConverterType& type,
   const NumericFormatID& formatIdentifier)
{
   if (formatIdentifier.empty())
      return Default(type);

   auto result = NumericConverterRegistry::Find(context, type, { formatIdentifier });

   if (result == nullptr)
      return Default(type);

   return result->symbol;
}

NUMERIC_FORMATS_API NumericFormatSymbol DefaultSelectionFormat()
{
   return MillisecondsFormat();
}

NUMERIC_FORMATS_API NumericFormatSymbol TimeAndSampleFormat()
{
   /* i18n-hint: Name of time display format that shows time in hours,
    * minutes, seconds and samples (at the current project sample rate) */
   return { XO("hh:mm:ss + samples") };
}

NUMERIC_FORMATS_API NumericFormatSymbol SecondsFormat()
{
   /* i18n-hint: Name of time display format that shows time in seconds */
   return { XO("seconds") };
}

NUMERIC_FORMATS_API NumericFormatSymbol HoursMinsSecondsFormat()
{
   /* i18n-hint: Name of time display format that shows time in hours, minutes
    * and seconds */
   return { XO("hh:mm:ss") };
}

NUMERIC_FORMATS_API NumericFormatSymbol MillisecondsFormat()
{
   /* i18n-hint: Name of time display format that shows time in hours,
    * minutes, seconds and milliseconds (1/1000 second) */
   return { XO("hh:mm:ss + milliseconds") };
}

NUMERIC_FORMATS_API NumericFormatSymbol HundredthsFormat()
{
   /* i18n-hint: Name of time display format that shows time in hours,
    * minutes, seconds and hundredths of a second (1/100 second) */
   return { XO("hh:mm:ss + hundredths") };
}

NUMERIC_FORMATS_API NumericFormatSymbol HertzFormat()
{
   /* i18n-hint: Name of display format that shows frequency in hertz */
   return { XO("Hz") };
}

NUMERIC_FORMATS_API NumericFormatSymbol OctavesFormat()
{
   /* i18n-hint: Name of display format that shows log of frequency
    * in octaves */
   return { XO("octaves") };
}
NUMERIC_FORMATS_API NumericFormatID
GetBestDurationFormat(const NumericFormatID& timeFormat)
{
   return timeFormat;
}
} // namespace NumericConverterFormats