|
ape
0.5.0
Audio Programming Environment
|
Go to the documentation of this file. 1 #ifndef CPPAPE_PARAMETER_H
2 #define CPPAPE_PARAMETER_H
9 #include <initializer_list>
26 template<
class Type,
typename Select = std::true_type>
33 return mi + x * (ma - mi);
38 return mi * std::pow(ma / mi, x);
43 return std::floor(static_cast<PFloat>(0.5) + mi + x * (ma - mi));
48 return std::floor(static_cast<PFloat>(0.5) + mi * std::pow(ma / mi, x));
55 return (y - mi) / (ma - mi);
60 return std::log(y / mi) / std::log(ma / mi);
65 return (std::floor(static_cast<PFloat>(0.5) + y) - mi) / (ma - mi);
70 return std::log(std::floor(static_cast<PFloat>(0.5) + y) / mi) / std::log(ma / mi);
80 template<
class Type,
typename Select>
107 : min(0), max(1), mapping(
Lin)
116 : min(minValue), max(maxValue), mapping(parameterMapping)
118 if (parameterMapping ==
Exp)
120 assert(minValue != 0 &&
"Exponential mapping cannot have a minimum of 0");
121 assert(maxValue != 0 &&
"Exponential mapping cannot have a maximum of 0");
132 return min + value * (max - min);
134 return min * pow(max / min, value);
157 return !quantized ? (mapping ==
Lin ? scaleLin : scaleExp) : (mapping ==
Lin ? scaleLinQ : scaleExpQ);
168 return !quantized ? (mapping ==
Lin ? invScaleLin : invScaleExp) : (mapping ==
Lin ? invScaleLinQ : invScaleExpQ);
178 auto getMin() const noexcept {
return min; }
182 auto getMax() const noexcept {
return max; }
203 template<
class Type,
class Derived>
212 :
name(paramName.size() == 0 ?
"Unnamed" : paramName)
213 ,
range(parameterRange)
225 return Derived::convert(normalized);
234 return Derived::representationFor(value);
240 int id() const noexcept
263 operator Type() const noexcept
271 template<
typename Index>
284 template<
typename Index>
285 Type
at(Index idx)
const noexcept
299 return static_cast<Derived&>(*
this);
333 using Base::operator =;
336 :
Param(paramName,
"", parameterRange)
341 Param(
const std::string_view paramName,
const std::string& unit,
const Range parameterRange =
Range())
342 :
Base(paramName, parameterRange)
349 return static_cast<int>(std::floor((value + static_cast<PFloat>(0.5f)))) ? true :
false;
354 return static_cast<PFloat>(value ? 1.0f : 0.0f);
384 typedef std::initializer_list<const char*>
Names;
385 using Base::operator =;
404 Param(
const std::string_view paramName,
const std::initializer_list<const char*> values)
405 :
Base(paramName,
Range(0, values.size() - 1))
418 return static_cast<ParameterType>(std::round(value));
423 return static_cast<float>(value);
438 using Base::operator =;
441 :
Param(paramName,
"", parameterRange)
446 Param(
const std::string_view paramName,
const std::string& unit,
const Range parameterRange =
Range())
447 :
Base(paramName, parameterRange)
454 this->range.getTransformer(
false),
455 this->range.getNormalizer(
false),
463 return static_cast<ParameterType>(value);
468 return static_cast<PFloat>(value);
483 using Base::operator =;
486 :
Param(paramName,
"", parameterRange)
491 Param(
const std::string_view paramName,
const std::string& unit,
const Range parameterRange =
Range())
492 :
Base(paramName, parameterRange)
499 this->range.getTransformer(
false),
500 this->range.getNormalizer(
false),
508 return static_cast<ParameterType>(value);
513 return static_cast<PFloat>(value);
531 using Base::operator =;
534 :
Param(paramName,
"", parameterRange)
539 Param(
const std::string_view paramName,
const std::string& unit,
const Range parameterRange =
Range())
540 :
Base(paramName, parameterRange)
547 this->range.getTransformer(
true),
548 this->range.getNormalizer(
true),
556 return static_cast<ParameterType>(std::round(value));
561 return static_cast<PFloat>(value);
APE_SharedInterface & getInterface()
Acquire the low-level C API.
PFloat step
Definition: SharedInterface.h:93
const char const char APE_Parameter APE_Transformer APE_Normalizer PFloat min
Definition: SharedInterface.h:178
static constexpr PFloat representationFor(ParameterType value) noexcept
Definition: parameter.h:511
static PFloat representationFor(Type value) noexcept
Convert a native Type to an engine PFloat type. convert
Definition: parameter.h:232
int id
Definition: SharedInterface.h:94
APE_DataType size_t size
Definition: SharedInterface.h:183
Param(const std::string_view paramName="", const Range parameterRange=Range())
Definition: parameter.h:440
int ParameterType
Definition: parameter.h:529
int changeFlags
Definition: SharedInterface.h:94
float ParameterType
Definition: parameter.h:436
static ParameterType convert(PFloat value) noexcept
Definition: parameter.h:347
static constexpr ParameterType convert(PFloat value) noexcept
Definition: parameter.h:506
Type operator[](Index idx) const noexcept
Alias for at().
Definition: parameter.h:272
static constexpr PFloat representationFor(ParameterType value) noexcept
Definition: parameter.h:466
PFloat(APE_API * APE_Normalizer)(PFloat y, PFloat _min, PFloat _max)
Definition: APE.h:59
static ParameterType convert(PFloat value) noexcept
Definition: parameter.h:416
Param(const std::string_view paramName, const std::string &unit, const Range parameterRange=Range())
Definition: parameter.h:446
Param(const std::string_view paramName, const std::string &unit, const Range parameterRange=Range())
Definition: parameter.h:539
bool ParameterType
Definition: parameter.h:331
static ParameterType convert(PFloat value) noexcept
Definition: parameter.h:554
static PFloat representationFor(ParameterType value) noexcept
Definition: parameter.h:352
auto getMax() const noexcept
Returns the maximum of the constructed range
Definition: parameter.h:182
Base traits class for all classes that are displayed in the GUI.
Definition: baselib.h:62
PFloat operator()(PFloat value) const noexcept
Evaluate the range as a f(x) function, where value is x inverse()
Definition: parameter.h:129
Param(const std::string_view paramName="", const Range parameterRange=Range())
Definition: parameter.h:335
Maps exponentially from min to max.
Definition: parameter.h:100
ParameterBase< bool, Param< bool > > Base
Definition: parameter.h:330
auto getMin() const noexcept
return the minimum of the constructed range
Definition: parameter.h:178
auto getMapping() const noexcept
Returns the Mapping this range was constructed with
Definition: parameter.h:174
PFloat old
Definition: SharedInterface.h:93
Range()
Construct a default linear range from 0 to 1
Definition: parameter.h:106
Type at(Index idx) const noexcept
Evaluate the value of the parameter at at a specific sample index, where 0 equals the start of the pr...
Definition: parameter.h:285
double PFloat
Floating-precision point type used for parameter processing
Definition: APE.h:56
ParameterBase< double, Param< double > > Base
Definition: parameter.h:480
static constexpr PFloat representationFor(ParameterType value) noexcept
Definition: parameter.h:559
ParameterBase(const std::string_view paramName="", const Range parameterRange=Range())
Constructs a named parameter.
Definition: parameter.h:211
Param(const std::string_view paramName, const std::string &unit, const Range parameterRange=Range())
Definition: parameter.h:341
Derived & operator=(Type t) noexcept
Assign a value to this parameter. Depending on host support, this might only make sense inside the co...
Definition: parameter.h:296
static Type convert(PFloat normalized) noexcept
Convert an engine PFloat to the native Type of this parameter. representationFor
Definition: parameter.h:223
PFloat inverse(bool quantized, PFloat value) const noexcept
Normalizes value back to a 0 .. 1 range. operator()()
Definition: parameter.h:144
Definition: audiofile.h:7
Param(const std::string_view paramName="", const Range parameterRange=Range())
Definition: parameter.h:533
Shared functionality for all specializations of parameters. ParameterBase
Definition: parameter.h:204
Template for parameter specializations on different types. Parameters are based on an normalized PFlo...
Definition: parameter.h:27
bool changed() const noexcept
Whether the parameter has changed in this processing frame. Only sensible when called from within Pro...
Definition: parameter.h:252
int id() const noexcept
A unique identifier for this parameter
Definition: parameter.h:240
~ParameterBase()
Delete this parameter instance.
Definition: parameter.h:305
APE_Transformer getTransformer(bool quantized) const noexcept
Retrieve a function pointer with appropriate Mapping and selectively quantized .
Definition: parameter.h:155
Param(const std::string_view paramName="", const Range parameterRange=Range())
Definition: parameter.h:485
PFloat next
Definition: SharedInterface.h:93
auto getRange() const noexcept
Returns the Range this parameter was constructed with.
Definition: parameter.h:313
APE_Parameter param
Definition: parameter.h:317
std::string name
Definition: parameter.h:319
static PFloat representationFor(ParameterType value) noexcept
Definition: parameter.h:421
ParameterBase< float, Param< float > > Base
Definition: parameter.h:435
ParameterBase< T, Param< T > > Base
Definition: parameter.h:367
const Range range
Definition: parameter.h:318
PFloat(APE_API * APE_Transformer)(PFloat x, PFloat _min, PFloat _max)
Definition: APE.h:58
std::initializer_list< const char * > Names
A list-initialization type suitable for a string names of enumerations, e.g.: enum class FilterChoice...
Definition: parameter.h:384
Param(const std::string_view paramName, const std::initializer_list< const char * > values)
Construct a parameter that can automate a list of string values, and convert them to T .
Definition: parameter.h:404
static constexpr ParameterType convert(PFloat value) noexcept
Definition: parameter.h:461
Param(const std::string_view paramName, const std::string &unit, const Range parameterRange=Range())
Definition: parameter.h:491
Definition: SharedInterface.h:91
ParameterBase< int, Param< int > > Base
Definition: parameter.h:528
Range(PFloat minValue, PFloat maxValue, Mapping parameterMapping=Lin)
Constructs a range from minValue to maxValue with parameterMapping mapping.
Definition: parameter.h:115
Mapping
Different curve mappings for the interval
Definition: parameter.h:88
Maps linearly from min to max
Definition: parameter.h:93
Represents a mapping function in a interval, suitable for evaluation between 0 .. 1 inclusive,...
Definition: parameter.h:78
double ParameterType
Definition: parameter.h:481
T ParameterType
Definition: parameter.h:368
APE_Normalizer getNormalizer(bool quantized) const noexcept
Retrieve a function pointer with appropriate Mapping and selectively quantized , for inverse transfor...
Definition: parameter.h:166