Audacity 3.2.0
Go to the documentation of this file.
3 Audacity: A Digital Audio Editor
5 Shuttle.h
7 James Crook
11#ifndef __AUDACITY_SHUTTLE__
12#define __AUDACITY_SHUTTLE__
14#include <type_traits>
19class WrappedType;
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{};
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...)
49template<typename Structure, typename Member>
50struct EnumParameter : EffectParameter<Structure, Member, int>
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 {}
62 const size_t nSymbols;
65// Deduction guide
66template<typename Structure, typename Member, typename... Args>
67EnumParameter(Member Structure::*const mem, Args...)
70class Shuttle /* not final */ {
71 public:
72 // constructors and destructors
73 Shuttle();
74 virtual ~Shuttle() {}
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);
96class ShuttleCli final : public Shuttle
99 wxString mParams;
101 virtual ~ShuttleCli() {}
102 bool ExchangeWithMaster(const wxString & Name) override;
113template<bool Const>
114class SettingsVisitorBase /* not final */
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&>;
122 wxString mParams;
123 std::conditional_t<Const, const bool, bool> *pOptionalFlag{};
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 );
153extern template class AUDACITY_DLL_API SettingsVisitorBase<false>;
154extern template class AUDACITY_DLL_API SettingsVisitorBase<true>;
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:359
virtual SettingsVisitorBase & OptionalY(Ref< bool > var)
Definition: Shuttle.cpp:330
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:322
virtual void DefineEnum(Arg< int > var, const wxChar *key, int vdefault, const EnumValueSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:394
std::conditional_t< Const, const T &, T & > Ref
Definition: Shuttle.h:118
virtual SettingsVisitorBase & OptionalN(Ref< bool > var)
Definition: Shuttle.cpp:337
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:267
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:76
virtual bool TransferString(const wxString &Name, wxString &strValue, const wxString &strDefault)
Definition: Shuttle.cpp:219
Definition: Shuttle.cpp:72
virtual bool TransferDouble(const wxString &Name, double &dValue, const double &dDefault)
Definition: Shuttle.cpp:114
virtual bool TransferWrappedType(const wxString &Name, WrappedType &W)
Definition: Shuttle.cpp:238
bool mbStoreInClient
Definition: Shuttle.h:77
virtual bool ExchangeWithMaster(const wxString &Name)
Definition: Shuttle.cpp:256
virtual bool TransferFloat(const wxString &Name, float &fValue, const float &fDefault)
Definition: Shuttle.cpp:95
virtual bool TransferLongLong(const wxString &Name, wxLongLong_t &iValue, const wxLongLong_t &iDefault)
Definition: Shuttle.cpp:158
virtual bool TransferInt(const wxString &Name, int &iValue, const int &iDefault)
Definition: Shuttle.cpp:134
virtual ~Shuttle()
Definition: Shuttle.h:74
virtual bool TransferEnum(const wxString &Name, int &iValue, const int nChoices, const wxString *pFirstStr)
Definition: Shuttle.cpp:178
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