Skip to content

Commit

Permalink
Merge branch 'properties-metadata' - support generic metadata on prop…
Browse files Browse the repository at this point in the history
…erties

* properties-metadata:
  devices/saturation/saturation.cc: add "blurb=" prefix and mark translations
  devices/liquidsfz/liquidsfz.cc: add "blurb=" prefix and mark translations
  devices/freeverb/freeverb.cc: add "blurb=" prefix and mark translations
  devices/blepsynth/blepsynth.cc: add "blurb=" prefix and mark translations
  ase/api.hh: introduce metadata() for properties
	* Add const this qualifier to parameter APIs.
	* engine.cc: add "descr=" prefix to property metadata
	* project.cc: add "descr=" prefix to property metadata
  ase/strings: add kvpairs_fetch() and kvpairs_assign()

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Feb 8, 2024
2 parents 070d91a + 75d7abb commit 5f06a6d
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 137 deletions.
41 changes: 21 additions & 20 deletions ase/api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,27 @@ class Property : public virtual Emittable {
protected:
virtual ~Property () = 0;
public:
virtual String ident () = 0; ///< Unique name (per owner) of this Property.
virtual String label () = 0; ///< Preferred user interface name.
virtual String nick () = 0; ///< Abbreviated user interface name, usually not more than 6 characters.
virtual String unit () = 0; ///< Units of the values within range.
virtual String hints () = 0; ///< Hints for parameter handling.
virtual String group () = 0; ///< Group name for parameters of similar function.
virtual String blurb () = 0; ///< Short description for user interface tooltips.
virtual String descr () = 0; ///< Elaborate description for help dialogs.
virtual double get_min () = 0; ///< Get the minimum property value, converted to double.
virtual double get_max () = 0; ///< Get the maximum property value, converted to double.
virtual double get_step () = 0; ///< Get the property value stepping, converted to double.
virtual void reset () = 0; ///< Assign default as normalized property value.
virtual Value get_value () = 0; ///< Get the native property value.
virtual bool set_value (const Value &v) = 0; ///< Set the native property value.
virtual double get_normalized () = 0; ///< Get the normalized property value, converted to double.
virtual bool set_normalized (double v) = 0; ///< Set the normalized property value as double.
virtual String get_text () = 0; ///< Get the current property value, converted to a text String.
virtual bool set_text (String v) = 0; ///< Set the current property value as a text String.
virtual bool is_numeric () = 0; ///< Whether the property settings can be represented as a floating point number.
virtual ChoiceS choices () = 0; ///< Enumerate choices for choosable properties.
virtual String ident () const = 0; ///< Unique name (per owner) of this Property.
virtual String label () const = 0; ///< Preferred user interface name.
virtual String nick () const = 0; ///< Abbreviated user interface name, usually not more than 6 characters.
virtual String unit () const = 0; ///< Units of the values within range.
virtual double get_min () const = 0; ///< Get the minimum property value, converted to double.
virtual double get_max () const = 0; ///< Get the maximum property value, converted to double.
virtual double get_step () const = 0; ///< Get the property value stepping, converted to double.
virtual void reset () = 0; ///< Assign default as normalized property value.
virtual Value get_value () const = 0; ///< Get the native property value.
virtual bool set_value (const Value &v) = 0; ///< Set the native property value.
virtual double get_normalized () const = 0; ///< Get the normalized property value, converted to double.
virtual bool set_normalized (double v) = 0; ///< Set the normalized property value as double.
virtual String get_text () const = 0; ///< Get the current property value, converted to a text String.
virtual bool set_text (String v) = 0; ///< Set the current property value as a text String.
virtual bool is_numeric () const = 0; ///< Whether the property settings can be represented as a floating point number.
virtual ChoiceS choices () const = 0; ///< Enumerate choices for choosable properties.
virtual StringS metadata () const = 0; ///< Get the list of additional metadata for a property.
String hints () const; ///< Hints for parameter handling (metadata).
String blurb () const; ///< Short description for user interface tooltips (metadata).
String descr () const; ///< Elaborate description, e.g. for help dialogs (metadata).
String group () const; ///< Group name for parameters of similar function (metadata).
};

/// Base type for classes with Property interfaces.
Expand Down
39 changes: 22 additions & 17 deletions ase/clapdevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ struct ClapPropertyImpl : public Property, public virtual EmittableImpl {
String ident_, label_, module_;
double min_value = NAN, max_value = NAN, default_value = NAN;
public:
String ident () override { return ident_; }
String label () override { return label_; }
String nick () override { return parameter_guess_nick (label_); }
String unit () override { return ""; }
String hints () override { return ClapParamInfo::hints_from_param_info_flags (flags); }
String group () override { return module_; }
String blurb () override { return ""; }
String descr () override { return ""; }
double get_min () override { return min_value; }
double get_max () override { return max_value; }
double get_step () override { return is_stepped() ? 1 : 0; }
bool is_numeric () override { return true; }
bool is_stepped () { return strstr (hints().c_str(), ":stepped:"); }
String ident () const override { return ident_; }
String label () const override { return label_; }
String nick () const override { return parameter_guess_nick (label_); }
String unit () const override { return ""; }
double get_min () const override { return min_value; }
double get_max () const override { return max_value; }
double get_step () const override { return is_stepped() ? 1 : 0; }
bool is_numeric () const override { return true; }
bool is_stepped () const { return strstr (hints().c_str(), ":stepped:"); }
void reset () override { set_value (default_value); }
ClapPropertyImpl (ClapDeviceImplP device, const ClapParamInfo info) :
device_ (device)
Expand All @@ -54,7 +50,7 @@ struct ClapPropertyImpl : public Property, public virtual EmittableImpl {
default_value = info.default_value;
}
ChoiceS
choices () override
choices () const override
{
const double mi = get_min(), ma = get_max();
const bool down = ma < mi;
Expand All @@ -67,8 +63,17 @@ struct ClapPropertyImpl : public Property, public virtual EmittableImpl {
}
return choices;
}
StringS
metadata () const override
{
StringS md;
md.push_back ("hints=" + ClapParamInfo::hints_from_param_info_flags (flags));
if (!module_.empty())
md.push_back ("group=" + module_);
return md;
}
double
get_normalized () override
get_normalized () const override
{
const double mi = get_min(), ma = get_max();
const double value = get_value().as_double();
Expand All @@ -82,7 +87,7 @@ struct ClapPropertyImpl : public Property, public virtual EmittableImpl {
return set_value (value);
}
String
get_text () override
get_text () const override
{
String txt;
device_->handle_->param_get_value (param_id, &txt);
Expand All @@ -94,7 +99,7 @@ struct ClapPropertyImpl : public Property, public virtual EmittableImpl {
return device_->handle_->param_set_value (param_id, vstr);
}
Value
get_value () override
get_value () const override
{
return Value (device_->handle_->param_get_value (param_id));
}
Expand Down
24 changes: 12 additions & 12 deletions ase/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -908,40 +908,40 @@ midi_driver_pref_list_choices (const CString &ident)
static Preference pcm_driver_pref =
Preference ({
"driver.pcm.devid", _("PCM Driver"), "", "auto", "ms",
{ pcm_driver_pref_list_choices }, STANDARD, "",
_("Driver and device to be used for PCM input and output"), },
{ pcm_driver_pref_list_choices }, STANDARD, {
String ("descr=") + _("Driver and device to be used for PCM input and output"), } },
[] (const CString&,const Value&) { apply_driver_preferences(); });

static Preference synth_latency_pref =
Preference ({
"driver.pcm.synth_latency", _("Synth Latency"), "", 15, "ms",
MinMaxStep { 0, 3000, 5 }, STANDARD + String ("step=5"), "",
_("Processing duration between input and output of a single sample, smaller values increase CPU load") },
MinMaxStep { 0, 3000, 5 }, STANDARD + String ("step=5"), {
String ("descr=") + _("Processing duration between input and output of a single sample, smaller values increase CPU load"), } },
[] (const CString&,const Value&) { apply_driver_preferences(); });

static Preference midi1_driver_pref =
Preference ({
"driver.midi1.devid", _("MIDI Controller (1)"), "", "auto", "ms",
{ midi_driver_pref_list_choices }, STANDARD, "",
_("MIDI controller device to be used for MIDI input"), },
{ midi_driver_pref_list_choices }, STANDARD, {
String ("descr=") + _("MIDI controller device to be used for MIDI input"), } },
[] (const CString&,const Value&) { apply_driver_preferences(); });
static Preference midi2_driver_pref =
Preference ({
"driver.midi2.devid", _("MIDI Controller (2)"), "", "auto", "ms",
{ midi_driver_pref_list_choices }, STANDARD, "",
_("MIDI controller device to be used for MIDI input"), },
{ midi_driver_pref_list_choices }, STANDARD, {
String ("descr=") + _("MIDI controller device to be used for MIDI input"), } },
[] (const CString&,const Value&) { apply_driver_preferences(); });
static Preference midi3_driver_pref =
Preference ({
"driver.midi3.devid", _("MIDI Controller (3)"), "", "auto", "ms",
{ midi_driver_pref_list_choices }, STANDARD, "",
_("MIDI controller device to be used for MIDI input"), },
{ midi_driver_pref_list_choices }, STANDARD, {
String ("descr=") + _("MIDI controller device to be used for MIDI input"), } },
[] (const CString&,const Value&) { apply_driver_preferences(); });
static Preference midi4_driver_pref =
Preference ({
"driver.midi4.devid", _("MIDI Controller (4)"), "", "auto", "ms",
{ midi_driver_pref_list_choices }, STANDARD, "",
_("MIDI controller device to be used for MIDI input"), },
{ midi_driver_pref_list_choices }, STANDARD, {
String ("descr=") + _("MIDI controller device to be used for MIDI input"), } },
[] (const CString&,const Value&) { apply_driver_preferences(); });

static void
Expand Down
10 changes: 6 additions & 4 deletions ase/gadget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ PropertyBag
GadgetImpl::property_bag ()
{
auto add_prop = [this] (const Prop &prop, CString group) {
Param param = prop.param;
if (param.group.empty() && !group.empty())
param.group = group;
this->props_.push_back (PropertyImpl::make_shared (param, prop.getter, prop.setter, prop.lister));
if (!group.empty() && prop.param.fetch ("group").empty()) {
Param param = prop.param;
param.store ("group", group);
this->props_.push_back (PropertyImpl::make_shared (param, prop.getter, prop.setter, prop.lister));
} else
this->props_.push_back (PropertyImpl::make_shared (prop.param, prop.getter, prop.setter, prop.lister));
// PropertyImpl &property = *gadget_.props_.back();
};
return PropertyBag (add_prop);
Expand Down
60 changes: 38 additions & 22 deletions ase/parameter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,26 @@ Parameter::nick () const
bool
Parameter::has (const String &key) const
{
return key == "ident" || kvpairs_search (details_, key) >= 0;
return key == "ident" || kvpairs_search (metadata_, key) >= 0;
}

String
Parameter::fetch (const String &key) const
{
return_unless (key != "ident", cident);
const ssize_t i = kvpairs_search (details_, key);
return i >= 0 ? details_[i].data() + key.size() + 1 : "";
return kvpairs_fetch (metadata_, key);
}

void
Parameter::store (const String &key, const String &value)
{
assert_return (key.size() > 0);
if (key == "ident") {
if (key == "ident")
cident = value;
return;
else {
const std::string kv = key + '=' + value;
kvpairs_assign (metadata_, kv);
}
const ssize_t i = kvpairs_search (details_, key);
const std::string kv = key + '=' + value;
if (i >= 0)
details_[i] = kv;
else
details_.push_back (kv);
}

MinMaxStep
Expand Down Expand Up @@ -319,7 +314,7 @@ Parameter::Parameter (const Param &initparam)
{
const Param &p = initparam;
cident = !p.ident.empty() ? string_to_ncname (p.ident) : string_to_ncname (p.label, '_');
details_ = p.details;
metadata_ = p.metadata;
const auto choicesfuncp = std::get_if<ChoicesFunc> (&p.extras);
MinMaxStep range;
if (const auto rangep = std::get_if<MinMaxStep> (&p.extras))
Expand All @@ -331,12 +326,6 @@ Parameter::Parameter (const Param &initparam)
store ("nick", p.nick);
if (!p.unit.empty())
store ("unit", p.unit);
if (!p.blurb.empty())
store ("blurb", p.blurb);
if (!p.descr.empty())
store ("descr", p.descr);
if (!p.group.empty())
store ("group", p.group);
const auto choicesp = std::get_if<ChoiceS> (&p.extras);
bool isbool = false;
if (choicesfuncp)
Expand Down Expand Up @@ -427,10 +416,37 @@ ParameterMap::Entry::operator= (const Param &param)
warning ("%s: duplicate %s: '%s' (param_id=%u)", FUNC, "label", param.label, id);
}
}
Param mparam = param;
if (mparam.group.empty())
mparam.group = map.group;
pmap[id] = std::make_shared<Parameter> (mparam);
if (!map.group.empty() && param.fetch ("group").empty()) {
Param mparam = param;
mparam.store ("group", map.group);
pmap[id] = std::make_shared<Parameter> (mparam);
} else
pmap[id] = std::make_shared<Parameter> (param);
}

// == Property ==
String
Property::hints () const
{
return kvpairs_fetch (metadata(), "hints");
}

String
Property::blurb () const
{
return kvpairs_fetch (metadata(), "blurb");
}

String
Property::descr () const
{
return kvpairs_fetch (metadata(), "descr");
}

String
Property::group () const
{
return kvpairs_fetch (metadata(), "group");
}

// == guess_nick ==
Expand Down
43 changes: 20 additions & 23 deletions ase/parameter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ struct Param {
String unit; ///< Units of the values within range.
ExtraVals extras; ///< Min, max, stepping for double ranges or array of choices to select from.
String hints; ///< Hints for parameter handling.
String blurb; ///< Short description for user interface tooltips.
String descr; ///< Elaborate description for help dialogs.
String group; ///< Group for parameters of similar function.
StringS details; ///< Array of "key=value" pairs.
StringS metadata; ///< Array of "key=value" pairs.
String fetch (const String &key) const { return kvpairs_fetch (metadata, key); }
void store (const String &key, const String &v) { kvpairs_assign (metadata, key + '=' + v); }
static inline const String STORAGE = ":r:w:S:";
static inline const String STANDARD = ":r:w:S:G:";
};
Expand All @@ -55,6 +54,7 @@ struct Parameter {
Value initial () const { return initial_; }
bool has_hint (const String &hint) const;
ChoiceS choices () const;
const StringS metadata () const { return metadata_; }
MinMaxStep range () const; ///< Min, max, stepping for double ranges.
bool is_numeric () const;
bool is_choice () const { return has_hint ("choice"); }
Expand All @@ -75,7 +75,7 @@ struct Parameter {
static size_t match_choice (const ChoiceS &choices, const String &text);
private:
using ExtrasV = std::variant<MinMaxStep,ChoiceS,ChoicesFunc>;
StringS details_;
StringS metadata_;
ExtrasV extras_;
Value initial_ = 0;
};
Expand All @@ -100,27 +100,24 @@ class ParameterProperty : public EmittableImpl, public virtual Property {
protected:
ParameterC parameter_;
public:
String ident () override { return parameter_->cident; }
String label () override { return parameter_->label(); }
String nick () override { return parameter_->nick(); }
String unit () override { return parameter_->unit(); }
String hints () override { return parameter_->hints(); }
String blurb () override { return parameter_->blurb(); }
String descr () override { return parameter_->descr(); }
String group () override { return parameter_->group(); }
double get_min () override { return std::get<0> (parameter_->range()); }
double get_max () override { return std::get<1> (parameter_->range()); }
double get_step () override { return std::get<2> (parameter_->range()); }
bool is_numeric () override { return parameter_->is_numeric(); }
ChoiceS choices () override { return parameter_->choices(); }
void reset () override { set_value (parameter_->initial()); }
double get_normalized () override { return !is_numeric() ? 0 : parameter_->normalize (get_double()); }
String ident () const override { return parameter_->cident; }
String label () const override { return parameter_->label(); }
String nick () const override { return parameter_->nick(); }
String unit () const override { return parameter_->unit(); }
double get_min () const override { return std::get<0> (parameter_->range()); }
double get_max () const override { return std::get<1> (parameter_->range()); }
double get_step () const override { return std::get<2> (parameter_->range()); }
bool is_numeric () const override { return parameter_->is_numeric(); }
ChoiceS choices () const override { return parameter_->choices(); }
StringS metadata () const override { return parameter_->metadata(); }
void reset () override { set_value (parameter_->initial()); }
double get_normalized () const override { return !is_numeric() ? 0 : parameter_->normalize (get_double()); }
bool set_normalized (double v) override { return is_numeric() && set_value (parameter_->rescale (v)); }
String get_text () override { return parameter_->value_to_text (get_value()); }
String get_text () const override { return parameter_->value_to_text (get_value()); }
bool set_text (String txt) override { set_value (parameter_->value_from_text (txt)); return !txt.empty(); }
Value get_value () override = 0;
Value get_value () const override = 0;
bool set_value (const Value &v) override = 0;
double get_double () { return !is_numeric() ? 0 : get_value().as_double(); }
double get_double () const { return !is_numeric() ? 0 : get_value().as_double(); }
ParameterC parameter () const { return parameter_; }
Value initial () const { return parameter_->initial(); }
MinMaxStep range () const { return parameter_->range(); }
Expand Down
Loading

0 comments on commit 5f06a6d

Please sign in to comment.