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

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

References key, Read(), and str.

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  }

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  }

References key.

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

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

◆ GetParameters()

bool CommandParameters::GetParameters ( wxString &  parms)
inline

Definition at line 258 of file EffectAutomationParameters.h.

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

References key, Read(), and str.

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

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

Referenced by ShuttleSetAutomation::CouldGet(), EffectManager::GetPreset(), 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()

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

Definition at line 306 of file EffectAutomationParameters.h.

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

References name.

◆ ReadAndVerify() [1/7]

bool CommandParameters::ReadAndVerify ( const wxString &  key,
bool *  val,
bool  defVal 
) 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  }

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  }

References key, and min().

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

253  {
254  ReadEnum(key, val, defVal, choices, nChoices, obsoletes, nObsoletes);
255  return (*val != wxNOT_FOUND);
256  }

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
inline

Definition at line 243 of file EffectAutomationParameters.h.

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

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

References entry, key, and Read().

Referenced by 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 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 286 of file EffectAutomationParameters.h.

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

References key.

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

Here is the caller graph for this function:

◆ Unescape()

wxString CommandParameters::Unescape ( wxString  val)
inline

Definition at line 329 of file EffectAutomationParameters.h.

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

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

References Internal, and 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 155 of file EffectAutomationParameters.h.

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

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 files:
CommandParameters::Escape
wxString Escape(wxString val)
Definition: EffectAutomationParameters.h:320
CommandParameters::SetParameters
bool SetParameters(const wxString &parms)
Definition: EffectAutomationParameters.h:286
str
#define str(a)
Definition: DBConnection.cpp:30
CommandParameters::ReadFloat
bool ReadFloat(const wxString &key, float *pf) const
Definition: EffectAutomationParameters.h:135
entry
static ProjectFileIORegistry::WriterEntry entry
Definition: ProjectSettings.cpp:197
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
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:165
CommandParameters::ObsoleteMap
std::pair< wxString, size_t > ObsoleteMap
Definition: EffectAutomationParameters.h:163
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:201
CommandParameters::NormalizeName
wxString NormalizeName(const wxString &name) const
Definition: EffectAutomationParameters.h:306
ExceptionType::Internal
@ Internal
Indicates internal failure from Audacity.
CommandParameters::Unescape
wxString Unescape(wxString val)
Definition: EffectAutomationParameters.h:329
CommandParameters::DoWriteString
virtual bool DoWriteString(const wxString &key, const wxString &szValue) override
Definition: EffectAutomationParameters.h:120