diff --git a/include/engine/Param.hpp b/include/engine/Param.hpp index 9931ff64..04261c99 100644 --- a/include/engine/Param.hpp +++ b/include/engine/Param.hpp @@ -1,6 +1,4 @@ #pragma once -#include - #include #include @@ -20,9 +18,6 @@ struct Param { void setValue(float value) { this->value = value; } - - json_t* toJson(); - void fromJson(json_t* rootJ); }; diff --git a/include/engine/ParamQuantity.hpp b/include/engine/ParamQuantity.hpp index f6eb722a..c3e6b7e2 100644 --- a/include/engine/ParamQuantity.hpp +++ b/include/engine/ParamQuantity.hpp @@ -1,6 +1,8 @@ #pragma once #include +#include + #include #include @@ -80,6 +82,9 @@ struct ParamQuantity : Quantity { void randomize() override; virtual std::string getDescription(); + + virtual json_t* toJson(); + virtual void fromJson(json_t* rootJ); }; diff --git a/src/engine/Module.cpp b/src/engine/Module.cpp index 9bea267f..36062ae0 100644 --- a/src/engine/Module.cpp +++ b/src/engine/Module.cpp @@ -189,12 +189,12 @@ void Module::fromJson(json_t* rootJ) { json_t* Module::paramsToJson() { json_t* rootJ = json_array(); - for (size_t paramId = 0; paramId < params.size(); paramId++) { + for (size_t paramId = 0; paramId < paramQuantities.size(); paramId++) { // Don't serialize unbounded Params if (!paramQuantities[paramId]->isBounded()) continue; - json_t* paramJ = params[paramId].toJson(); + json_t* paramJ = paramQuantities[paramId]->toJson(); json_object_set_new(paramJ, "id", json_integer(paramId)); @@ -221,7 +221,7 @@ void Module::paramsFromJson(json_t* rootJ) { paramId = i; // Check ID bounds - if (paramId >= params.size()) + if (paramId >= paramQuantities.size()) continue; // Check that the Param is bounded @@ -230,7 +230,7 @@ void Module::paramsFromJson(json_t* rootJ) { json_t* valueJ = json_object_get(paramJ, "value"); if (valueJ) - params[paramId].setValue(json_number_value(valueJ)); + paramQuantities[paramId]->setValue(json_number_value(valueJ)); } } diff --git a/src/engine/Param.cpp b/src/engine/Param.cpp deleted file mode 100644 index 3de75df1..00000000 --- a/src/engine/Param.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - - -namespace rack { -namespace engine { - - -json_t* Param::toJson() { - json_t* rootJ = json_object(); - json_object_set_new(rootJ, "value", json_real(value)); - return rootJ; -} - - -void Param::fromJson(json_t* rootJ) { - json_t* valueJ = json_object_get(rootJ, "value"); - if (valueJ) - value = json_number_value(valueJ); -} - - -} // namespace engine -} // namespace rack diff --git a/src/engine/ParamQuantity.cpp b/src/engine/ParamQuantity.cpp index 45d4f8f6..d4a90aa8 100644 --- a/src/engine/ParamQuantity.cpp +++ b/src/engine/ParamQuantity.cpp @@ -147,6 +147,20 @@ std::string ParamQuantity::getDescription() { } +json_t* ParamQuantity::toJson() { + json_t* rootJ = json_object(); + json_object_set_new(rootJ, "value", json_real(getValue())); + return rootJ; +} + + +void ParamQuantity::fromJson(json_t* rootJ) { + json_t* valueJ = json_object_get(rootJ, "value"); + if (valueJ) + setValue(json_number_value(valueJ)); +} + + std::string SwitchQuantity::getDisplayValueString() { int index = (int) std::floor(getValue()); if (!(0 <= index && index < (int) labels.size()))