Audacity 3.2.0
Public Types | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
CapturedParameters< EffectType, Parameters > Class Template Reference

Generates EffectParameterMethods overrides from variadic template arguments. More...

#include <ShuttleAutomation.h>

Inheritance diagram for CapturedParameters< EffectType, Parameters >:
[legend]
Collaboration diagram for CapturedParameters< EffectType, Parameters >:
[legend]

Public Types

using Params = std::remove_pointer_t< decltype(EffectType::FetchParameters(std::declval< EffectType & >(), std::declval< EffectSettings & >())) >
 
using PostSetFunction = std::function< bool(EffectType &, EffectSettings &, Params &, bool) >
 

Public Member Functions

virtual ~CapturedParameters ()=default
 
 CapturedParameters ()
 
template<typename Fn , typename = decltype( std::declval<Fn>()( std::declval<EffectType &>(), std::declval<EffectSettings &>(), std::declval<Params &>(), true) )>
 CapturedParameters (Fn &&PostSet)
 
void Reset (Effect &effect) const override
 
void Visit (Effect &effect, SettingsVisitor &visitor, EffectSettings &settings) const override
 
void Visit (const Effect &effect, ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
void Get (const Effect &effect, const EffectSettings &settings, CommandParameters &parms) const override
 
bool Set (Effect &effect, const CommandParameters &parms, EffectSettings &settings) const override
 
- Public Member Functions inherited from EffectParameterMethods
virtual ~EffectParameterMethods ()
 
virtual void Reset (Effect &effect) const =0
 
virtual void Visit (Effect &effect, SettingsVisitor &visitor, EffectSettings &settings) const =0
 
virtual void Visit (const Effect &effect, ConstSettingsVisitor &visitor, const EffectSettings &settings) const =0
 
virtual void Get (const Effect &effect, const EffectSettings &settings, CommandParameters &parms) const =0
 
virtual bool Set (Effect &effect, const CommandParameters &parms, EffectSettings &settings) const =0
 

Static Private Member Functions

template<typename Member , typename Type , typename Value >
static void ResetOne (Params &structure, const EffectParameter< Params, Member, Type, Value > &param)
 
static void DoReset (Effect &effect, EffectSettings settings, Params &structure, const CapturedParameters &This)
 
template<bool Const, typename Member , typename Type , typename Value >
static void VisitOne (Params &structure, SettingsVisitorBase< Const > &visitor, const EffectParameter< Params, Member, Type, Value > &param)
 
template<bool Const, typename Member >
static void VisitOne (Params &structure, SettingsVisitorBase< Const > &visitor, const EnumParameter< Params, Member > &param)
 
template<bool Const>
static void DoVisit (Params &structure, SettingsVisitorBase< Const > &visitor)
 
template<typename Member , typename Type , typename Value >
static void GetOne (const Params &structure, CommandParameters &parms, const EffectParameter< Params, Member, Type, Value > &param)
 
template<typename Member >
static void GetOne (const Params &structure, CommandParameters &parms, const EnumParameter< Params, Member > &param)
 
static void DoGet (const Params &structure, CommandParameters &parms)
 
template<typename Member , typename Type , typename Value >
static bool SetOne (Params &structure, const CommandParameters &parms, const EffectParameter< Params, Member, Type, Value > &param)
 
template<typename Member >
static bool SetOne (Params &structure, const CommandParameters &parms, const EnumParameter< Params, Member > &param)
 
static bool DoSet (Effect &effect, EffectSettings &settings, Params &structure, const CapturedParameters &This, const CommandParameters &parms)
 

Private Attributes

PostSetFunction PostSetFn
 

Detailed Description

template<typename EffectType, const auto &... Parameters>
class CapturedParameters< EffectType, Parameters >

Generates EffectParameterMethods overrides from variadic template arguments.

For each effect parameter, the function... Reset resets it to a default Visit visits it with a SettingsVisitor object; there are overloads taking SettingsVisitor and ConstSettingsVisitor Get serializes it to a string Set deserializes it from a string and returns a success flag (if there is failure, parameters might not all be unchanged)

The constructor optionally takes an argument which is a function to be called at the end of Reset or Set, and returning a value for Set.

Template Parameters
EffectTypesubclass of Effect, expected to define a public static member function FetchParameters, taking EffectType & and EffectSettings &, and returning a pointer to something that holds the parameters
Parametersa pack of non-type template parameters, whose types are specializations of the class template EffectParameter

TODO in C++20: could use simply auto ...Parameters if they are constexpr

Definition at line 60 of file ShuttleAutomation.h.

Member Typedef Documentation

◆ Params

template<typename EffectType , const auto &... Parameters>
using CapturedParameters< EffectType, Parameters >::Params = std::remove_pointer_t< decltype( EffectType::FetchParameters( std::declval<EffectType&>(), std::declval<EffectSettings &>()) ) >

Definition at line 62 of file ShuttleAutomation.h.

◆ PostSetFunction

template<typename EffectType , const auto &... Parameters>
using CapturedParameters< EffectType, Parameters >::PostSetFunction = std::function< bool(EffectType&, EffectSettings &, Params &, bool) >

Definition at line 74 of file ShuttleAutomation.h.

Constructor & Destructor Documentation

◆ ~CapturedParameters()

template<typename EffectType , const auto &... Parameters>
virtual CapturedParameters< EffectType, Parameters >::~CapturedParameters ( )
virtualdefault

◆ CapturedParameters() [1/2]

template<typename EffectType , const auto &... Parameters>
CapturedParameters< EffectType, Parameters >::CapturedParameters ( )
inline

Definition at line 79 of file ShuttleAutomation.h.

79{}

◆ CapturedParameters() [2/2]

template<typename EffectType , const auto &... Parameters>
template<typename Fn , typename = decltype( std::declval<Fn>()( std::declval<EffectType &>(), std::declval<EffectSettings &>(), std::declval<Params &>(), true) )>
CapturedParameters< EffectType, Parameters >::CapturedParameters ( Fn &&  PostSet)
inlineexplicit

Definition at line 90 of file ShuttleAutomation.h.

91 : PostSetFn{ std::forward<Fn>(PostSet) }
92 {}
PostSetFunction PostSetFn

Member Function Documentation

◆ DoGet()

template<typename EffectType , const auto &... Parameters>
static void CapturedParameters< EffectType, Parameters >::DoGet ( const Params structure,
CommandParameters parms 
)
inlinestaticprivate

Definition at line 199 of file ShuttleAutomation.h.

199 {
200 (GetOne(structure, parms, Parameters), ...);
201 }
static void GetOne(const Params &structure, CommandParameters &parms, const EffectParameter< Params, Member, Type, Value > &param)

References CapturedParameters< EffectType, Parameters >::GetOne().

Referenced by CapturedParameters< EffectType, Parameters >::Get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoReset()

template<typename EffectType , const auto &... Parameters>
static void CapturedParameters< EffectType, Parameters >::DoReset ( Effect effect,
EffectSettings  settings,
Params structure,
const CapturedParameters< EffectType, Parameters > &  This 
)
inlinestaticprivate

Definition at line 152 of file ShuttleAutomation.h.

154 {
155 (ResetOne(structure, Parameters), ...);
156 // Call the post-set function after all other assignments
157 if (This.PostSetFn)
158 This.PostSetFn(
159 static_cast<EffectType&>(effect), settings, structure, false);
160 }
EffectType
static Settings & settings()
Definition: TrackInfo.cpp:87
static void ResetOne(Params &structure, const EffectParameter< Params, Member, Type, Value > &param)

References CapturedParameters< EffectType, Parameters >::PostSetFn, CapturedParameters< EffectType, Parameters >::ResetOne(), and settings().

Referenced by CapturedParameters< EffectType, Parameters >::Reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoSet()

template<typename EffectType , const auto &... Parameters>
static bool CapturedParameters< EffectType, Parameters >::DoSet ( Effect effect,
EffectSettings settings,
Params structure,
const CapturedParameters< EffectType, Parameters > &  This,
const CommandParameters parms 
)
inlinestaticprivate

Definition at line 228 of file ShuttleAutomation.h.

230 {
231 if (!(SetOne(structure, parms, Parameters) && ...))
232 return false;
233 // Call the post-set function after all other assignments, or return
234 // true if no function was given
235 return !This.PostSetFn ||
236 This.PostSetFn(
237 static_cast<EffectType&>(effect), settings, structure, true);
238 }
static bool SetOne(Params &structure, const CommandParameters &parms, const EffectParameter< Params, Member, Type, Value > &param)

References CapturedParameters< EffectType, Parameters >::PostSetFn, CapturedParameters< EffectType, Parameters >::SetOne(), and settings().

Referenced by CapturedParameters< EffectType, Parameters >::Set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoVisit()

template<typename EffectType , const auto &... Parameters>
template<bool Const>
static void CapturedParameters< EffectType, Parameters >::DoVisit ( Params structure,
SettingsVisitorBase< Const > &  visitor 
)
inlinestaticprivate

Definition at line 181 of file ShuttleAutomation.h.

181 {
182 (VisitOne<Const>(structure, visitor, Parameters), ...);
183 }

Referenced by CapturedParameters< EffectType, Parameters >::Visit().

Here is the caller graph for this function:

◆ Get()

template<typename EffectType , const auto &... Parameters>
void CapturedParameters< EffectType, Parameters >::Get ( const Effect effect,
const EffectSettings settings,
CommandParameters parms 
) const
inlineoverridevirtual

Implements EffectParameterMethods.

Definition at line 119 of file ShuttleAutomation.h.

120 {
121 // const_cast the effect...
122 auto &nonconstEffect = const_cast<Effect &>(effect);
123 // ... and the settings ...
124 auto &nonconstSettings = const_cast<EffectSettings&>(settings);
125 // ... but only to fetch the structure and pass it as const &
126 if (auto pStruct = EffectType::FetchParameters(
127 static_cast<EffectType&>(nonconstEffect), nonconstSettings))
128 DoGet(*pStruct, parms);
129 }
static void DoGet(const Params &structure, CommandParameters &parms)
Base class for many of the effects in Audacity.
Definition: Effect.h:63
Externalized state of a plug-in.

References CapturedParameters< EffectType, Parameters >::DoGet(), and settings().

Here is the call graph for this function:

◆ GetOne() [1/2]

template<typename EffectType , const auto &... Parameters>
template<typename Member , typename Type , typename Value >
static void CapturedParameters< EffectType, Parameters >::GetOne ( const Params structure,
CommandParameters parms,
const EffectParameter< Params, Member, Type, Value > &  param 
)
inlinestaticprivate

Definition at line 186 of file ShuttleAutomation.h.

187 {
188 // Serialize one variable
189 parms.Write( param.key, static_cast<Value>(structure.*(param.mem)) );
190 }
const wxChar *const key
Identifier in configuration file.
Definition: Shuttle.h:28
Member Structure::*const mem
Member holding the parameter.
Definition: Shuttle.h:27

References EffectParameter< Structure, Member, Type, Value >::key, and EffectParameter< Structure, Member, Type, Value >::mem.

Referenced by CapturedParameters< EffectType, Parameters >::DoGet().

Here is the caller graph for this function:

◆ GetOne() [2/2]

template<typename EffectType , const auto &... Parameters>
template<typename Member >
static void CapturedParameters< EffectType, Parameters >::GetOne ( const Params structure,
CommandParameters parms,
const EnumParameter< Params, Member > &  param 
)
inlinestaticprivate

Definition at line 193 of file ShuttleAutomation.h.

194 {
195 // Serialize one enumeration variable as a string identifier, not a number
196 parms.Write(
197 param.key, param.symbols[ structure.*(param.mem) ].Internal() );
198 }
const wxString & Internal() const
const EnumValueSymbol *const symbols
Definition: Shuttle.h:61

References ComponentInterfaceSymbol::Internal(), EffectParameter< Structure, Member, Type, Value >::key, EffectParameter< Structure, Member, Type, Value >::mem, and EnumParameter< Structure, Member >::symbols.

Here is the call graph for this function:

◆ Reset()

template<typename EffectType , const auto &... Parameters>
void CapturedParameters< EffectType, Parameters >::Reset ( Effect effect) const
inlineoverridevirtual

Implements EffectParameterMethods.

Definition at line 94 of file ShuttleAutomation.h.

94 {
95 EffectSettings dummy;
96 if (auto pStruct = EffectType::FetchParameters(
97 static_cast<EffectType&>(effect), dummy))
98 DoReset(effect, dummy, *pStruct, *this);
99 }
static void DoReset(Effect &effect, EffectSettings settings, Params &structure, const CapturedParameters &This)

References CapturedParameters< EffectType, Parameters >::DoReset().

Here is the call graph for this function:

◆ ResetOne()

template<typename EffectType , const auto &... Parameters>
template<typename Member , typename Type , typename Value >
static void CapturedParameters< EffectType, Parameters >::ResetOne ( Params structure,
const EffectParameter< Params, Member, Type, Value > &  param 
)
inlinestaticprivate

Definition at line 147 of file ShuttleAutomation.h.

148 {
149 // Do one assignment of the default value
150 structure.*(param.mem) = param.def;
151 }
const Type def
Default value.
Definition: Shuttle.h:29

References EffectParameter< Structure, Member, Type, Value >::def, and EffectParameter< Structure, Member, Type, Value >::mem.

Referenced by CapturedParameters< EffectType, Parameters >::DoReset().

Here is the caller graph for this function:

◆ Set()

template<typename EffectType , const auto &... Parameters>
bool CapturedParameters< EffectType, Parameters >::Set ( Effect effect,
const CommandParameters parms,
EffectSettings settings 
) const
inlineoverridevirtual

Implements EffectParameterMethods.

Definition at line 130 of file ShuttleAutomation.h.

131 {
132 if (auto pStruct = EffectType::FetchParameters(
133 static_cast<EffectType&>(effect), settings))
134 return DoSet(effect, settings, *pStruct, *this, parms);
135 else
136 return false;
137 }
static bool DoSet(Effect &effect, EffectSettings &settings, Params &structure, const CapturedParameters &This, const CommandParameters &parms)

References CapturedParameters< EffectType, Parameters >::DoSet(), and settings().

Here is the call graph for this function:

◆ SetOne() [1/2]

template<typename EffectType , const auto &... Parameters>
template<typename Member , typename Type , typename Value >
static bool CapturedParameters< EffectType, Parameters >::SetOne ( Params structure,
const CommandParameters parms,
const EffectParameter< Params, Member, Type, Value > &  param 
)
inlinestaticprivate

Definition at line 204 of file ShuttleAutomation.h.

206 {
207 // Deserialize and assign one variable (or fail)
208 Value temp;
209 if (!parms.ReadAndVerify(param.key, &temp, param.def,
210 param.min, param.max))
211 return false;
212 structure.*(param.mem) = temp;
213 return true;
214 }
bool ReadAndVerify(const wxString &key, float *val, float defVal, float min, float max) const
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31

References EffectParameter< Structure, Member, Type, Value >::def, EffectParameter< Structure, Member, Type, Value >::key, EffectParameter< Structure, Member, Type, Value >::max, EffectParameter< Structure, Member, Type, Value >::mem, EffectParameter< Structure, Member, Type, Value >::min, and CommandParameters::ReadAndVerify().

Referenced by CapturedParameters< EffectType, Parameters >::DoSet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetOne() [2/2]

template<typename EffectType , const auto &... Parameters>
template<typename Member >
static bool CapturedParameters< EffectType, Parameters >::SetOne ( Params structure,
const CommandParameters parms,
const EnumParameter< Params, Member > &  param 
)
inlinestaticprivate

Definition at line 217 of file ShuttleAutomation.h.

219 {
220 // Deserialize and assign one enumeration variable (or fail)
221 int temp;
222 if (!parms.ReadAndVerify(param.key, &temp, param.def,
223 param.symbols, param.nSymbols))
224 return false;
225 structure.*(param.mem) = temp;
226 return true;
227 }
const size_t nSymbols
Definition: Shuttle.h:62

References EffectParameter< Structure, Member, Type, Value >::def, EffectParameter< Structure, Member, Type, Value >::key, EffectParameter< Structure, Member, Type, Value >::mem, EnumParameter< Structure, Member >::nSymbols, CommandParameters::ReadAndVerify(), and EnumParameter< Structure, Member >::symbols.

Here is the call graph for this function:

◆ Visit() [1/2]

template<typename EffectType , const auto &... Parameters>
void CapturedParameters< EffectType, Parameters >::Visit ( const Effect effect,
ConstSettingsVisitor visitor,
const EffectSettings settings 
) const
inlineoverridevirtual

Implements EffectParameterMethods.

Definition at line 107 of file ShuttleAutomation.h.

109 {
110 // const_cast the effect...
111 auto &nonconstEffect = const_cast<Effect&>(effect);
112 // ... and the settings ...
113 auto &nonconstSettings = const_cast<EffectSettings&>(settings);
114 // ... but only to fetch the structure and pass it as const &
115 if (auto pStruct = EffectType::FetchParameters(
116 static_cast<EffectType&>(nonconstEffect), nonconstSettings))
117 DoVisit(*pStruct, visitor);
118 }
static void DoVisit(Params &structure, SettingsVisitorBase< Const > &visitor)

References CapturedParameters< EffectType, Parameters >::DoVisit(), and settings().

Here is the call graph for this function:

◆ Visit() [2/2]

template<typename EffectType , const auto &... Parameters>
void CapturedParameters< EffectType, Parameters >::Visit ( Effect effect,
SettingsVisitor visitor,
EffectSettings settings 
) const
inlineoverridevirtual

Implements EffectParameterMethods.

Definition at line 100 of file ShuttleAutomation.h.

102 {
103 if (auto pStruct = EffectType::FetchParameters(
104 static_cast<EffectType&>(effect), settings))
105 DoVisit<false>(*pStruct, visitor);
106 }

References settings().

Here is the call graph for this function:

◆ VisitOne() [1/2]

template<typename EffectType , const auto &... Parameters>
template<bool Const, typename Member , typename Type , typename Value >
static void CapturedParameters< EffectType, Parameters >::VisitOne ( Params structure,
SettingsVisitorBase< Const > &  visitor,
const EffectParameter< Params, Member, Type, Value > &  param 
)
inlinestaticprivate

Definition at line 163 of file ShuttleAutomation.h.

164 {
165 // Visit one variable
166 visitor.Define( structure.*(param.mem), param.key,
167 static_cast<Member>(param.def),
168 static_cast<Member>(param.min),
169 static_cast<Member>(param.max),
170 static_cast<Member>(param.scale) );
171 }
virtual void Define(Arg< bool > var, const wxChar *key, bool vdefault, bool vmin=false, bool vmax=false, bool vscl=false)
Definition: Shuttle.cpp:359
const Type scale
Scaling factor, for slider control.
Definition: Shuttle.h:32

References EffectParameter< Structure, Member, Type, Value >::def, SettingsVisitorBase< Const >::Define(), EffectParameter< Structure, Member, Type, Value >::key, EffectParameter< Structure, Member, Type, Value >::max, EffectParameter< Structure, Member, Type, Value >::mem, EffectParameter< Structure, Member, Type, Value >::min, and EffectParameter< Structure, Member, Type, Value >::scale.

Here is the call graph for this function:

◆ VisitOne() [2/2]

template<typename EffectType , const auto &... Parameters>
template<bool Const, typename Member >
static void CapturedParameters< EffectType, Parameters >::VisitOne ( Params structure,
SettingsVisitorBase< Const > &  visitor,
const EnumParameter< Params, Member > &  param 
)
inlinestaticprivate

Definition at line 174 of file ShuttleAutomation.h.

175 {
176 // Visit one enumeration variable, passing the table of names
177 visitor.DefineEnum( structure.*(param.mem),
178 param.key, param.def, param.symbols, param.nSymbols );
179 }
virtual void DefineEnum(Arg< int > var, const wxChar *key, int vdefault, const EnumValueSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:394

References EffectParameter< Structure, Member, Type, Value >::def, SettingsVisitorBase< Const >::DefineEnum(), EffectParameter< Structure, Member, Type, Value >::key, EffectParameter< Structure, Member, Type, Value >::mem, EnumParameter< Structure, Member >::nSymbols, and EnumParameter< Structure, Member >::symbols.

Here is the call graph for this function:

Member Data Documentation

◆ PostSetFn

template<typename EffectType , const auto &... Parameters>
PostSetFunction CapturedParameters< EffectType, Parameters >::PostSetFn
private

The documentation for this class was generated from the following file: