Use definitions in Boards for pots/sliders config
This commit is contained in:
@@ -24,7 +24,12 @@
|
||||
#include "generalsettings.h"
|
||||
#include <string.h>
|
||||
|
||||
template <unsigned int N, const YamlLookupTable& name_lut>
|
||||
struct YamlStickLookup {
|
||||
static int name2idx(const std::string& name);
|
||||
static std::string idx2name(unsigned int idx);
|
||||
};
|
||||
|
||||
template <unsigned int N, class name_lookup>
|
||||
struct YamlNameConfig {
|
||||
char name[N][HARDWARE_NAME_LEN + 1];
|
||||
|
||||
@@ -41,19 +46,17 @@ struct YamlNameConfig {
|
||||
}
|
||||
};
|
||||
|
||||
extern const YamlLookupTable sticksLut;
|
||||
typedef YamlNameConfig<CPN_MAX_SWITCHES, sticksLut> YamlStickConfig;
|
||||
typedef YamlNameConfig<CPN_MAX_SWITCHES, YamlStickLookup> YamlStickConfig;
|
||||
|
||||
template <unsigned int N, const YamlLookupTable& name_lut,
|
||||
const YamlLookupTable& cfg_lut>
|
||||
struct YamlKnobConfig : public YamlNameConfig<N, name_lut> {
|
||||
template <unsigned int N, class name_lookup, const YamlLookupTable& cfg_lut>
|
||||
struct YamlKnobConfig : public YamlNameConfig<N, name_lookup> {
|
||||
unsigned int config[N];
|
||||
|
||||
YamlKnobConfig() { memset(config, 0, sizeof(config)); }
|
||||
|
||||
YamlKnobConfig(const char in_names[N][HARDWARE_NAME_LEN + 1],
|
||||
const unsigned int in_configs[N]) :
|
||||
YamlNameConfig<N, name_lut>(in_names)
|
||||
YamlNameConfig<N, name_lookup>(in_names)
|
||||
{
|
||||
memcpy(config, in_configs, sizeof(config));
|
||||
}
|
||||
@@ -61,7 +64,7 @@ struct YamlKnobConfig : public YamlNameConfig<N, name_lut> {
|
||||
void copy(char out_names[N][HARDWARE_NAME_LEN + 1],
|
||||
unsigned int out_configs[N])
|
||||
{
|
||||
YamlNameConfig<N, name_lut>::copy(out_names);
|
||||
YamlNameConfig<N, name_lookup>::copy(out_names);
|
||||
memcpy(out_configs, config, sizeof(config));
|
||||
}
|
||||
};
|
||||
@@ -69,71 +72,89 @@ struct YamlKnobConfig : public YamlNameConfig<N, name_lut> {
|
||||
// SA:
|
||||
// type: 3pos
|
||||
// name:
|
||||
extern const YamlLookupTable switchesLut;
|
||||
struct YamlSwitchLookup {
|
||||
static int name2idx(const std::string& name);
|
||||
static std::string idx2name(unsigned int idx);
|
||||
};
|
||||
extern const YamlLookupTable switchConfigLut;
|
||||
typedef YamlKnobConfig<CPN_MAX_SWITCHES, switchesLut, switchConfigLut>
|
||||
typedef YamlKnobConfig<CPN_MAX_SWITCHES, YamlSwitchLookup, switchConfigLut>
|
||||
YamlSwitchConfig;
|
||||
|
||||
// S1:
|
||||
// type: with_detent
|
||||
// name:
|
||||
extern const YamlLookupTable potsLut;
|
||||
struct YamlPotLookup {
|
||||
static int name2idx(const std::string& name);
|
||||
static std::string idx2name(unsigned int idx);
|
||||
};
|
||||
extern const YamlLookupTable potConfigLut;
|
||||
typedef YamlKnobConfig<CPN_MAX_POTS, potsLut, potConfigLut> YamlPotConfig;
|
||||
typedef YamlKnobConfig<CPN_MAX_POTS, YamlPotLookup, potConfigLut> YamlPotConfig;
|
||||
|
||||
// S1:
|
||||
// type: with_detent
|
||||
// name:
|
||||
extern const YamlLookupTable slidersLut;
|
||||
struct YamlSliderLookup {
|
||||
static int name2idx(const std::string& name);
|
||||
static std::string idx2name(unsigned int idx);
|
||||
};
|
||||
extern const YamlLookupTable sliderConfigLut;
|
||||
typedef YamlKnobConfig<CPN_MAX_SLIDERS, slidersLut, sliderConfigLut>
|
||||
typedef YamlKnobConfig<CPN_MAX_SLIDERS, YamlSliderLookup, sliderConfigLut>
|
||||
YamlSliderConfig;
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
template <unsigned int N, const YamlLookupTable& name_lut>
|
||||
struct convert<YamlNameConfig<N, name_lut> > {
|
||||
static Node encode(const YamlNameConfig<N, name_lut>& rhs)
|
||||
template <unsigned int N, class name_lookup>
|
||||
struct convert<YamlNameConfig<N, name_lookup> > {
|
||||
static Node encode(const YamlNameConfig<N, name_lookup>& rhs)
|
||||
{
|
||||
Node node;
|
||||
for (const auto& kv : name_lut) {
|
||||
node[kv.second]["name"] = rhs.name[kv.first];
|
||||
for (unsigned int i=0; i<N; i++) {
|
||||
std::string name = name_lookup::idx2name(i);
|
||||
if (!name.empty()) {
|
||||
node[name]["name"] = rhs.name[i];
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
static bool decode(const Node& node, YamlNameConfig<N, name_lut>& rhs)
|
||||
static bool decode(const Node& node, YamlNameConfig<N, name_lookup>& rhs)
|
||||
{
|
||||
if (!node.IsMap()) return false;
|
||||
int idx = 0;
|
||||
for (const auto& kv : node) {
|
||||
kv.first >> name_lut >> idx;
|
||||
kv.second["name"] >> rhs.name[idx];
|
||||
idx = name_lookup::name2idx(kv.first.Scalar());
|
||||
if (idx >= 0) {
|
||||
kv.second["name"] >> rhs.name[idx];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <unsigned int N, const YamlLookupTable& name_lut,
|
||||
const YamlLookupTable& cfg_lut>
|
||||
struct convert<YamlKnobConfig<N, name_lut, cfg_lut> > {
|
||||
static Node encode(const YamlKnobConfig<N, name_lut, cfg_lut>& rhs)
|
||||
template <unsigned int N, class name_lookup, const YamlLookupTable& cfg_lut>
|
||||
struct convert<YamlKnobConfig<N, name_lookup, cfg_lut> > {
|
||||
static Node encode(const YamlKnobConfig<N, name_lookup, cfg_lut>& rhs)
|
||||
{
|
||||
Node node;
|
||||
for (const auto& kv : name_lut) {
|
||||
node[kv.second]["type"] = cfg_lut << rhs.config[kv.first];
|
||||
node[kv.second]["name"] = rhs.name[kv.first];
|
||||
for (unsigned int i=0; i<N; i++) {
|
||||
std::string name = name_lookup::idx2name(i);
|
||||
if (!name.empty()) {
|
||||
node[name]["type"] = cfg_lut << rhs.config[i];
|
||||
node[name]["name"] = rhs.name[i];
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
static bool decode(const Node& node,
|
||||
YamlKnobConfig<N, name_lut, cfg_lut>& rhs)
|
||||
YamlKnobConfig<N, name_lookup, cfg_lut>& rhs)
|
||||
{
|
||||
if (!node.IsMap()) return false;
|
||||
int idx = 0;
|
||||
for (const auto& kv : node) {
|
||||
kv.first >> name_lut >> idx;
|
||||
kv.second["type"] >> cfg_lut >> rhs.config[idx];
|
||||
kv.second["name"] >> rhs.name[idx];
|
||||
idx = name_lookup::name2idx(kv.first.Scalar());
|
||||
if (idx >= 0) {
|
||||
kv.second["type"] >> cfg_lut >> rhs.config[idx];
|
||||
kv.second["name"] >> rhs.name[idx];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user