Browse Source

Fix serialization for unbounded Params.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
cdf7a2bbfa
4 changed files with 21 additions and 39 deletions
  1. +1
    -1
      helper.py
  2. +0
    -3
      include/engine/Param.hpp
  3. +20
    -7
      src/engine/Module.cpp
  4. +0
    -28
      src/engine/Param.cpp

+ 1
- 1
helper.py View File

@@ -8,7 +8,7 @@ import xml.etree.ElementTree




# Version check # Version check
f"Python 3.6 is required"
f"Python 3.6+ is required"




class UserException(Exception): class UserException(Exception):


+ 0
- 3
include/engine/Param.hpp View File

@@ -19,9 +19,6 @@ struct Param {
void setValue(float value) { void setValue(float value) {
this->value = value; this->value = value;
} }

json_t *toJson();
void fromJson(json_t *rootJ);
}; };






+ 20
- 7
src/engine/Module.cpp View File

@@ -34,9 +34,14 @@ json_t *Module::toJson() {


// params // params
json_t *paramsJ = json_array(); json_t *paramsJ = json_array();
for (Param &param : 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); json_object_set_new(rootJ, "params", paramsJ);


@@ -67,7 +72,7 @@ void Module::fromJson(json_t *rootJ) {
size_t i; size_t i;
json_t *paramJ; json_t *paramJ;
json_array_foreach(paramsJ, i, paramJ) { json_array_foreach(paramsJ, i, paramJ) {
uint32_t paramId = i;
size_t paramId = i;
// Get paramId // Get paramId
// Legacy v0.6.0 to <v1.0 // Legacy v0.6.0 to <v1.0
json_t *paramIdJ = json_object_get(paramJ, "paramId"); json_t *paramIdJ = json_object_get(paramJ, "paramId");
@@ -75,9 +80,17 @@ void Module::fromJson(json_t *rootJ) {
paramId = json_integer_value(paramIdJ); paramId = json_integer_value(paramIdJ);
} }


if (paramId < params.size()) {
params[paramId].fromJson(paramJ);
}
// Check ID bounds
if (paramId >= 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 // bypass


+ 0
- 28
src/engine/Param.cpp View File

@@ -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

Loading…
Cancel
Save