Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
parameter.hh
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#ifndef __ASE_PARAMETER_HH__
3#define __ASE_PARAMETER_HH__
4
5#include <ase/defs.hh>
6#include <ase/memory.hh>
7#include <ase/value.hh>
8
9namespace Ase {
10
13
15using ChoicesFunc = std::function<ChoiceS(const CString&)>;
16
19
21struct ParamExtraVals : std::variant<MinMaxStep,ChoiceS,ChoicesFunc> {
22 ParamExtraVals () = default;
23 ParamExtraVals (double vmin, double vmax, double step = 0);
26 ParamExtraVals (const ChoiceS&);
28};
29
31struct Param {
42 String fetch (const String &key) const;
43 void store (const String &key, const String &v);
44 static inline const String STORAGE = ":r:w:S:";
45 static inline const String STANDARD = ":r:w:S:G:";
46};
47
49struct Parameter {
50 CString cident;
51 bool has (const String &key) const;
52 String fetch (const String &key) const;
53 void store (const String &key, const String &value);
54 String ident () const { return cident; }
55 String label () const { return fetch ("label"); }
56 String nick () const;
57 String unit () const { return fetch ("unit"); }
58 String hints () const { return fetch ("hints"); }
59 String blurb () const { return fetch ("blurb"); }
60 String descr () const { return fetch ("descr"); }
61 String group () const { return fetch ("group"); }
62 Value initial () const { return initial_; }
63 bool has_hint (const String &hint) const;
64 ChoiceS choices () const;
65 const StringS metadata () const { return metadata_; }
66 MinMaxStep range () const;
67 bool is_numeric () const;
68 bool is_choice () const { return has_hint ("choice"); }
69 bool is_text () const { return has_hint ("text"); }
70 double normalize (double val) const;
71 double rescale (double t) const;
72 Value constrain (const Value &value) const;
73 double dconstrain (const Value &value) const;
74 void initialsync (const Value &v);
75 /*ctor*/ Parameter () = default;
76 /*ctor*/ Parameter (const Param&);
77 /*copy*/ Parameter (const Parameter&) = default;
78 Parameter& operator= (const Parameter&) = default;
79 // helpers
80 String value_to_text (const Value &value) const;
81 Value value_from_text (const String &text) const;
82 static String construct_hints (const String &hints, const String &more, double pmin = 0, double pmax = 0);
83 static size_t match_choice (const ChoiceS &choices, const String &text);
84private:
86 StringS metadata_;
87 ExtrasV extras_;
88 Value initial_ = 0;
89};
91
93struct ParameterMap final : std::map<uint32_t,ParameterC> {
97 struct Entry {
98 ParameterMap &map;
99 const uint32_t id;
100 void operator= (const Param&);
101 };
103 Entry operator[] (uint32_t id);
104};
105
107String parameter_guess_nick (const String &parameter_label);
108
109} // Ase
110
111#endif // __ASE_PARAMETER_HH__
Compact, deduplicating string variant for constant strings.
Definition memory.hh:138
The Anklang C++ API namespace.
Definition api.hh:9
String parameter_guess_nick(const String &parameter_label)
Create a few letter nick name from a multi word parameter label.
Definition parameter.cc:583
std::variant< bool, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, float, double, const char *, std::string > ParamInitialVal
Initial value for parameters.
Definition parameter.hh:18
typedef uint32_t
Helper to specify parameter ranges.
Definition parameter.hh:21
Structured initializer for Parameter.
Definition parameter.hh:31
StringS metadata
Array of "key=value" pairs.
Definition parameter.hh:41
InitialVal initial
Initial value for float, int, choice types.
Definition parameter.hh:37
String label
Preferred user interface name.
Definition parameter.hh:35
String hints
Hints for parameter handling.
Definition parameter.hh:40
String unit
Units of the values within range.
Definition parameter.hh:38
String nick
Abbreviated user interface name, usually not more than 6 characters.
Definition parameter.hh:36
ExtraVals extras
Min, max, stepping for double ranges or array of choices to select from.
Definition parameter.hh:39
String ident
Identifier used for serialization (can be derived from untranslated label).
Definition parameter.hh:34
Helper for new Parameter creation from Param initializer.
Definition parameter.hh:97
Parameter list construction helper.
Definition parameter.hh:93
Entry operator[](uint32_t id)
Slot subscription for new Parameter creation.
Definition parameter.cc:422
String group
Group to be applied to all newly inserted Parameter objects.
Definition parameter.hh:95
Structure to provide information about properties or preferences.
Definition parameter.hh:49
MinMaxStep range() const
Min, max, stepping for double ranges.
Definition parameter.cc:113
Value type used to interface with various property types.
Definition value.hh:54