Improve quicktune feature a bit

This commit is contained in:
sfan5 2024-12-11 14:42:42 +01:00
parent 33b8307119
commit 612d4f9656
2 changed files with 39 additions and 35 deletions

@ -13,6 +13,8 @@ std::string QuicktuneValue::getString()
return "(none)";
case QVT_FLOAT:
return ftos(value_QVT_FLOAT.current);
case QVT_INT:
return itos(value_QVT_INT.current);
}
return "<invalid type>";
}
@ -22,14 +24,21 @@ void QuicktuneValue::relativeAdd(float amount)
switch(type){
case QVT_NONE:
break;
case QVT_FLOAT:
value_QVT_FLOAT.current += amount * (value_QVT_FLOAT.max - value_QVT_FLOAT.min);
if(value_QVT_FLOAT.current > value_QVT_FLOAT.max)
value_QVT_FLOAT.current = value_QVT_FLOAT.max;
if(value_QVT_FLOAT.current < value_QVT_FLOAT.min)
value_QVT_FLOAT.current = value_QVT_FLOAT.min;
case QVT_FLOAT: {
float &v = value_QVT_FLOAT.current;
v += amount * (value_QVT_FLOAT.max - value_QVT_FLOAT.min);
v = core::clamp(v, value_QVT_FLOAT.min, value_QVT_FLOAT.max);
break;
}
case QVT_INT: {
int &v = value_QVT_INT.current;
int diff = std::floor(amount * (value_QVT_INT.max - value_QVT_INT.min));
if (!diff)
diff = amount < 0 ? -1 : 1;
v = core::clamp(v + diff, value_QVT_INT.min, value_QVT_INT.max);
break;
}
}
}
static std::map<std::string, QuicktuneValue> g_values;
@ -44,12 +53,9 @@ const std::vector<std::string> &getQuicktuneNames()
QuicktuneValue getQuicktuneValue(const std::string &name)
{
MutexAutoLock lock(g_mutex);
std::map<std::string, QuicktuneValue>::iterator i = g_values.find(name);
if(i == g_values.end()){
QuicktuneValue val;
val.type = QVT_NONE;
return val;
}
auto i = g_values.find(name);
if (i == g_values.end())
return QuicktuneValue();
return i->second;
}
@ -70,9 +76,9 @@ void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
return;
}
QuicktuneValue &ref = i->second;
if(ref.modified)
if (ref.modified) {
val = ref;
else{
} else {
ref = val;
ref.modified = false;
}

@ -39,17 +39,19 @@
enum QuicktuneValueType {
QVT_NONE,
QVT_FLOAT
QVT_FLOAT,
QVT_INT
};
struct QuicktuneValue
{
QuicktuneValueType type = QVT_NONE;
union {
struct {
float current;
float min;
float max;
float current, min, max;
} value_QVT_FLOAT;
struct {
int current, min, max;
} value_QVT_INT;
};
bool modified = false;
@ -65,8 +67,7 @@ void setQuicktuneValue(const std::string &name, const QuicktuneValue &val);
void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
#ifndef NDEBUG
#define QUICKTUNE(type_, var, min_, max_, name){\
#define QUICKTUNE(type_, var, min_, max_, name) do { \
QuicktuneValue qv; \
qv.type = type_; \
qv.value_##type_.current = var; \
@ -74,10 +75,7 @@ void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
qv.value_##type_.max = max_; \
updateQuicktuneValue(name, qv); \
var = qv.value_##type_.current; \
}
#else // NDEBUG
#define QUICKTUNE(type, var, min_, max_, name){}
#endif
} while (0)
#define QUICKTUNE_AUTONAME(type_, var, min_, max_)\
QUICKTUNE(type_, var, min_, max_, #var)