Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
CommandParameters Class Referencefinal

CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVisitor classes. It does text <-> binary conversions of parameters. It does not seem to be using actual file read/writing.
More...

#include <EffectAutomationParameters.h>

Inheritance diagram for CommandParameters:
[legend]
Collaboration diagram for CommandParameters:
[legend]

Public Types

using ObsoleteMap = std::pair< wxString, size_t >
 

Public Member Functions

 CommandParameters (const wxString &parms={})
 
virtual ~CommandParameters ()
 
virtual bool HasGroup (const wxString &strName) const override
 
virtual bool HasEntry (const wxString &strName) const override
 
virtual bool DoReadString (const wxString &key, wxString *pStr) const override
 
virtual bool DoReadLong (const wxString &key, long *pl) const override
 
virtual bool DoReadDouble (const wxString &key, double *pd) const override
 
virtual bool DoWriteString (const wxString &key, const wxString &szValue) override
 
virtual bool DoWriteLong (const wxString &key, long lValue) override
 
virtual bool DoWriteDouble (const wxString &key, double value) override
 
bool ReadFloat (const wxString &key, float *pf) const
 
bool ReadFloat (const wxString &key, float *pf, float defVal) const
 
bool WriteFloat (const wxString &key, float f)
 
bool ReadEnum (const wxString &key, int *pi, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
 
bool ReadEnum (const wxString &key, int *pi, int defVal, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
 
bool WriteEnum (const wxString &key, int value, const EnumValueSymbol choices[], size_t nChoices)
 
bool ReadAndVerify (const wxString &key, float *val, float defVal, float min, float max) const
 
bool ReadAndVerify (const wxString &key, double *val, double defVal, double min, double max) const
 
bool ReadAndVerify (const wxString &key, int *val, int defVal, int min, int max) const
 
bool ReadAndVerify (const wxString &key, long *val, long defVal, long min, long max) const
 
bool ReadAndVerify (const wxString &key, bool *val, bool defVal, bool=false, bool=false) const
 
bool ReadAndVerify (const wxString &key, wxString *val, const wxString &defVal, const wxString &={}, const wxString &={}) const
 
bool ReadAndVerify (const wxString &key, int *val, int defVal, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
 
bool GetParameters (wxString &parms)
 
bool SetParameters (const wxString &parms)
 
wxString Escape (wxString val)
 
wxString Unescape (wxString val)
 

Static Public Member Functions

static wxString NormalizeName (const wxString &name)
 

Detailed Description

CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVisitor classes. It does text <-> binary conversions of parameters. It does not seem to be using actual file read/writing.

Should it be converted to using SettingsVisitor? Probably yes. SettingsVisitor leads to shorter code. And SettingsVisitor is more multi-functional since SettingsVisitor can report on signature, do the work of wxWidget validators, and can create default dialogs. However until that conversion is done, we need this class, and we use a pointer to one from within a SettingsVisitor when interfacing with the code that still uses it.

Definition at line 66 of file EffectAutomationParameters.h.

Member Typedef Documentation

◆ ObsoleteMap

using CommandParameters::ObsoleteMap = std::pair< wxString, size_t >

Definition at line 163 of file EffectAutomationParameters.h.

Constructor & Destructor Documentation

◆ CommandParameters()

CommandParameters::CommandParameters ( const wxString &  parms = {})
inline

Definition at line 69 of file EffectAutomationParameters.h.

69 {})
70 : wxFileConfig(wxEmptyString,
71 wxEmptyString,
72 wxEmptyString,
73 wxEmptyString,
74 0)
75 {
76 SetExpandEnvVars(false);
77 SetParameters(parms);
78 }
bool SetParameters(const wxString &parms)

◆ ~CommandParameters()

CommandParameters::~CommandParameters ( )
virtualdefault

Member Function Documentation

◆ DoReadDouble()

virtual bool CommandParameters::DoReadDouble ( const wxString &  key,
double *  pd 
) const
inlineoverridevirtual

Definition at line 102 of file EffectAutomationParameters.h.

103 {
104 wxString str;
105 if (Read(key, &str))
106 {
107 struct lconv *info = localeconv();
108 wxString dec =
109 info ? wxString::FromUTF8(info->decimal_point) : wxString(".");
110
111 str.Replace(wxT(","), dec);
112 str.Replace(wxT("."), dec);
113
114 return str.ToDouble(pd);
115 }
116
117 return false;
118 }
wxT("CloseDown"))
static const AudacityProject::AttachedObjects::RegisteredFactory key
#define str(a)
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)

References key, Read(), str, and wxT().

Here is the call graph for this function:

◆ DoReadLong()

virtual bool CommandParameters::DoReadLong ( const wxString &  key,
long *  pl 
) const
inlineoverridevirtual

Definition at line 97 of file EffectAutomationParameters.h.

98 {
99 return wxFileConfig::DoReadLong(NormalizeName(key), pl);
100 }
static wxString NormalizeName(const wxString &name)

References key.

◆ DoReadString()

virtual bool CommandParameters::DoReadString ( const wxString &  key,
wxString *  pStr 
) const
inlineoverridevirtual

Definition at line 92 of file EffectAutomationParameters.h.

93 {
94 return wxFileConfig::DoReadString(NormalizeName(key), pStr);
95 }

References key.

◆ DoWriteDouble()

virtual bool CommandParameters::DoWriteDouble ( const wxString &  key,
double  value 
)
inlineoverridevirtual

Definition at line 130 of file EffectAutomationParameters.h.

131 {
132 return DoWriteString(key, wxString::Format(wxT("%.8g"), value));
133 }
virtual bool DoWriteString(const wxString &key, const wxString &szValue) override

References key, and wxT().

Here is the call graph for this function:

◆ DoWriteLong()

virtual bool CommandParameters::DoWriteLong ( const wxString &  key,
long  lValue 
)
inlineoverridevirtual

Definition at line 125 of file EffectAutomationParameters.h.

126 {
127 return wxFileConfig::DoWriteLong(NormalizeName(key), lValue);
128 }

References key.

◆ DoWriteString()

virtual bool CommandParameters::DoWriteString ( const wxString &  key,
const wxString &  szValue 
)
inlineoverridevirtual

Definition at line 120 of file EffectAutomationParameters.h.

121 {
122 return wxFileConfig::DoWriteString(NormalizeName(key), szValue);
123 }

References key.

◆ Escape()

wxString CommandParameters::Escape ( wxString  val)
inline

Definition at line 321 of file EffectAutomationParameters.h.

322 {
323 val.Replace(wxT("\\"), wxT("\\\\"), true);
324 val.Replace(wxT("\""), wxT("\\\""), true);
325 val.Replace(wxT("\n"), wxT("\\n"), true);
326
327 return val;
328 }

References wxT().

Here is the call graph for this function:

◆ GetParameters()

bool CommandParameters::GetParameters ( wxString &  parms)
inline

Definition at line 259 of file EffectAutomationParameters.h.

260 {
261 wxFileConfig::SetPath(wxT("/"));
262
263 wxString str;
264 wxString key;
265
266 long ndx = 0;
267 bool res = wxFileConfig::GetFirstEntry(key, ndx);
268 while (res)
269 {
270 wxString val;
271 if (!wxFileConfig::Read(key, &val))
272 {
273 return false;
274 }
275
276 str += key + wxT("=\"") + Escape(val) + wxT("\" ");
277
278 res = wxFileConfig::GetNextEntry(key, ndx);
279 }
280 str.Trim();
281
282 parms = str;
283
284 return true;
285 }
wxString Escape(wxString val)

References key, Read(), str, and wxT().

Referenced by EffectManager::GetDefaultPreset(), EffectManager::GetPreset(), LadspaEffect::SaveParameters(), LV2Effect::SaveParameters(), Effect::SaveSettingsAsString(), AudacityCommand::SaveSettingsAsString(), VSTEffect::SaveUserPreset(), and NyquistEffect::ShowHostInterface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasEntry()

virtual bool CommandParameters::HasEntry ( const wxString &  strName) const
inlineoverridevirtual

Definition at line 87 of file EffectAutomationParameters.h.

88 {
89 return wxFileConfig::HasEntry(NormalizeName(strName));
90 }

Referenced by ShuttleSetAutomation::CouldGet(), EffectManager::GetPreset(), VST3Wrapper::LoadSettings(), and EffectManager::SetEffectParameters().

Here is the caller graph for this function:

◆ HasGroup()

virtual bool CommandParameters::HasGroup ( const wxString &  strName) const
inlineoverridevirtual

Definition at line 82 of file EffectAutomationParameters.h.

83 {
84 return wxFileConfig::HasGroup(NormalizeName(strName));
85 }

◆ NormalizeName()

static wxString CommandParameters::NormalizeName ( const wxString &  name)
inlinestatic

Definition at line 307 of file EffectAutomationParameters.h.

308 {
309 wxString cleaned = name;
310
311 cleaned.Trim(true).Trim(false);
312 cleaned.Replace(wxT(" "), wxT("_"));
313 cleaned.Replace(wxT("/"), wxT("_"));
314 cleaned.Replace(wxT("\\"), wxT("_"));
315 cleaned.Replace(wxT(":"), wxT("_"));
316 cleaned.Replace(wxT("="), wxT("_"));
317
318 return cleaned;
319 }
const TranslatableString name
Definition: Distortion.cpp:82

References name, and wxT().

Referenced by VSTEffectWrapper::ForEachParameter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadAndVerify() [1/7]

bool CommandParameters::ReadAndVerify ( const wxString &  key,
bool *  val,
bool  defVal,
bool  = false,
bool  = false 
) const
inline

Definition at line 237 of file EffectAutomationParameters.h.

238 {
239 Read(key, val, defVal);
240 return true;
241 }

References key, and Read().

Here is the call graph for this function:

◆ ReadAndVerify() [2/7]

bool CommandParameters::ReadAndVerify ( const wxString &  key,
double *  val,
double  defVal,
double  min,
double  max 
) const
inline

Definition at line 219 of file EffectAutomationParameters.h.

220 {
221 Read(key, val, defVal);
222 return (*val >= min && *val <= max);
223 }
int min(int a, int b)

References key, min(), and Read().

Here is the call graph for this function:

◆ ReadAndVerify() [3/7]

bool CommandParameters::ReadAndVerify ( const wxString &  key,
float *  val,
float  defVal,
float  min,
float  max 
) const
inline

Definition at line 213 of file EffectAutomationParameters.h.

214 {
215 ReadFloat(key, val, defVal);
216 return (*val >= min && *val <= max);
217 }
bool ReadFloat(const wxString &key, float *pf) const

References key, and min().

Referenced by ShuttleSetAutomation::Define(), ShuttleSetAutomation::DefineEnum(), EffectTruncSilence::LoadSettings(), and CapturedParameters< EffectType, Parameters >::SetOne().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadAndVerify() [4/7]

bool CommandParameters::ReadAndVerify ( const wxString &  key,
int *  val,
int  defVal,
const EnumValueSymbol  choices[],
size_t  nChoices,
const ObsoleteMap  obsoletes[] = nullptr,
size_t  nObsoletes = 0 
) const
inline

Definition at line 250 of file EffectAutomationParameters.h.

254 {
255 ReadEnum(key, val, defVal, choices, nChoices, obsoletes, nObsoletes);
256 return (*val != wxNOT_FOUND);
257 }
bool ReadEnum(const wxString &key, int *pi, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const

References key.

◆ ReadAndVerify() [5/7]

bool CommandParameters::ReadAndVerify ( const wxString &  key,
int *  val,
int  defVal,
int  min,
int  max 
) const
inline

Definition at line 225 of file EffectAutomationParameters.h.

226 {
227 Read(key, val, defVal);
228 return (*val >= min && *val <= max);
229 }

References key, min(), and Read().

Here is the call graph for this function:

◆ ReadAndVerify() [6/7]

bool CommandParameters::ReadAndVerify ( const wxString &  key,
long *  val,
long  defVal,
long  min,
long  max 
) const
inline

Definition at line 231 of file EffectAutomationParameters.h.

232 {
233 Read(key, val, defVal);
234 return (*val >= min && *val <= max);
235 }

References key, min(), and Read().

Here is the call graph for this function:

◆ ReadAndVerify() [7/7]

bool CommandParameters::ReadAndVerify ( const wxString &  key,
wxString *  val,
const wxString &  defVal,
const wxString &  = {},
const wxString &  = {} 
) const
inline

Definition at line 243 of file EffectAutomationParameters.h.

244 {}, const wxString& = {} ) const
245 {
246 Read(key, val, defVal);
247 return true;
248 }

◆ ReadEnum() [1/2]

bool CommandParameters::ReadEnum ( const wxString &  key,
int *  pi,
const EnumValueSymbol  choices[],
size_t  nChoices,
const ObsoleteMap  obsoletes[] = nullptr,
size_t  nObsoletes = 0 
) const
inline

Definition at line 165 of file EffectAutomationParameters.h.

169 {
170 wxString s;
171 if (!wxFileConfig::Read(key, &s))
172 {
173 return false;
174 }
175 *pi = std::find( choices, choices + nChoices,
176 EnumValueSymbol{ s, {} } ) - choices;
177 if (*pi == (int)nChoices)
178 *pi = -1;
179 if (*pi < 0 && obsoletes) {
180 auto index = std::find_if(obsoletes, obsoletes + nObsoletes,
181 [&](const ObsoleteMap &entry){
182 return entry.first == s; })
183 - obsoletes;
184 if (index < (int)nObsoletes)
185 *pi = (int)obsoletes[index].second;
186 }
187 return true;
188 }
static ProjectFileIORegistry::AttributeWriterEntry entry
std::pair< wxString, size_t > ObsoleteMap
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...

References entry, key, and Read().

Referenced by VampEffect::LoadSettings(), and NyquistEffect::SetLispVarsFromParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadEnum() [2/2]

bool CommandParameters::ReadEnum ( const wxString &  key,
int *  pi,
int  defVal,
const EnumValueSymbol  choices[],
size_t  nChoices,
const ObsoleteMap  obsoletes[] = nullptr,
size_t  nObsoletes = 0 
) const
inline

Definition at line 190 of file EffectAutomationParameters.h.

194 {
195 if (!ReadEnum(key, pi, choices, nChoices, obsoletes, nObsoletes))
196 {
197 *pi = defVal;
198 }
199 return true;
200 }

References key.

◆ ReadFloat() [1/2]

bool CommandParameters::ReadFloat ( const wxString &  key,
float *  pf 
) const
inline

Definition at line 135 of file EffectAutomationParameters.h.

136 {
137 double d = *pf;
138 bool success = Read(key, &d);
139 if (success)
140 {
141 *pf = (float) d;
142 }
143 return success;
144 }

References key, and Read().

Here is the call graph for this function:

◆ ReadFloat() [2/2]

bool CommandParameters::ReadFloat ( const wxString &  key,
float *  pf,
float  defVal 
) const
inline

Definition at line 146 of file EffectAutomationParameters.h.

147 {
148 if (!ReadFloat(key, pf))
149 {
150 *pf = defVal;
151 }
152 return true;
153 }

References key.

◆ SetParameters()

bool CommandParameters::SetParameters ( const wxString &  parms)
inline

Definition at line 287 of file EffectAutomationParameters.h.

288 {
289 wxFileConfig::SetPath(wxT("/"));
290
291 auto parsed = wxCmdLineParser::ConvertStringToArgs(parms);
292
293 for (size_t i = 0, cnt = parsed.size(); i < cnt; i++)
294 {
295 wxString key = parsed[i].BeforeFirst(wxT('=')).Trim(false).Trim(true);
296 wxString val = parsed[i].AfterFirst(wxT('=')).Trim(false).Trim(true);
297
298 if (!wxFileConfig::Write(key, Unescape(val)))
299 {
300 return false;
301 }
302 }
303
304 return true;
305 }
wxString Unescape(wxString val)

References key, and wxT().

Referenced by NyquistEffect::DoLoadSettings(), LadspaEffect::LoadParameters(), LV2Effect::LoadParameters(), VSTEffect::LoadUserPreset(), AudioUnitEffect::MigrateOldConfigFile(), and NyquistEffect::ShowHostInterface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Unescape()

wxString CommandParameters::Unescape ( wxString  val)
inline

Definition at line 330 of file EffectAutomationParameters.h.

331 {
332 val.Replace(wxT("\\n"), wxT("\n"), true);
333 val.Replace(wxT("\\\""), wxT("\""), true);
334 val.Replace(wxT("\\\\"), wxT("\\"), true);
335
336 return val;
337 }

References wxT().

Here is the call graph for this function:

◆ WriteEnum()

bool CommandParameters::WriteEnum ( const wxString &  key,
int  value,
const EnumValueSymbol  choices[],
size_t  nChoices 
)
inline

Definition at line 202 of file EffectAutomationParameters.h.

204 {
205 if (value < 0 || value >= (int)nChoices)
206 {
207 return false;
208 }
209
210 return wxFileConfig::Write(key, choices[value].Internal());
211 }
@ Internal
Indicates internal failure from Audacity.

References Internal, and key.

Referenced by NyquistEffect::SaveSettings(), and VampEffect::SaveSettings().

Here is the caller graph for this function:

◆ WriteFloat()

bool CommandParameters::WriteFloat ( const wxString &  key,
float  f 
)
inline

Definition at line 155 of file EffectAutomationParameters.h.

156 {
157 return Write(key, f);
158 }

References key.

Referenced by ShuttleGetAutomation::Define().

Here is the caller graph for this function:

The documentation for this class was generated from the following files: