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 "../include/audacity/ComponentInterface.h"
15 
17 class WrappedType;
18 
19 class Shuttle /* not final */ {
20  public:
21  // constructors and destructors
22  Shuttle();
23  virtual ~Shuttle() {}
24 
25  public:
27  wxString mValueString;
28  // Even though virtual, mostly the transfer functions won't change
29  // for special kinds of archive.
30  virtual bool TransferBool( const wxString & Name, bool & bValue, const bool & bDefault );
31  virtual bool TransferFloat( const wxString & Name, float & fValue, const float &fDefault );
32  virtual bool TransferDouble( const wxString & Name, double & dValue, const double &dDefault );
33  virtual bool TransferInt( const wxString & Name, int & iValue, const int &iDefault );
34  virtual bool TransferInt( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
35  virtual bool TransferLongLong( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
36  virtual bool TransferString( const wxString & Name, wxString & strValue, const wxString &strDefault );
37  virtual bool TransferEnum( const wxString & Name, int & iValue,
38  const int nChoices, const wxString * pFirstStr);
39  virtual bool TransferWrappedType( const wxString & Name, WrappedType & W );
40  // We expect the ExchangeWithMaster function to change from one type of
41  // archive to another.
42  virtual bool ExchangeWithMaster(const wxString & Name);
43 };
44 
45 class ShuttleCli final : public Shuttle
46 {
47 public:
48  wxString mParams;
50  virtual ~ShuttleCli() {}
51  bool ExchangeWithMaster(const wxString & Name) override;
52 };
53 
54 class CommandParameters;
55 /**************************************************************************/
60 class AUDACITY_DLL_API ShuttleParams /* not final */
61 {
62 public:
63  wxString mParams;
66  ShuttleParams() { mpEap = NULL; pOptionalFlag = NULL; }
67  virtual ~ShuttleParams() {}
68  bool ShouldSet();
69  virtual ShuttleParams & Optional( bool & WXUNUSED(var) ){ pOptionalFlag = NULL;return *this;};
70  virtual ShuttleParams & OptionalY( bool & var ){ return Optional( var );};
71  virtual ShuttleParams & OptionalN( bool & var ){ return Optional( var );};
72  virtual void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false );
73  virtual void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
74  virtual void Define( int & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
75  virtual void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl=1.0f );
76  virtual void Define( double & 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 double vdefault, const double vmin, const double vmax, const double vscl=1.0f );
78  virtual void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin = {}, const wxString vmax = {}, const wxString vscl = {} );
79  virtual void DefineEnum( int &var, const wxChar * key, const int vdefault,
80  const EnumValueSymbol strings[], size_t nStrings );
81 };
82 
83 /**************************************************************************/
86 class AUDACITY_DLL_API ShuttleGetAutomation final : public ShuttleParams
87 {
88 public:
89  ShuttleParams & Optional( bool & var ) override;
90  void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
91  void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
92  void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
93  void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
94  void Define( double & 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 double vdefault, const double vmin, const double vmax, const double vscl ) override;
96  void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
97  void DefineEnum( int &var, const wxChar * key, const int vdefault,
98  const EnumValueSymbol strings[], size_t nStrings ) override;
99 };
100 
101 /**************************************************************************/
104 class AUDACITY_DLL_API ShuttleSetAutomation final : public ShuttleParams
105 {
106 public:
107  ShuttleSetAutomation(){ bWrite = false; bOK = false;};
108  bool bOK;
109  bool bWrite;
110  ShuttleParams & Optional( bool & var ) override;
111  bool CouldGet(const wxString &key);
112  void SetForValidating( CommandParameters * pEap){ mpEap=pEap; bOK=true;bWrite=false;};
113  void SetForWriting(CommandParameters * pEap){ mpEap=pEap;bOK=true;bWrite=true;};
114  void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
115  void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
116  void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
117  void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
118  void Define( double & 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 double vdefault, const double vmin, const double vmax, const double vscl ) override;
120  void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
121  void DefineEnum( int &var, const wxChar * key, const int vdefault,
122  const EnumValueSymbol strings[], size_t nStrings ) override;
123 };
124 
125 
126 /**************************************************************************/
129 class ShuttleDefaults final : public ShuttleParams
130 {
131 public:
132  wxString Result;
133  virtual ShuttleParams & Optional( bool & var )override{ var = true; pOptionalFlag = NULL;return *this;};
134  virtual ShuttleParams & OptionalY( bool & var )override{ var = true; pOptionalFlag = NULL;return *this;};
135  virtual ShuttleParams & OptionalN( bool & var )override{ var = false;pOptionalFlag = NULL;return *this;};
136 
137  void Define( bool & var, const wxChar * WXUNUSED(key), const bool vdefault,
138  const bool WXUNUSED(vmin), const bool WXUNUSED(vmax), const bool WXUNUSED(vscl) )
139  override { var = vdefault;};
140  void Define( int & var, const wxChar * WXUNUSED(key), const int vdefault,
141  const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl) )
142  override { var = vdefault;};
143  void Define( size_t & var, const wxChar * WXUNUSED(key), const int vdefault,
144  const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl) )
145  override{ var = vdefault;};
146  void Define( float & var, const wxChar * WXUNUSED(key), const float vdefault,
147  const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl) )
148  override { var = vdefault;};
149  void Define( double & var, const wxChar * WXUNUSED(key), const float vdefault,
150  const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl) )
151  override { var = vdefault;};
152  void Define( double & var, const wxChar * WXUNUSED(key), const double vdefault,
153  const double WXUNUSED(vmin), const double WXUNUSED(vmax), const double WXUNUSED(vscl) )
154  override { var = vdefault;};
155  void Define( wxString &var, const wxChar * WXUNUSED(key), const wxString vdefault,
156  const wxString WXUNUSED(vmin), const wxString WXUNUSED(vmax), const wxString WXUNUSED(vscl) )
157  override { var = vdefault;};
158  void DefineEnum( int &var, const wxChar * WXUNUSED(key), const int vdefault,
159  const EnumValueSymbol WXUNUSED(strings) [], size_t WXUNUSED( nStrings ) )
160  override { var = vdefault;};
161 };
162 
163 
164 
165 
166 
167 
168 #define SHUTTLE_PARAM( var, name ) \
169  Define( var, KEY_ ## name, DEF_ ## name, MIN_ ## name, MAX_ ## name, SCL_ ## name )
170 
171 #define SHUTTLE_ENUM_PARAM( var, name, strings, nStrings ) \
172  DefineEnum( var, KEY_ ## name, DEF_ ## name, strings, nStrings )
173 
174 #endif
ShuttleSetAutomation
Shuttle that sets parameters to a value (from a string)
Definition: Shuttle.h:105
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:112
ShuttleDefaults::Result
wxString Result
Definition: Shuttle.h:132
Optional
Like a smart pointer, allows for object to not exist (nullptr)
Definition: MemoryX.h:210
Shuttle::TransferFloat
virtual bool TransferFloat(const wxString &Name, float &fValue, const float &fDefault)
Definition: Shuttle.cpp:97
ShuttleParams::ShuttleParams
ShuttleParams()
Definition: Shuttle.h:66
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:143
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:46
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:152
ShuttleSetAutomation::ShuttleSetAutomation
ShuttleSetAutomation()
Definition: Shuttle.h:107
ShuttleDefaults
Shuttle that sets parameters to their default values.
Definition: Shuttle.h:130
ShuttleCli::~ShuttleCli
virtual ~ShuttleCli()
Definition: Shuttle.h:50
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:61
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:134
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
ShuttleParams::OptionalN
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:71
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:149
ShuttleParams::mParams
wxString mParams
Definition: Shuttle.h:63
ShuttleCli::mParams
wxString mParams
Definition: Shuttle.h:48
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:140
ShuttleParams::mpEap
CommandParameters * mpEap
Definition: Shuttle.h:65
ShuttleDefaults::Optional
virtual ShuttleParams & Optional(bool &var) override
Definition: Shuttle.h:133
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:155
ShuttleCli::ShuttleCli
ShuttleCli()
Definition: Shuttle.h:49
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:87
Shuttle::~Shuttle
virtual ~Shuttle()
Definition: Shuttle.h:23
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:67
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:70
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:146
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:19
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:196
ShuttleDefaults::OptionalN
virtual ShuttleParams & OptionalN(bool &var) override
Definition: Shuttle.h:135
Shuttle::TransferInt
virtual bool TransferInt(const wxString &Name, int &iValue, const int &iDefault)
Definition: Shuttle.cpp:136
Shuttle::mValueString
wxString mValueString
Definition: Shuttle.h:27
Shuttle::mbStoreInClient
bool mbStoreInClient
Definition: Shuttle.h:26
ShuttleSetAutomation::bWrite
bool bWrite
Definition: Shuttle.h:109
ShuttleSetAutomation::bOK
bool bOK
Definition: Shuttle.h:107
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:137
ShuttleSetAutomation::SetForWriting
void SetForWriting(CommandParameters *pEap)
Definition: Shuttle.h:113
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:158
ShuttleParams::Optional
virtual ShuttleParams & Optional(bool &WXUNUSED(var))
Definition: Shuttle.h:69
ShuttleParams::pOptionalFlag
bool * pOptionalFlag
Definition: Shuttle.h:64