From cdf7a2bbfaf4b7731dab3e5936ab9e90e48e9167 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 14 May 2019 09:54:24 -0400 Subject: [PATCH] Fix serialization for unbounded Params. --- helper.py | 2 +- include/engine/Param.hpp | 3 --- src/engine/Module.cpp | 27 ++++++++++++++++++++------- src/engine/Param.cpp | 28 ---------------------------- 4 files changed, 21 insertions(+), 39 deletions(-) delete mode 100644 src/engine/Param.cpp diff --git a/helper.py b/helper.py index 0dae63e5..39e4ca0b 100755 --- a/helper.py +++ b/helper.py @@ -8,7 +8,7 @@ import xml.etree.ElementTree # Version check -f"Python 3.6 is required" +f"Python 3.6+ is required" class UserException(Exception): diff --git a/include/engine/Param.hpp b/include/engine/Param.hpp index 1a77d40c..e4de4a20 100644 --- a/include/engine/Param.hpp +++ b/include/engine/Param.hpp @@ -19,9 +19,6 @@ struct Param { void setValue(float value) { this->value = value; } - - json_t *toJson(); - void fromJson(json_t *rootJ); }; diff --git a/src/engine/Module.cpp b/src/engine/Module.cpp index 3f51fdd2..7ccebe8e 100644 --- a/src/engine/Module.cpp +++ b/src/engine/Module.cpp @@ -34,9 +34,14 @@ json_t *Module::toJson() { // params json_t *paramsJ = json_array(); - for (Param ¶m : params) { - json_t *paramJ = param.toJson(); - json_array_append_new(paramsJ, paramJ); + for (size_t paramId = 0; paramId < params.size(); paramId++) { + float value = params[paramId].getValue(); + // Set value to 0 if param is unbounded + if (!paramQuantities[paramId]->isBounded()) + value = 0.f; + + json_t *paramJ = json_real(value); + json_array_insert_new(paramsJ, paramId, paramJ); } json_object_set_new(rootJ, "params", paramsJ); @@ -67,7 +72,7 @@ void Module::fromJson(json_t *rootJ) { size_t i; json_t *paramJ; json_array_foreach(paramsJ, i, paramJ) { - uint32_t paramId = i; + size_t paramId = i; // Get paramId // Legacy v0.6.0 to = params.size()) + continue; + + // Check that param is bounded + if (!paramQuantities[paramId]->isBounded()) + continue; + + json_t *valueJ = json_object_get(rootJ, "value"); + if (valueJ) + params[paramId].setValue(json_number_value(valueJ)); } // bypass diff --git a/src/engine/Param.cpp b/src/engine/Param.cpp deleted file mode 100644 index b69a5f42..00000000 --- a/src/engine/Param.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "engine/Param.hpp" -#include "random.hpp" -#include "math.hpp" - - -namespace rack { -namespace engine { - - -json_t *Param::toJson() { - json_t *rootJ = json_object(); - - // TODO Handle unbounded case - json_object_set_new(rootJ, "value", json_real(value)); - - return rootJ; -} - -void Param::fromJson(json_t *rootJ) { - // TODO Handle unbounded case - json_t *valueJ = json_object_get(rootJ, "value"); - if (valueJ) - value = json_number_value(valueJ); -} - - -} // namespace engine -} // namespace rack