diff --git a/src/core/sdk/ISchema.h b/src/core/sdk/ISchema.h index a7db7b245..36d5916b8 100644 --- a/src/core/sdk/ISchema.h +++ b/src/core/sdk/ISchema.h @@ -71,6 +71,7 @@ namespace musik { namespace core { namespace sdk { Entry entry; double minValue; double maxValue; + int precision; double defaultValue; }; @@ -141,7 +142,7 @@ namespace musik { namespace core { namespace sdk { const std::string& name, int defaultValue, int min = INT_MIN, - int max = INT_MAX) + int max = INT_MAX) { auto entry = new IntEntry(); entry->entry.type = ISchema::Type::Int; @@ -154,8 +155,9 @@ namespace musik { namespace core { namespace sdk { } TSchema& AddDouble( - const std::string& name, - double defaultValue, + const std::string& name, + double defaultValue, + int precision = 2, double min = DBL_MIN, double max = DBL_MAX) { @@ -163,6 +165,7 @@ namespace musik { namespace core { namespace sdk { entry->entry.type = ISchema::Type::Double; entry->entry.name = AllocString(name); entry->defaultValue = defaultValue; + entry->precision = precision; entry->minValue = min; entry->maxValue = max; entries.push_back(reinterpret_cast(entry)); @@ -181,7 +184,7 @@ namespace musik { namespace core { namespace sdk { TSchema& AddEnum( const std::string& name, const std::vector&& values, - const std::string& defaultValue) + const std::string& defaultValue) { auto entry = new EnumEntry(); entry->entry.type = ISchema::Type::Enum; @@ -211,7 +214,11 @@ namespace musik { namespace core { namespace sdk { const char* AllocString(const std::string& str) { 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()); +#endif result[str.size()] = 0; return result; } diff --git a/src/musikcube/app/overlay/PluginOverlay.cpp b/src/musikcube/app/overlay/PluginOverlay.cpp index 364fea6a2..89a2380ce 100644 --- a/src/musikcube/app/overlay/PluginOverlay.cpp +++ b/src/musikcube/app/overlay/PluginOverlay.cpp @@ -91,10 +91,11 @@ static std::function INT_FORMATTER = return std::to_string(value); }; -static std::function DOUBLE_FORMATTER = -[](double value) -> std::string { - return stringValueForDouble(value); -}; +static std::function doubleFormatter(int precision) { + return [precision](double value) -> std::string { + return stringValueForDouble(value, precision); + }; +} template bool bounded(T minimum, T maximum) { @@ -129,8 +130,12 @@ static std::string stringValueFor( return prefs->GetBool(name, DEFAULT(BoolEntry)) ? "true" : "false"; case ISchema::Type::Int: return std::to_string(prefs->GetInt(name, DEFAULT(IntEntry))); - case ISchema::Type::Double: - return stringValueForDouble(prefs->GetDouble(name, DEFAULT(DoubleEntry))); + case ISchema::Type::Double: { + auto doubleEntry = reinterpret_cast(entry); + auto defaultValue = doubleEntry->defaultValue; + auto precision = doubleEntry->precision; + return stringValueForDouble(prefs->GetDouble(name, defaultValue), precision); + } case ISchema::Type::String: return prefs->GetString(name, DEFAULT(StringEntry)); case ISchema::Type::Enum: @@ -334,11 +339,13 @@ class SchemaAdapter: public ScrollAdapterBase { void ShowDoubleOverlay(const ISchema::DoubleEntry* entry) { auto name = entry->entry.name; + auto formatter = doubleFormatter(entry->precision); + auto title = numberInputTitle( - name, entry->minValue, entry->maxValue, DOUBLE_FORMATTER); + name, entry->minValue, entry->maxValue, formatter); auto validator = std::make_shared>( - entry->minValue, entry->maxValue, DOUBLE_FORMATTER); + entry->minValue, entry->maxValue, formatter); auto width = std::max(u8cols(title) + 4, DEFAULT_INPUT_WIDTH); diff --git a/src/plugins/nullout/NullOut.cpp b/src/plugins/nullout/NullOut.cpp index 113418bf6..3e3b3fe4c 100644 --- a/src/plugins/nullout/NullOut.cpp +++ b/src/plugins/nullout/NullOut.cpp @@ -66,7 +66,7 @@ extern "C" DLLEXPORT void SetPreferences(IPreferences* prefs) { extern "C" DLLEXPORT musik::core::sdk::ISchema* GetSchema() { 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; }