Audacity 3.2.0
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 <type_traits>
15
17
19class WrappedType;
20
21template<
22 typename Structure,
23 typename Member,
24 typename Type,
25 typename Value = Type
27 Member Structure::*const mem{};
28 const wxChar *const key{};
29 const Type def{};
30 const Type min{};
31 const Type max{};
32 const Type scale{};
33};
34
35// Deduction guides
36// Type of def chooses the parameter type; others just need to be convertible
37template<typename Structure, typename Member,
38 typename Type, typename... Args>
39EffectParameter(Member Structure::*const mem,
40 const wxChar *key, const Type &def, Args...)
42// Deduce string type from string literal
43template<typename Structure, typename Member,
44 typename Char, size_t N, typename... Args>
45EffectParameter(Member Structure::*const mem,
46 const wxChar *key, const Char (&def)[N], Args...)
48
49template<typename Structure, typename Member>
50struct EnumParameter : EffectParameter<Structure, Member, int>
51{
52 constexpr EnumParameter(Member Structure::*const mem,
53 const wxChar *key, int def, int min, int max, int scale,
54 const EnumValueSymbol *symbols_, size_t nSymbols_ )
55 : EffectParameter<Structure, Member, int>{
56 mem, key, def, min, max, scale }
57 , symbols{ symbols_ }
58 , nSymbols{ nSymbols_ }
59 {}
60
62 const size_t nSymbols;
63};
64
65// Deduction guide
66template<typename Structure, typename Member, typename... Args>
67EnumParameter(Member Structure::*const mem, Args...)
69
70class Shuttle /* not final */ {
71 public:
72 // constructors and destructors
73 Shuttle();
74 virtual ~Shuttle() {}
75
76 public:
78 wxString mValueString;
79 // Even though virtual, mostly the transfer functions won't change
80 // for special kinds of archive.
81 virtual bool TransferBool( const wxString & Name, bool & bValue, const bool & bDefault );
82 virtual bool TransferFloat( const wxString & Name, float & fValue, const float &fDefault );
83 virtual bool TransferDouble( const wxString & Name, double & dValue, const double &dDefault );
84 virtual bool TransferInt( const wxString & Name, int & iValue, const int &iDefault );
85 virtual bool TransferInt( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
86 virtual bool TransferLongLong( const wxString & Name, wxLongLong_t & iValue, const wxLongLong_t &iDefault );
87 virtual bool TransferString( const wxString & Name, wxString & strValue, const wxString &strDefault );
88 virtual bool TransferEnum( const wxString & Name, int & iValue,
89 const int nChoices, const wxString * pFirstStr);
90 virtual bool TransferWrappedType( const wxString & Name, WrappedType & W );
91 // We expect the ExchangeWithMaster function to change from one type of
92 // archive to another.
93 virtual bool ExchangeWithMaster(const wxString & Name);
94};
95
96class ShuttleCli final : public Shuttle
97{
98public:
99 wxString mParams;
101 virtual ~ShuttleCli() {}
102 bool ExchangeWithMaster(const wxString & Name) override;
103};
104
106/**************************************************************************/
113template<bool Const>
114class SettingsVisitorBase /* not final */
115{
116public:
117 // By-value argument for const visitor, otherwise reference
118 template<typename T> using Ref = std::conditional_t<Const, const T&, T&>;
119 // const-reference argument for const visitor, otherwise reference
120 template<typename T> using Arg = std::conditional_t<Const, T, T&>;
121
122 wxString mParams;
123 std::conditional_t<Const, const bool, bool> *pOptionalFlag{};
125
128
129 bool ShouldSet();
130 virtual SettingsVisitorBase &Optional( Ref<bool> var );
133 virtual void Define( Arg<bool> var, const wxChar * key, bool vdefault,
134 bool vmin = false, bool vmax = false, bool vscl = false );
135 virtual void Define( Arg<size_t> var, const wxChar * key, int vdefault,
136 int vmin = 0, int vmax = 100000, int vscl = 1 );
137 virtual void Define( Arg<int> var, const wxChar * key, int vdefault,
138 int vmin = 0, int vmax = 100000, int vscl = 1 );
139 virtual void Define( Arg<float> var, const wxChar * key, float vdefault,
140 float vmin, float vmax, float vscl = 1.0f );
141 virtual void Define( Arg<double> var, const wxChar * key, float vdefault,
142 float vmin, float vmax, float vscl = 1.0f );
143 virtual void Define( Arg<double> var, const wxChar * key, double vdefault,
144 double vmin, double vmax, double vscl = 1.0f );
145 virtual void Define( Ref<wxString> var, const wxChar * key,
146 wxString vdefault,
147 wxString vmin = {}, wxString vmax = {},
148 wxString vscl = {} );
149 virtual void DefineEnum( Arg<int> var, const wxChar * key, int vdefault,
150 const EnumValueSymbol strings[], size_t nStrings );
151};
152
153extern template class AUDACITY_DLL_API SettingsVisitorBase<false>;
154extern template class AUDACITY_DLL_API SettingsVisitorBase<true>;
155
158
159#endif
static const AudacityProject::AttachedObjects::RegisteredFactory key
EnumParameter(Member Structure::*const mem, Args...) -> EnumParameter< Structure, Member >
EffectParameter(Member Structure::*const mem, const wxChar *key, const Type &def, Args...) -> EffectParameter< Structure, Member, Type >
#define W(N, I)
Definition: ToChars.cpp:60
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Definition: Shuttle.h:115
virtual void Define(Arg< bool > var, const wxChar *key, bool vdefault, bool vmin=false, bool vmax=false, bool vscl=false)
Definition: Shuttle.cpp:355
virtual SettingsVisitorBase & OptionalY(Ref< bool > var)
Definition: Shuttle.cpp:326
std::conditional_t< Const, T, T & > Arg
Definition: Shuttle.h:120
wxString mParams
Definition: Shuttle.h:122
CommandParameters * mpEap
Definition: Shuttle.h:124
std::conditional_t< Const, const bool, bool > * pOptionalFlag
Definition: Shuttle.h:123
virtual ~SettingsVisitorBase()
virtual SettingsVisitorBase & Optional(Ref< bool > var)
Definition: Shuttle.cpp:318
virtual void DefineEnum(Arg< int > var, const wxChar *key, int vdefault, const EnumValueSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:390
std::conditional_t< Const, const T &, T & > Ref
Definition: Shuttle.h:118
virtual SettingsVisitorBase & OptionalN(Ref< bool > var)
Definition: Shuttle.cpp:333
Derived from Shuttle, this class exchanges string parameters with a binary representation.
Definition: Shuttle.h:97
virtual ~ShuttleCli()
Definition: Shuttle.h:101
wxString mParams
Definition: Shuttle.h:99
bool ExchangeWithMaster(const wxString &Name) override
Definition: Shuttle.cpp:263
ShuttleCli()
Definition: Shuttle.h:100
Moves data from one place to another, converting it as required.
Definition: Shuttle.h:70
virtual bool TransferBool(const wxString &Name, bool &bValue, const bool &bDefault)
Definition: Shuttle.cpp:72
virtual bool TransferString(const wxString &Name, wxString &strValue, const wxString &strDefault)
Definition: Shuttle.cpp:215
Shuttle()
Definition: Shuttle.cpp:68
virtual bool TransferDouble(const wxString &Name, double &dValue, const double &dDefault)
Definition: Shuttle.cpp:110
virtual bool TransferWrappedType(const wxString &Name, WrappedType &W)
Definition: Shuttle.cpp:234
bool mbStoreInClient
Definition: Shuttle.h:77
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:252
virtual bool TransferFloat(const wxString &Name, float &fValue, const float &fDefault)
Definition: Shuttle.cpp:91
virtual bool TransferLongLong(const wxString &Name, wxLongLong_t &iValue, const wxLongLong_t &iDefault)
Definition: Shuttle.cpp:154
virtual bool TransferInt(const wxString &Name, int &iValue, const int &iDefault)
Definition: Shuttle.cpp:130
virtual ~Shuttle()
Definition: Shuttle.h:74
virtual bool TransferEnum(const wxString &Name, int &iValue, const int nChoices, const wxString *pFirstStr)
Definition: Shuttle.cpp:174
wxString mValueString
Definition: Shuttle.h:78
Used in type conversions, this wrapper for ints, strings, doubles and enums provides conversions betw...
Definition: WrappedType.h:31
const wxChar *const key
Identifier in configuration file.
Definition: Shuttle.h:28
const Type scale
Scaling factor, for slider control.
Definition: Shuttle.h:32
Member Structure::*const mem
Member holding the parameter.
Definition: Shuttle.h:27
const Type def
Default value.
Definition: Shuttle.h:29
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31
constexpr EnumParameter(Member Structure::*const mem, const wxChar *key, int def, int min, int max, int scale, const EnumValueSymbol *symbols_, size_t nSymbols_)
Definition: Shuttle.h:52
const size_t nSymbols
Definition: Shuttle.h:62
const EnumValueSymbol *const symbols
Definition: Shuttle.h:61