forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShuttle.h
174 lines (150 loc) · 9.65 KB
/
Shuttle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**********************************************************************
Sneedacity: A Digital Audio Editor
Shuttle.h
James Crook
**********************************************************************/
#ifndef __SNEEDACITY_SHUTTLE__
#define __SNEEDACITY_SHUTTLE__
#include "../include/sneedacity/ComponentInterface.h"
class ComponentInterfaceSymbol;
class WrappedType;
class Shuttle /* not final */ {
public:
// constructors and destructors
Shuttle();
virtual ~Shuttle() {}
public:
bool mbStoreInClient;
wxString mValueString;
// Even though virtual, mostly the transfer functions won't change
// for special kinds of archive.
virtual bool TransferBool( const wxString & Name, bool & bValue, const bool & bDefault );
virtual bool TransferFloat( const wxString & Name, float & fValue, const float &fDefault );
virtual bool TransferDouble( const wxString & Name, double & dValue, const double &dDefault );
virtual bool TransferInt( const wxString & Name, int & iValue, const int &iDefault );
virtual bool TransferInt( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
virtual bool TransferLongLong( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
virtual bool TransferString( const wxString & Name, wxString & strValue, const wxString &strDefault );
virtual bool TransferEnum( const wxString & Name, int & iValue,
const int nChoices, const wxString * pFirstStr);
virtual bool TransferWrappedType( const wxString & Name, WrappedType & W );
// We expect the ExchangeWithMaster function to change from one type of
// archive to another.
virtual bool ExchangeWithMaster(const wxString & Name);
};
class ShuttleCli final : public Shuttle
{
public:
wxString mParams;
ShuttleCli() {}
virtual ~ShuttleCli() {}
bool ExchangeWithMaster(const wxString & Name) override;
};
class CommandParameters;
/**************************************************************************//**
\brief Shuttle that deals with parameters. This is a base class with lots of
virtual functions that do nothing by default.
Unrelated to class Shuttle.
********************************************************************************/
class SNEEDACITY_DLL_API ShuttleParams /* not final */
{
public:
wxString mParams;
bool *pOptionalFlag;
CommandParameters * mpEap;
ShuttleParams() { mpEap = NULL; pOptionalFlag = NULL; }
virtual ~ShuttleParams() {}
bool ShouldSet();
virtual ShuttleParams & Optional( bool & WXUNUSED(var) ){ pOptionalFlag = NULL;return *this;};
virtual ShuttleParams & OptionalY( bool & var ){ return Optional( var );};
virtual ShuttleParams & OptionalN( bool & var ){ return Optional( var );};
virtual void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false );
virtual void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
virtual void Define( int & var, const wxChar * key, const int vdefault, const int vmin=0, const int vmax=100000, const int vscl=1 );
virtual void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl=1.0f );
virtual void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl=1.0f );
virtual void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl=1.0f );
virtual void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin = {}, const wxString vmax = {}, const wxString vscl = {} );
virtual void DefineEnum( int &var, const wxChar * key, const int vdefault,
const EnumValueSymbol strings[], size_t nStrings );
};
/**************************************************************************//**
\brief Shuttle that gets parameter values into a string.
********************************************************************************/
class SNEEDACITY_DLL_API ShuttleGetAutomation final : public ShuttleParams
{
public:
ShuttleParams & Optional( bool & var ) override;
void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl ) override;
void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
void DefineEnum( int &var, const wxChar * key, const int vdefault,
const EnumValueSymbol strings[], size_t nStrings ) override;
};
/**************************************************************************//**
\brief Shuttle that sets parameters to a value (from a string)
********************************************************************************/
class SNEEDACITY_DLL_API ShuttleSetAutomation final : public ShuttleParams
{
public:
ShuttleSetAutomation(){ bWrite = false; bOK = false;};
bool bOK;
bool bWrite;
ShuttleParams & Optional( bool & var ) override;
bool CouldGet(const wxString &key);
void SetForValidating( CommandParameters * pEap){ mpEap=pEap; bOK=true;bWrite=false;};
void SetForWriting(CommandParameters * pEap){ mpEap=pEap;bOK=true;bWrite=true;};
void Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl ) override;
void Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
void Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl ) override;
void Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
void Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl ) override;
void Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl ) override;
void Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl ) override;
void DefineEnum( int &var, const wxChar * key, const int vdefault,
const EnumValueSymbol strings[], size_t nStrings ) override;
};
/**************************************************************************//**
\brief Shuttle that sets parameters to their default values.
********************************************************************************/
class ShuttleDefaults final : public ShuttleParams
{
public:
wxString Result;
virtual ShuttleParams & Optional( bool & var )override{ var = true; pOptionalFlag = NULL;return *this;};
virtual ShuttleParams & OptionalY( bool & var )override{ var = true; pOptionalFlag = NULL;return *this;};
virtual ShuttleParams & OptionalN( bool & var )override{ var = false;pOptionalFlag = NULL;return *this;};
void Define( bool & var, const wxChar * WXUNUSED(key), const bool vdefault,
const bool WXUNUSED(vmin), const bool WXUNUSED(vmax), const bool WXUNUSED(vscl) )
override { var = vdefault;};
void Define( int & var, const wxChar * WXUNUSED(key), const int vdefault,
const int WXUNUSED(vmin), const int WXUNUSED(vmax), const int WXUNUSED(vscl) )
override { var = vdefault;};
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{ var = vdefault;};
void Define( float & var, const wxChar * WXUNUSED(key), const float vdefault,
const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl) )
override { var = vdefault;};
void Define( double & var, const wxChar * WXUNUSED(key), const float vdefault,
const float WXUNUSED(vmin), const float WXUNUSED(vmax), const float WXUNUSED(vscl) )
override { var = vdefault;};
void Define( double & var, const wxChar * WXUNUSED(key), const double vdefault,
const double WXUNUSED(vmin), const double WXUNUSED(vmax), const double WXUNUSED(vscl) )
override { var = vdefault;};
void Define( wxString &var, const wxChar * WXUNUSED(key), const wxString vdefault,
const wxString WXUNUSED(vmin), const wxString WXUNUSED(vmax), const wxString WXUNUSED(vscl) )
override { var = vdefault;};
void DefineEnum( int &var, const wxChar * WXUNUSED(key), const int vdefault,
const EnumValueSymbol WXUNUSED(strings) [], size_t WXUNUSED( nStrings ) )
override { var = vdefault;};
};
#define SHUTTLE_PARAM( var, name ) \
Define( var, KEY_ ## name, DEF_ ## name, MIN_ ## name, MAX_ ## name, SCL_ ## name )
#define SHUTTLE_ENUM_PARAM( var, name, strings, nStrings ) \
DefineEnum( var, KEY_ ## name, DEF_ ## name, strings, nStrings )
#endif