mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-05 21:55:24 +00:00
Added precision to ISchema::DoubleEntry
This commit is contained in:
parent
b2f4f7fde6
commit
157071ed9d
@ -71,6 +71,7 @@ namespace musik { namespace core { namespace sdk {
|
|||||||
Entry entry;
|
Entry entry;
|
||||||
double minValue;
|
double minValue;
|
||||||
double maxValue;
|
double maxValue;
|
||||||
|
int precision;
|
||||||
double defaultValue;
|
double defaultValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -141,7 +142,7 @@ namespace musik { namespace core { namespace sdk {
|
|||||||
const std::string& name,
|
const std::string& name,
|
||||||
int defaultValue,
|
int defaultValue,
|
||||||
int min = INT_MIN,
|
int min = INT_MIN,
|
||||||
int max = INT_MAX)
|
int max = INT_MAX)
|
||||||
{
|
{
|
||||||
auto entry = new IntEntry();
|
auto entry = new IntEntry();
|
||||||
entry->entry.type = ISchema::Type::Int;
|
entry->entry.type = ISchema::Type::Int;
|
||||||
@ -154,8 +155,9 @@ namespace musik { namespace core { namespace sdk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TSchema& AddDouble(
|
TSchema& AddDouble(
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
double defaultValue,
|
double defaultValue,
|
||||||
|
int precision = 2,
|
||||||
double min = DBL_MIN,
|
double min = DBL_MIN,
|
||||||
double max = DBL_MAX)
|
double max = DBL_MAX)
|
||||||
{
|
{
|
||||||
@ -163,6 +165,7 @@ namespace musik { namespace core { namespace sdk {
|
|||||||
entry->entry.type = ISchema::Type::Double;
|
entry->entry.type = ISchema::Type::Double;
|
||||||
entry->entry.name = AllocString(name);
|
entry->entry.name = AllocString(name);
|
||||||
entry->defaultValue = defaultValue;
|
entry->defaultValue = defaultValue;
|
||||||
|
entry->precision = precision;
|
||||||
entry->minValue = min;
|
entry->minValue = min;
|
||||||
entry->maxValue = max;
|
entry->maxValue = max;
|
||||||
entries.push_back(reinterpret_cast<Entry*>(entry));
|
entries.push_back(reinterpret_cast<Entry*>(entry));
|
||||||
@ -181,7 +184,7 @@ namespace musik { namespace core { namespace sdk {
|
|||||||
TSchema& AddEnum(
|
TSchema& AddEnum(
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::vector<std::string>&& values,
|
const std::vector<std::string>&& values,
|
||||||
const std::string& defaultValue)
|
const std::string& defaultValue)
|
||||||
{
|
{
|
||||||
auto entry = new EnumEntry();
|
auto entry = new EnumEntry();
|
||||||
entry->entry.type = ISchema::Type::Enum;
|
entry->entry.type = ISchema::Type::Enum;
|
||||||
@ -211,7 +214,11 @@ namespace musik { namespace core { namespace sdk {
|
|||||||
|
|
||||||
const char* AllocString(const std::string& str) {
|
const char* AllocString(const std::string& str) {
|
||||||
char* result = new char[str.size() + 1];
|
char* result = new char[str.size() + 1];
|
||||||
|
#ifdef WIN32
|
||||||
|
strncpy_s(result, str.size() + 1, str.c_str(), str.size());
|
||||||
|
#else
|
||||||
strncpy(result, str.c_str(), str.size());
|
strncpy(result, str.c_str(), str.size());
|
||||||
|
#endif
|
||||||
result[str.size()] = 0;
|
result[str.size()] = 0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -91,10 +91,11 @@ static std::function<std::string(int)> INT_FORMATTER =
|
|||||||
return std::to_string(value);
|
return std::to_string(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::function<std::string(double)> DOUBLE_FORMATTER =
|
static std::function<std::string(double)> doubleFormatter(int precision) {
|
||||||
[](double value) -> std::string {
|
return [precision](double value) -> std::string {
|
||||||
return stringValueForDouble(value);
|
return stringValueForDouble(value, precision);
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool bounded(T minimum, T maximum) {
|
bool bounded(T minimum, T maximum) {
|
||||||
@ -129,8 +130,12 @@ static std::string stringValueFor(
|
|||||||
return prefs->GetBool(name, DEFAULT(BoolEntry)) ? "true" : "false";
|
return prefs->GetBool(name, DEFAULT(BoolEntry)) ? "true" : "false";
|
||||||
case ISchema::Type::Int:
|
case ISchema::Type::Int:
|
||||||
return std::to_string(prefs->GetInt(name, DEFAULT(IntEntry)));
|
return std::to_string(prefs->GetInt(name, DEFAULT(IntEntry)));
|
||||||
case ISchema::Type::Double:
|
case ISchema::Type::Double: {
|
||||||
return stringValueForDouble(prefs->GetDouble(name, DEFAULT(DoubleEntry)));
|
auto doubleEntry = reinterpret_cast<const ISchema::DoubleEntry*>(entry);
|
||||||
|
auto defaultValue = doubleEntry->defaultValue;
|
||||||
|
auto precision = doubleEntry->precision;
|
||||||
|
return stringValueForDouble(prefs->GetDouble(name, defaultValue), precision);
|
||||||
|
}
|
||||||
case ISchema::Type::String:
|
case ISchema::Type::String:
|
||||||
return prefs->GetString(name, DEFAULT(StringEntry));
|
return prefs->GetString(name, DEFAULT(StringEntry));
|
||||||
case ISchema::Type::Enum:
|
case ISchema::Type::Enum:
|
||||||
@ -334,11 +339,13 @@ class SchemaAdapter: public ScrollAdapterBase {
|
|||||||
void ShowDoubleOverlay(const ISchema::DoubleEntry* entry) {
|
void ShowDoubleOverlay(const ISchema::DoubleEntry* entry) {
|
||||||
auto name = entry->entry.name;
|
auto name = entry->entry.name;
|
||||||
|
|
||||||
|
auto formatter = doubleFormatter(entry->precision);
|
||||||
|
|
||||||
auto title = numberInputTitle(
|
auto title = numberInputTitle(
|
||||||
name, entry->minValue, entry->maxValue, DOUBLE_FORMATTER);
|
name, entry->minValue, entry->maxValue, formatter);
|
||||||
|
|
||||||
auto validator = std::make_shared<NumberValidator<double>>(
|
auto validator = std::make_shared<NumberValidator<double>>(
|
||||||
entry->minValue, entry->maxValue, DOUBLE_FORMATTER);
|
entry->minValue, entry->maxValue, formatter);
|
||||||
|
|
||||||
auto width = std::max(u8cols(title) + 4, DEFAULT_INPUT_WIDTH);
|
auto width = std::max(u8cols(title) + 4, DEFAULT_INPUT_WIDTH);
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ extern "C" DLLEXPORT void SetPreferences(IPreferences* prefs) {
|
|||||||
|
|
||||||
extern "C" DLLEXPORT musik::core::sdk::ISchema* GetSchema() {
|
extern "C" DLLEXPORT musik::core::sdk::ISchema* GetSchema() {
|
||||||
auto schema = new TSchema<>();
|
auto schema = new TSchema<>();
|
||||||
schema->AddDouble(PREF_MULTIPLIER, 1.0, 0.25, 1000.0);
|
schema->AddDouble(PREF_MULTIPLIER, 1.0, 2, 0.25, 1000.0);
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user