Audacity  3.0.3
WaveformSettings.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 WaveformSettings.cpp
6 
7 Paul Licameli
8 
9 *******************************************************************//*******************************************************************/
15 
16 
17 #include "WaveformSettings.h"
18 
19 #include "Decibels.h"
20 #include "GUIPrefs.h"
21 #include "TracksPrefs.h"
22 
23 #include <algorithm>
24 #include <wx/intl.h>
25 
26 #include "Prefs.h"
27 
28 
30 {
31  LoadPrefs();
32 }
33 
35 {
36 }
37 
39 {
40 }
41 
44 {
45  static Globals instance;
46  return instance;
47 }
48 
50 {
51  LoadPrefs();
52 }
53 
55  : scaleType(other.scaleType)
56  , dBRange(other.dBRange)
57 {
58 }
59 
61 {
62  if (this != &other) {
63  scaleType = other.scaleType;
64  dBRange = other.dBRange;
65  }
66  return *this;
67 }
68 
70 {
71  static WaveformSettings instance;
72  return instance;
73 }
74 
75 bool WaveformSettings::Validate(bool /* quiet */)
76 {
78  std::max(0, std::min((int)(stNumScaleTypes) - 1, (int)(scaleType)))
79  );
80 
83 
84  return true;
85 }
86 
88 {
90 
92 
93  // Enforce legal values
94  Validate(true);
95 
96  Update();
97 }
98 
100 {
101 }
102 
104 {
105 }
106 
107 // This is a temporary hack until WaveformSettings gets fully integrated
109 {
110  if (scaleType == defaults().scaleType) {
112  }
113 
114  if (dBRange == defaults().dBRange){
116  }
117 
118  // Enforce legal values
119  Validate(true);
120 }
121 
123 {
124  // Assumes the codes are in ascending sequence.
125  wxArrayStringEx codes;
126  GUIPrefs::GetRangeChoices(nullptr, &codes);
127  int ii = 0;
128  for (int nn = codes.size(); ii < nn; ++ii) {
129  long value = 0;
130  codes[ii].ToLong(&value);
131  if (dBRange < value)
132  break;
133  }
134  dBRange = std::max(0, ii - 1);
135 }
136 
138 {
139  wxArrayStringEx codes;
140  GUIPrefs::GetRangeChoices(nullptr, &codes);
141  long value = 0;
142  codes[std::max(0, std::min((int)(codes.size()) - 1, dBRange))]
143  .ToLong(&value);
144  dBRange = (int)(value);
145 }
146 
148 {
150  ++dBRange;
152 }
153 
155 {
157  --dBRange;
159 }
160 
161 //static
163 {
164  static const EnumValueSymbols result{
165  // Keep in correspondence with ScaleTypeValues:
166  XO("Linear"),
167  XO("dB"),
168  };
169  return result;
170 }
171 
173 {
174 }
WaveformSettings::scaleType
ScaleType scaleType
Definition: WaveformSettings.h:67
WaveformSettings::Validate
bool Validate(bool quiet)
Definition: WaveformSettings.cpp:75
WaveformSettings::Globals::Get
static Globals & Get()
Definition: WaveformSettings.cpp:43
WaveformSettings::~WaveformSettings
~WaveformSettings()
Definition: WaveformSettings.cpp:172
WaveformSettings::Globals::LoadPrefs
void LoadPrefs()
Definition: WaveformSettings.cpp:38
WaveformSettings::UpdatePrefs
void UpdatePrefs() override
Definition: WaveformSettings.cpp:108
WaveformSettings::ScaleType
int ScaleType
Definition: WaveformSettings.h:57
TracksPrefs.h
XO
#define XO(s)
Definition: Internat.h:31
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
WaveformSettings::Globals
Definition: WaveformSettings.h:24
Setting::Read
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:128
WaveformSettings.h
EnumValueSymbols
Definition: Prefs.h:239
WaveformSettings::LoadPrefs
void LoadPrefs()
Definition: WaveformSettings.cpp:87
WaveformSettings::GetScaleNames
static const EnumValueSymbols & GetScaleNames()
Definition: WaveformSettings.cpp:162
WaveformSettings::ConvertToActualDBRange
void ConvertToActualDBRange()
Definition: WaveformSettings.cpp:137
WaveformSettings::NextHigherDBRange
void NextHigherDBRange()
Definition: WaveformSettings.cpp:154
GUIPrefs::GetRangeChoices
static void GetRangeChoices(TranslatableStrings *pChoices, wxArrayStringEx *pCodes, int *pDefaultRangeIndex=nullptr)
Definition: GUIPrefs.cpp:64
WaveformSettings::Globals::SavePrefs
void SavePrefs()
Definition: WaveformSettings.cpp:34
Decibels.h
DecibelScaleCutoff
IntSetting DecibelScaleCutoff
Negation of this value is the lowest dB level that should be shown in dB scales.
Definition: Decibels.cpp:12
WaveformSettings::Globals::Globals
Globals()
Definition: WaveformSettings.cpp:29
WaveformSettings::defaults
static WaveformSettings & defaults()
Definition: WaveformSettings.cpp:69
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
WaveformSettings::Update
void Update()
Definition: WaveformSettings.cpp:103
WaveformSettings::ConvertToEnumeratedDBRange
void ConvertToEnumeratedDBRange()
Definition: WaveformSettings.cpp:122
GUIPrefs.h
WaveformSettings::stNumScaleTypes
@ stNumScaleTypes
Definition: WaveformSettings.h:62
WaveformSettings::dBRange
int dBRange
Definition: WaveformSettings.h:68
WaveformSettings::NextLowerDBRange
void NextLowerDBRange()
Definition: WaveformSettings.cpp:147
WaveformSettings
Waveform settings, either for one track or as defaults.
Definition: WaveformSettings.h:19
WaveformSettings::SavePrefs
void SavePrefs()
Definition: WaveformSettings.cpp:99
Prefs.h
WaveformSettings::operator=
WaveformSettings & operator=(const WaveformSettings &other)
Definition: WaveformSettings.cpp:60
WaveformSettings::WaveformSettings
WaveformSettings()
Definition: WaveformSettings.cpp:49
TracksPrefs::WaveformScaleChoice
static WaveformSettings::ScaleTypeValues WaveformScaleChoice()
Definition: TracksPrefs.cpp:173