Anklang-0.3.0.dev956+gd75ac925 anklang-0.3.0.dev956+gd75ac925
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#pragma once
3
4#include <ase/defs.hh>
5#include <ase/memory.hh>
6#include <ase/value.hh>
7
8namespace Ase {
9
12
14using ChoicesFunc = std::function<ChoiceS(const CString&)>;
15
18
20struct ParamExtraVals : std::variant<MinMaxStep,ChoiceS,ChoicesFunc> {
21 ParamExtraVals () = default;
22 ParamExtraVals (double vmin, double vmax, double step = 0);
25 ParamExtraVals (const ChoiceS&);
27};
28
30struct Param {
41 String fetch (const String &key) const;
42 void store (const String &key, const String &v);
43 static inline const String STORAGE = ":r:w:S:";
44 static inline const String STANDARD = ":r:w:S:G:";
45};
46
48struct Parameter {
49 CString cident;
50 bool has (const String &key) const;
51 String fetch (const String &key) const;
52 void store (const String &key, const String &value);
53 String ident () const { return cident; }
54 String label () const { return fetch ("label"); }
55 String nick () const;
56 String unit () const { return fetch ("unit"); }
57 String hints () const { return fetch ("hints"); }
58 String blurb () const { return fetch ("blurb"); }
59 String descr () const { return fetch ("descr"); }
60 String group () const { return fetch ("group"); }
61 Value initial () const { return initial_; }
62 bool has_hint (const String &hint) const;
63 ChoiceS choices () const;
64 const StringS metadata () const { return metadata_; }
65 MinMaxStep range () const;
66 bool is_numeric () const;
67 bool is_choice () const { return has_hint ("choice"); }
68 bool is_text () const { return has_hint ("text"); }
69 double normalize (double val) const;
70 double rescale (double t) const;
71 Value constrain (const Value &value) const;
72 double dconstrain (const Value &value) const;
73 void initialsync (const Value &v);
74 /*ctor*/ Parameter () = default;
75 /*ctor*/ Parameter (const Param&);
76 /*copy*/ Parameter (const Parameter&) = default;
77 Parameter& operator= (const Parameter&) = default;
78 // helpers
79 String value_to_text (const Value &value) const;
80 Value value_from_text (const String &text) const;
81 static String construct_hints (const String &hints, const String &more, double pmin = 0, double pmax = 0);
82 static size_t match_choice (const ChoiceS &choices, const String &text);
83private:
85 StringS metadata_;
86 ExtrasV extras_;
87 Value initial_ = 0;
88};
90
92struct ParameterMap final : std::map<uint32_t,ParameterC> {
96 struct Entry {
97 ParameterMap &map;
98 const uint32_t id;
99 void operator= (const Param&);
100 };
102 Entry operator[] (uint32_t id);
103};
104
106String parameter_guess_nick (const String &parameter_label);
107
108} // Ase
109
Compact, deduplicating string variant for constant strings.
Definition memory.hh:137
The Anklang C++ API namespace.
Definition api.hh:8
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:17
typedef uint32_t
Helper to specify parameter ranges.
Definition parameter.hh:20
Structured initializer for Parameter.
Definition parameter.hh:30
StringS metadata
Array of "key=value" pairs.
Definition parameter.hh:40
InitialVal initial
Initial value for float, int, choice types.
Definition parameter.hh:36
String label
Preferred user interface name.
Definition parameter.hh:34
String hints
Hints for parameter handling.
Definition parameter.hh:39
String unit
Units of the values within range.
Definition parameter.hh:37
String nick
Abbreviated user interface name, usually not more than 6 characters.
Definition parameter.hh:35
ExtraVals extras
Min, max, stepping for double ranges or array of choices to select from.
Definition parameter.hh:38
String ident
Identifier used for serialization (can be derived from untranslated label).
Definition parameter.hh:33
Helper for new Parameter creation from Param initializer.
Definition parameter.hh:96
Parameter list construction helper.
Definition parameter.hh:92
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:94
Structure to provide information about properties or preferences.
Definition parameter.hh:48
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:53