Audacity  2.2.2
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 #include "../Audacity.h"
17 #include "WaveformSettings.h"
18 #include "GUISettings.h"
19 #include "GUIPrefs.h"
20 
21 #include <algorithm>
22 #include <wx/intl.h>
23 
24 #include "../Prefs.h"
25 #include "../TranslatableStringArray.h"
26 #include "../Internat.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 {
89  scaleType = ScaleType(gPrefs->Read(wxT("/Waveform/ScaleType"), 0L));
90  bool newPrefFound = gPrefs->Read(wxT("/Waveform/dBRange"), &dBRange);
91  if (!newPrefFound)
93 
94  // Enforce legal values
95  Validate(true);
96 
97  Update();
98 }
99 
101 {
102  gPrefs->Write(wxT("/Waveform/ScaleType"), long(scaleType));
103  gPrefs->Write(wxT("/Waveform/dBRange"), long(dBRange));
104 }
105 
107 {
108 }
109 
111 {
112  // Assumes the codes are in ascending sequence.
113  wxArrayString codes;
114  GUIPrefs::GetRangeChoices(NULL, &codes);
115  int ii = 0;
116  for (int nn = codes.size(); ii < nn; ++ii) {
117  long value = 0;
118  codes[ii].ToLong(&value);
119  if (dBRange < value)
120  break;
121  }
122  dBRange = std::max(0, ii - 1);
123 }
124 
126 {
127  wxArrayString codes;
128  GUIPrefs::GetRangeChoices(NULL, &codes);
129  long value = 0;
130  codes[std::max(0, std::min((int)(codes.size()) - 1, dBRange))]
131  .ToLong(&value);
132  dBRange = (int)(value);
133 }
134 
136 {
138  ++dBRange;
140 }
141 
143 {
145  --dBRange;
147 }
148 
149 //static
150 const wxArrayString &WaveformSettings::GetScaleNames()
151 {
152  class ScaleNamesArray final : public TranslatableStringArray
153  {
154  void Populate() override
155  {
156  // Keep in correspondence with enum WaveTrack::WaveTrackDisplay:
157  mContents.Add(_("Linear"));
158  mContents.Add(_("Logarithmic"));
159  }
160  };
161 
162  static ScaleNamesArray theArray;
163  return theArray.Get();
164 }
165 
167 {
168 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
#define ENV_DB_KEY
Definition: GUISettings.h:15
static void GetRangeChoices(wxArrayString *pChoices, wxArrayString *pCodes)
Definition: GUIPrefs.cpp:50
bool Validate(bool quiet)
static WaveformSettings & defaults()
WaveformSettings & operator=(const WaveformSettings &other)
#define ENV_DB_RANGE
Definition: GUISettings.h:16
int min(int a, int b)
static const wxArrayString & GetScaleNames()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
Waveform settings, either for one track or as defaults.