Audacity 3.2.0
ShuttleAutomation.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file ShuttleAutomation.cpp
6
7 Paul Licameli split from Shuttle.cpp
8
9**********************************************************************/
10
11#include "ShuttleAutomation.h"
13
15
16// ShuttleGetAutomation gets from the shuttle into typically a string.
18 pOptionalFlag = &var;
19 return *this;
20};
21
22void ShuttleGetAutomation::Define(bool var, const wxChar * key,
23 bool, bool, bool, bool)
24{
25 if( !ShouldSet() ) return;
26 mpEap->Write(key, var);
27}
28
29void ShuttleGetAutomation::Define(int var, const wxChar * key,
30 int, int, int, int)
31{
32 if( !ShouldSet() ) return;
33 mpEap->Write(key, var);
34}
35
36void ShuttleGetAutomation::Define(size_t var, const wxChar * key,
37 int, int, int, int)
38{
39 if( !ShouldSet() ) return;
40 mpEap->Write(key, (int) var);
41}
42
43void ShuttleGetAutomation::Define(double var, const wxChar * key,
44 float, float, float, float)
45{
46 if( !ShouldSet() ) return;
47 mpEap->WriteFloat(key, var);
48}
49
50void ShuttleGetAutomation::Define(float var, const wxChar * key,
51 float, float, float, float)
52{
53 if( !ShouldSet() ) return;
54 mpEap->WriteFloat(key, var);
55}
56
57void ShuttleGetAutomation::Define(double var, const wxChar * key,
58 double, double, double, double)
59{
60 if( !ShouldSet() ) return;
61 mpEap->Write(key, var);
62}
63
64
65void ShuttleGetAutomation::Define(const wxString &var, const wxChar * key,
66 wxString, wxString, wxString, wxString)
67{
68 if( !ShouldSet() ) return;
69 mpEap->Write(key, var);
70}
71
72
73void ShuttleGetAutomation::DefineEnum(int var, const wxChar * key,
74 int, const EnumValueSymbol strings[], size_t)
75{
76 if( !ShouldSet() ) return;
77 mpEap->Write(key, strings[var].Internal());
78}
79
80
81
83 pOptionalFlag = &var;
84 return *this;
85};
86
87// Tests for parameter being optional.
88// Prepares for next parameter by clearing the pointer.
89// If the parameter is optional, finds out if it was actually provided.
90// i.e. could it be got from a macro?
91// The result goes into the flag variable, so we typically ignore the result.
92bool ShuttleSetAutomation::CouldGet( const wxString &key ){
93 // Not optional? Can get as we will get the default, at worst.
94 if( !pOptionalFlag )
95 return true;
96 bool result = mpEap->HasEntry( key );
97 *pOptionalFlag = result;
98 pOptionalFlag = NULL;
99 return result;
100}
101
102void ShuttleSetAutomation::Define( bool & var, const wxChar * key, const bool vdefault, const bool vmin, const bool vmax, const bool vscl )
103{
104 CouldGet( key );
105 if( !bOK )
106 return;
107 // Use of temp in this and related functions is to handle the case of
108 // only committing values if all values pass verification.
109 bool temp =var;
110 bOK = mpEap->ReadAndVerify(key, &temp, vdefault);
111 if( bWrite && bOK)
112 var = temp;
113}
114
115void ShuttleSetAutomation::Define( int & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
116{
117 CouldGet( key );
118 if( !bOK )
119 return;
120 int temp =var;
121 bOK = mpEap->ReadAndVerify(key, &temp, vdefault, vmin, vmax);
122 if( bWrite && bOK)
123 var = temp;
124}
125
126void ShuttleSetAutomation::Define( size_t & var, const wxChar * key, const int vdefault, const int vmin, const int vmax, const int vscl )
127{
128 CouldGet( key );
129 if( !bOK )
130 return;
131 int temp = var;
132 bOK = mpEap->ReadAndVerify(key, &temp, vdefault, vmin, vmax);
133 if( bWrite && bOK )
134 var = temp;
135}
136
137void ShuttleSetAutomation::Define( float & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
138{
139 CouldGet( key );
140 if( !bOK )
141 return;
142 float temp = var;
143 bOK = mpEap->ReadAndVerify(key, &temp, vdefault, vmin, vmax);
144 if( bWrite && bOK )
145 var = temp;
146}
147
148
149void ShuttleSetAutomation::Define( double & var, const wxChar * key, const float vdefault, const float vmin, const float vmax, const float vscl )
150{
151 CouldGet( key );
152 if( !bOK )
153 return;
154 double temp = var;
155 bOK = mpEap->ReadAndVerify(key, &temp, vdefault, vmin, vmax);
156 if( bWrite && bOK)
157 var = temp;
158}
159
160void ShuttleSetAutomation::Define( double & var, const wxChar * key, const double vdefault, const double vmin, const double vmax, const double vscl )
161{
162 CouldGet( key );
163 if( !bOK )
164 return;
165 double temp = var;
166 bOK = mpEap->ReadAndVerify(key, &temp, vdefault, vmin, vmax);
167 if( bWrite && bOK)
168 var = temp;
169}
170
171
172void ShuttleSetAutomation::Define( wxString &var, const wxChar * key, const wxString vdefault, const wxString vmin, const wxString vmax, const wxString vscl )
173{
174 CouldGet( key );
175 if( !bOK )
176 return;
177 wxString temp = var;
178 bOK = mpEap->ReadAndVerify(key, &temp, vdefault);
179 if( bWrite && bOK )
180 var = temp;
181}
182
183
184void ShuttleSetAutomation::DefineEnum( int &var, const wxChar * key, const int vdefault, const EnumValueSymbol strings[], size_t nStrings )
185{
186 CouldGet( key );
187 if( !bOK )
188 return;
189 int temp = var;
190 bOK = mpEap->ReadAndVerify(key, &temp, vdefault, strings, nStrings);
191 if( bWrite && bOK)
192 var = temp;
193}
194
196{
197 var = true;
198 pOptionalFlag = nullptr;
199 return *this;
200}
201
203{
204 var = true;
205 pOptionalFlag = nullptr;
206 return *this;
207}
208
210{
211 var = false;
212 pOptionalFlag = nullptr;
213 return *this;
214}
215
216void ShuttleDefaults::Define(bool & var, const wxChar *, bool vdefault,
217 bool, bool, bool)
218{
219 var = vdefault;
220}
221
222void ShuttleDefaults::Define(int & var, const wxChar *, int vdefault,
223 int, int, int)
224{
225 var = vdefault;
226}
227
228void ShuttleDefaults::Define(size_t & var, const wxChar *, int vdefault,
229 int, int, int)
230{
231 var = vdefault;
232}
233
234void ShuttleDefaults::Define(float & var, const wxChar *, float vdefault,
235 float, float, float)
236{
237 var = vdefault;
238}
239
240void ShuttleDefaults::Define(double & var, const wxChar *, float vdefault,
241 float, float, float)
242{
243 var = vdefault;
244}
245
246void ShuttleDefaults::Define(double & var, const wxChar *, double vdefault,
247 double, double, double)
248{
249 var = vdefault;
250}
251
252void ShuttleDefaults::Define(wxString &var, const wxChar *, wxString vdefault,
253 wxString, wxString, wxString)
254{
255 var = vdefault;
256}
257
258void ShuttleDefaults::DefineEnum(int &var, const wxChar *, int vdefault,
259 const EnumValueSymbol [], size_t)
260{
261 var = vdefault;
262}
@ Internal
Indicates internal failure from Audacity.
static const AudacityProject::AttachedObjects::RegisteredFactory key
bool ReadAndVerify(const wxString &key, float *val, float defVal, float min, float max) const
virtual bool HasEntry(const wxString &strName) const override
bool WriteFloat(const wxString &key, float f)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
virtual ~EffectParameterMethods()
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
CommandParameters * mpEap
std::conditional_t< Const, const bool, bool > * pOptionalFlag
void Define(bool &var, const wxChar *key, bool vdefault, bool vmin, bool vmax, bool vscl) override
SettingsVisitor & Optional(bool &var) override
void DefineEnum(int &var, const wxChar *key, int vdefault, const EnumValueSymbol strings[], size_t nStrings) override
SettingsVisitor & OptionalY(bool &var) override
SettingsVisitor & OptionalN(bool &var) override
void Define(bool var, const wxChar *key, bool vdefault, bool vmin, bool vmax, bool vscl) override
void DefineEnum(int var, const wxChar *key, int vdefault, const EnumValueSymbol strings[], size_t nStrings) override
ConstSettingsVisitor & Optional(const bool &var) override
void DefineEnum(int &var, const wxChar *key, int vdefault, const EnumValueSymbol strings[], size_t nStrings) override
void Define(bool &var, const wxChar *key, bool vdefault, bool vmin, bool vmax, bool vscl) override
bool CouldGet(const wxString &key)
SettingsVisitor & Optional(bool &var) override