Audacity  3.0.3
Shuttle.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Shuttle.h
6 
7  James Crook
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_SHUTTLE__
12 #define __AUDACITY_SHUTTLE__
13 
14 #include "ComponentInterface.h"
16 
18 class WrappedType;
19 
20 class Shuttle /* not final */ {
21  public:
22  // constructors and destructors
23  Shuttle();
24  virtual ~Shuttle() {}
25 
26  public:
28  wxString mValueString;
29  // Even though virtual, mostly the transfer functions won't change
30  // for special kinds of archive.
31  virtual bool TransferBool( const wxString & Name, bool & bValue, const bool & bDefault );
32  virtual bool TransferFloat( const wxString & Name, float & fValue, const float &fDefault );
33  virtual bool TransferDouble( const wxString & Name, double & dValue, const double &dDefault );
34  virtual bool TransferInt( const wxString & Name, int & iValue, const int &iDefault );
35  virtual bool TransferInt( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
36  virtual bool TransferLongLong( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
37  virtual bool TransferString( const wxString & Name, wxString & strValue, const wxString &strDefault );
38  virtual bool TransferEnum( const wxString & Name, int & iValue,
39  const int nChoices, const wxString * pFirstStr);
40  virtual bool TransferWrappedType( const wxString & Name, WrappedType & W );
41  // We expect the ExchangeWithMaster function to change from one type of
42  // archive to another.
43  virtual bool ExchangeWithMaster(const wxString & Name);
44 };
45 
46 class ShuttleCli final : public Shuttle
47 {
48 public:
49  wxString mParams;
51  virtual ~ShuttleCli() {}
52  bool ExchangeWithMaster(const wxString & Name) override;
53 };
54 
55 class CommandParameters;
56 /**************************************************************************/
61 class AUDACITY_DLL_API ShuttleParams /* not final */
62 {
63 public:
64  wxString mParams;
67  ShuttleParams() { mpEap = NULL; pOptionalFlag = NULL; }
68  virtual ~ShuttleParams() {}
69  bool ShouldSet();
70  virtual ShuttleParams & Optional( bool & WXUNUSED(var) ){ pOptionalFlag = NULL;return *this;};
71  virtual ShuttleParams & OptionalY( bool & var ){ return Optional( var );};
72  virtual ShuttleParams & OptionalN( bool & var ){ return Optional( var );};
73  virtual void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false );
74  virtual void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
75  virtual void Define( int & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
76  virtual void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl=1.0f );
77  virtual void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl=1.0f );
78  virtual void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl=1.0f );
79  virtual void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin = {}, const wxString vmax = {}, const wxString vscl = {} );
80  virtual void DefineEnum( int &var, const wxChar * key, const int vdefault,
81  const EnumValueSymbol strings[], size_t nStrings );
82 };
83 
84 /**************************************************************************/
87 class AUDACITY_DLL_API ShuttleGetAutomation final : public ShuttleParams
88 {
89 public:
90  ShuttleParams & Optional( bool & var ) override;
91  void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
92  void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
93  void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
94  void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
95  void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
96  void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl ) override;
97  void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
98  void DefineEnum( int &var, const wxChar * key, const int vdefault,
99  const EnumValueSymbol strings[], size_t nStrings ) override;
100 };
101 
102 /**************************************************************************/
105 class AUDACITY_DLL_API ShuttleSetAutomation final : public ShuttleParams
106 {
107 public:
108  ShuttleSetAutomation(){ bWrite = false; bOK = false;};
109  bool bOK;
110  bool bWrite;
111  ShuttleParams & Optional( bool & var ) override;
112  bool CouldGet(const wxString &key);
113  void SetForValidating( CommandParameters * pEap){ mpEap=pEap; bOK=true;bWrite=false;};
114  void SetForWriting(CommandParameters * pEap){ mpEap=pEap;bOK=true;bWrite=true;};
115  void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
116  void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
117  void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
118  void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
119  void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
120  void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl ) override;
121  void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
122  void DefineEnum( int &var, const wxChar * key, const int vdefault,
123  const EnumValueSymbol strings[], size_t nStrings ) override;
124 };
125 
126 
127 /**************************************************************************/
130 class ShuttleDefaults final : public ShuttleParams
131 {
132 public:
133  wxString Result;
134  virtual ShuttleParams & Optional( bool & var )override{ var = true; pOptionalFlag = NULL;return *this;};
135  virtual ShuttleParams & OptionalY( bool & var )override{ var = true; pOptionalFlag = NULL;return *this;};
136  virtual ShuttleParams & OptionalN( bool & var )override{ var = false;pOptionalFlag = NULL;return *this;};
137 
138  void Define( bool & var, const wxChar * WXUNUSED(key), const bool vdefault,
139  const bool WXUNUSED(vmin), const bool WXUNUSED(vmax), const bool WXUNUSED(vscl) )
140  override { var = vdefault;};
141  void Define( int & var, const wxChar * WXUNUSED(key), const int vdefault,
142  const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl) )
143  override { var = vdefault;};
144  void Define( size_t & var, const wxChar * WXUNUSED(key), const int vdefault,
145  const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl) )
146  override{ var = vdefault;};
147  void Define( float & var, const wxChar * WXUNUSED(key), const float vdefault,
148  const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl) )
149  override { var = vdefault;};
150  void Define( double & var, const wxChar * WXUNUSED(key), const float vdefault,
151  const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl) )
152  override { var = vdefault;};
153  void Define( double & var, const wxChar * WXUNUSED(key), const double vdefault,
154  const double WXUNUSED(vmin), const double WXUNUSED(vmax), const double WXUNUSED(vscl) )
155  override { var = vdefault;};
156  void Define( wxString &var, const wxChar * WXUNUSED(key), const wxString vdefault,
157  const wxString WXUNUSED(vmin), const wxString WXUNUSED(vmax), const wxString WXUNUSED(vscl) )
158  override { var = vdefault;};
159  void DefineEnum( int &var, const wxChar * WXUNUSED(key), const int vdefault,
160  const EnumValueSymbol WXUNUSED(strings) [], size_t WXUNUSED( nStrings ) )
161  override { var = vdefault;};
162 };
163 
164 
165 
166 
167 
168 
169 #define SHUTTLE_PARAM( var, name ) \
170  Define( var, KEY_ ## name, DEF_ ## name, MIN_ ## name, MAX_ ## name, SCL_ ## name )
171 
172 #define SHUTTLE_ENUM_PARAM( var, name, strings, nStrings ) \
173  DefineEnum( var, KEY_ ## name, DEF_ ## name, strings, nStrings )
174 
175 #endif
ShuttleSetAutomation
Shuttle that sets parameters to a value (from a string)
Definition: Shuttle.h:106
CommandParameters
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
Definition: EffectAutomationParameters.h:67
ShuttleSetAutomation::SetForValidating
void SetForValidating(CommandParameters *pEap)
Definition: Shuttle.h:113
ShuttleDefaults::Result
wxString Result
Definition: Shuttle.h:133
Optional
Like a smart pointer, allows for object to not exist (nullptr)
Definition: MemoryX.h:144
Shuttle::TransferFloat
virtual bool TransferFloat(const wxString &Name, float &fValue, const float &fDefault)
Definition: Shuttle.cpp:97
ShuttleParams::ShuttleParams
ShuttleParams()
Definition: Shuttle.h:67
Shuttle::TransferDouble
virtual bool TransferDouble(const wxString &Name, double &dValue, const double &dDefault)
Definition: Shuttle.cpp:116
Shuttle::TransferBool
virtual bool TransferBool(const wxString &Name, bool &bValue, const bool &bDefault)
Definition: Shuttle.cpp:78
ShuttleDefaults::Define
void Define(size_t &var, const wxChar *WXUNUSED(key), const int vdefault, const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl)) override
Definition: Shuttle.h:144
Shuttle::TransferEnum
virtual bool TransferEnum(const wxString &Name, int &iValue, const int nChoices, const wxString *pFirstStr)
Definition: Shuttle.cpp:180
ShuttleCli
Derived from Shuttle, this class exchanges string parameters with a binary representation.
Definition: Shuttle.h:47
ShuttleDefaults::Define
void Define(double &var, const wxChar *WXUNUSED(key), const double vdefault, const double WXUNUSED(vmin), const double WXUNUSED(vmax), const double WXUNUSED(vscl)) override
Definition: Shuttle.h:153
ShuttleSetAutomation::ShuttleSetAutomation
ShuttleSetAutomation()
Definition: Shuttle.h:108
ShuttleDefaults
Shuttle that sets parameters to their default values.
Definition: Shuttle.h:131
ShuttleCli::~ShuttleCli
virtual ~ShuttleCli()
Definition: Shuttle.h:51
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
ComponentInterfaceSymbol.h
Shuttle::TransferWrappedType
virtual bool TransferWrappedType(const wxString &Name, WrappedType &W)
Definition: Shuttle.cpp:240
ShuttleDefaults::OptionalY
virtual ShuttleParams & OptionalY(bool &var) override
Definition: Shuttle.h:135
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ShuttleParams::OptionalN
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:72
ShuttleDefaults::Define
void Define(double &var, const wxChar *WXUNUSED(key), const float vdefault, const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl)) override
Definition: Shuttle.h:150
ShuttleParams::mParams
wxString mParams
Definition: Shuttle.h:64
ShuttleCli::mParams
wxString mParams
Definition: Shuttle.h:49
ShuttleDefaults::Define
void Define(int &var, const wxChar *WXUNUSED(key), const int vdefault, const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl)) override
Definition: Shuttle.h:141
ComponentInterface.h
ShuttleParams::mpEap
CommandParameters * mpEap
Definition: Shuttle.h:66
ShuttleDefaults::Optional
virtual ShuttleParams & Optional(bool &var) override
Definition: Shuttle.h:134
ShuttleDefaults::Define
void Define(wxString &var, const wxChar *WXUNUSED(key), const wxString vdefault, const wxString WXUNUSED(vmin), const wxString WXUNUSED(vmax), const wxString WXUNUSED(vscl)) override
Definition: Shuttle.h:156
ShuttleCli::ShuttleCli
ShuttleCli()
Definition: Shuttle.h:50
Shuttle::TransferLongLong
virtual bool TransferLongLong(const wxString &Name, wxLongLong_t &iValue, const wxLongLong_t &iDefault)
Definition: Shuttle.cpp:160
ShuttleGetAutomation
Shuttle that gets parameter values into a string.
Definition: Shuttle.h:88
Shuttle::~Shuttle
virtual ~Shuttle()
Definition: Shuttle.h:24
WrappedType
Used in type conversions, this wrapper for ints, strings, doubles and enums provides conversions betw...
Definition: WrappedType.h:31
ShuttleParams::~ShuttleParams
virtual ~ShuttleParams()
Definition: Shuttle.h:68
ShuttleParams::DefineEnum
virtual void DefineEnum(int &var, const wxChar *key, const int vdefault, const EnumValueSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:339
ShuttleParams::OptionalY
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:71
Shuttle::TransferString
virtual bool TransferString(const wxString &Name, wxString &strValue, const wxString &strDefault)
Definition: Shuttle.cpp:221
Shuttle::ExchangeWithMaster
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:258
ShuttleDefaults::Define
void Define(float &var, const wxChar *WXUNUSED(key), const float vdefault, const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl)) override
Definition: Shuttle.h:147
ShuttleCli::ExchangeWithMaster
bool ExchangeWithMaster(const wxString &Name) override
Definition: Shuttle.cpp:269
Shuttle
Moves data from one place to another, converting it as required.
Definition: Shuttle.h:20
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
ShuttleDefaults::OptionalN
virtual ShuttleParams & OptionalN(bool &var) override
Definition: Shuttle.h:136
Shuttle::TransferInt
virtual bool TransferInt(const wxString &Name, int &iValue, const int &iDefault)
Definition: Shuttle.cpp:136
Shuttle::mValueString
wxString mValueString
Definition: Shuttle.h:28
Shuttle::mbStoreInClient
bool mbStoreInClient
Definition: Shuttle.h:27
ShuttleSetAutomation::bWrite
bool bWrite
Definition: Shuttle.h:110
ShuttleSetAutomation::bOK
bool bOK
Definition: Shuttle.h:108
Shuttle::Shuttle
Shuttle()
Definition: Shuttle.cpp:74
ShuttleParams::Define
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:332
ShuttleDefaults::Define
void Define(bool &var, const wxChar *WXUNUSED(key), const bool vdefault, const bool WXUNUSED(vmin), const bool WXUNUSED(vmax), const bool WXUNUSED(vscl)) override
Definition: Shuttle.h:138
ShuttleSetAutomation::SetForWriting
void SetForWriting(CommandParameters *pEap)
Definition: Shuttle.h:114
ShuttleDefaults::DefineEnum
void DefineEnum(int &var, const wxChar *WXUNUSED(key), const int vdefault, const EnumValueSymbol WXUNUSED(strings)[], size_t WXUNUSED(nStrings)) override
Definition: Shuttle.h:159
ShuttleParams::Optional
virtual ShuttleParams & Optional(bool &WXUNUSED(var))
Definition: Shuttle.h:70
ShuttleParams::pOptionalFlag
bool * pOptionalFlag
Definition: Shuttle.h:65