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

CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle 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) const
 
bool ReadAndVerify (const wxString &key, wxString *val, const wxString &defVal) 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 NormalizeName (const wxString &name) const
 
wxString Escape (wxString val)
 
wxString Unescape (wxString val)
 

Detailed Description

CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle 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 Shuttle? Probably yes. Shuttle leads to shorter code.
And Shuttle is more multi-functional since Shuttle 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 Shuttle 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 164 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  }

◆ ~CommandParameters()

virtual CommandParameters::~CommandParameters ( )
inlinevirtual

Definition at line 80 of file EffectAutomationParameters.h.

81  {
82  }

Member Function Documentation

◆ DoReadDouble()

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

Definition at line 104 of file EffectAutomationParameters.h.

105  {
106  wxString str;
107  if (Read(key, &str))
108  {
109  struct lconv *info = localeconv();
110  wxString dec = info ? wxString::FromUTF8(info->decimal_point) : wxT(".");
111 
112  str.Replace(wxT(","), dec);
113  str.Replace(wxT("."), dec);
114 
115  return str.ToDouble(pd);
116  }
117 
118  return false;
119  }

References key, and Read().

Here is the call graph for this function:

◆ DoReadLong()

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

Definition at line 99 of file EffectAutomationParameters.h.

100  {
101  return wxFileConfig::DoReadLong(NormalizeName(key), pl);
102  }

References key, and NormalizeName().

Here is the call graph for this function:

◆ DoReadString()

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

Definition at line 94 of file EffectAutomationParameters.h.

95  {
96  return wxFileConfig::DoReadString(NormalizeName(key), pStr);
97  }

References key, and NormalizeName().

Here is the call graph for this function:

◆ DoWriteDouble()

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

Definition at line 131 of file EffectAutomationParameters.h.

132  {
133  return DoWriteString(key, wxString::Format(wxT("%.8g"), value));
134  }

References DoWriteString(), and key.

Here is the call graph for this function:

◆ DoWriteLong()

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

Definition at line 126 of file EffectAutomationParameters.h.

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

References key, and NormalizeName().

Here is the call graph for this function:

◆ DoWriteString()

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

Definition at line 121 of file EffectAutomationParameters.h.

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

References key, and NormalizeName().

Referenced by DoWriteDouble().

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

◆ 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  }

Referenced by GetParameters().

Here is the caller 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  }

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

Referenced by AudacityCommand::GetAutomationParameters(), Effect::GetAutomationParameters(), EffectManager::GetDefaultPreset(), EffectManager::GetPreset(), LadspaEffect::SaveParameters(), LV2Effect::SaveParameters(), VSTEffect::SaveParameters(), and NyquistEffect::ShowInterface().

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 89 of file EffectAutomationParameters.h.

90  {
91  return wxFileConfig::HasEntry(NormalizeName(strName));
92  }

References NormalizeName().

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

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

◆ HasGroup()

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

Definition at line 84 of file EffectAutomationParameters.h.

85  {
86  return wxFileConfig::HasGroup(NormalizeName(strName));
87  }

References NormalizeName().

Here is the call graph for this function:

◆ NormalizeName()

wxString CommandParameters::NormalizeName ( const wxString &  name) const
inline

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  }

References name.

Referenced by DoReadLong(), DoReadString(), DoWriteLong(), DoWriteString(), HasEntry(), and HasGroup().

Here is the caller graph for this function:

◆ ReadAndVerify() [1/7]

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

Definition at line 238 of file EffectAutomationParameters.h.

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

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 220 of file EffectAutomationParameters.h.

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

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 214 of file EffectAutomationParameters.h.

215  {
216  ReadFloat(key, val, defVal);
217  return (*val >= min && *val <= max);
218  }

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

Referenced by ShuttleSetAutomation::Define(), and ShuttleSetAutomation::DefineEnum().

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  }

References key, and ReadEnum().

Here is the call graph for this function:

◆ ReadAndVerify() [5/7]

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

Definition at line 226 of file EffectAutomationParameters.h.

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

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 232 of file EffectAutomationParameters.h.

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

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
inline

Definition at line 244 of file EffectAutomationParameters.h.

245  {
246  Read(key, val, defVal);
247  return true;
248  }

References key, and Read().

Here is the call graph for this function:

◆ 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 166 of file EffectAutomationParameters.h.

170  {
171  wxString s;
172  if (!wxFileConfig::Read(key, &s))
173  {
174  return false;
175  }
176  *pi = std::find( choices, choices + nChoices,
177  EnumValueSymbol{ s, {} } ) - choices;
178  if (*pi == (int)nChoices)
179  *pi = -1;
180  if (*pi < 0 && obsoletes) {
181  auto index = std::find_if(obsoletes, obsoletes + nObsoletes,
182  [&](const ObsoleteMap &entry){
183  return entry.first == s; })
184  - obsoletes;
185  if (index < (int)nObsoletes)
186  *pi = (int)obsoletes[index].second;
187  }
188  return true;
189  }

References key, and Read().

Referenced by ReadAndVerify(), ReadEnum(), VampEffect::SetAutomationParameters(), 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 191 of file EffectAutomationParameters.h.

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

References key, and ReadEnum().

Here is the call graph for this function:

◆ ReadFloat() [1/2]

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

Definition at line 136 of file EffectAutomationParameters.h.

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

References key, and Read().

Referenced by ReadAndVerify(), and ReadFloat().

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

◆ ReadFloat() [2/2]

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

Definition at line 147 of file EffectAutomationParameters.h.

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

References key, and ReadFloat().

Here is the call graph for this function:

◆ 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  }

References key, and Unescape().

Referenced by LadspaEffect::LoadParameters(), LV2Effect::LoadParameters(), VSTEffect::LoadParameters(), AudioUnitEffect::LoadPreset(), NyquistEffect::SetAutomationParameters(), and NyquistEffect::ShowInterface().

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  }

Referenced by SetParameters().

Here is the caller graph for this function:

◆ WriteEnum()

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

Definition at line 203 of file EffectAutomationParameters.h.

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

References key.

Referenced by EffectEqualization::GetAutomationParameters(), NyquistEffect::GetAutomationParameters(), and VampEffect::GetAutomationParameters().

Here is the caller graph for this function:

◆ WriteFloat()

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

Definition at line 156 of file EffectAutomationParameters.h.

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

References key.

Referenced by ShuttleGetAutomation::Define(), EffectAmplify::GetAutomationParameters(), EffectEcho::GetAutomationParameters(), EffectPaulstretch::GetAutomationParameters(), and EffectScienFilter::GetAutomationParameters().

Here is the caller graph for this function:

The documentation for this class was generated from the following file:
CommandParameters::Escape
wxString Escape(wxString val)
Definition: EffectAutomationParameters.h:321
CommandParameters::SetParameters
bool SetParameters(const wxString &parms)
Definition: EffectAutomationParameters.h:287
CommandParameters::ReadFloat
bool ReadFloat(const wxString &key, float *pf) const
Definition: EffectAutomationParameters.h:136
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
CommandParameters::ReadEnum
bool ReadEnum(const wxString &key, int *pi, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
Definition: EffectAutomationParameters.h:166
CommandParameters::ObsoleteMap
std::pair< wxString, size_t > ObsoleteMap
Definition: EffectAutomationParameters.h:164
name
const TranslatableString name
Definition: Distortion.cpp:98
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
Read
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:196
CommandParameters::NormalizeName
wxString NormalizeName(const wxString &name) const
Definition: EffectAutomationParameters.h:307
CommandParameters::Unescape
wxString Unescape(wxString val)
Definition: EffectAutomationParameters.h:330
CommandParameters::DoWriteString
virtual bool DoWriteString(const wxString &key, const wxString &szValue) override
Definition: EffectAutomationParameters.h:121