Skip to content

Commit

Permalink
Patch: Export node IDs to json sequentially
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Jan 11, 2024
1 parent 5732366 commit 5979770
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions source/src/patch/patch-spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ std::string PatchSpec::to_json()
std::vector<Json::object> patch_inputs;
std::vector<Json::object> patch_buffer_inputs;

for (auto pair : nodespecs)
// Iterate over node pairs, ordered by node ID
int nodespec_count = nodespecs.size();
for (auto nodespec_index = 0; nodespec_index < nodespec_count; nodespec_index++)
{
PatchNodeSpec *spec = pair.second;
PatchNodeSpec *spec = nodespecs[nodespec_index];
Json::object inputs;
Json::object properties;

Expand Down Expand Up @@ -282,8 +284,6 @@ std::string PatchSpec::to_json()
nodes.push_back(object);
}

std::reverse(nodes.begin(), nodes.end());

Json::object root;
root["name"] = this->name;
root["nodes"] = nodes;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self):
patch = TestPatch()
spec = patch.to_spec()
spec_json = spec.to_json()
ref_json = '{"buffer_inputs": [], "inputs": [], "name": "", "nodes": [{"id": 4, "inputs": {"attack": 0.1, "curve": 1, "release": 0.1, "sustain": 0.5}, "node": "asr-envelope"}, {"id": 2, "inputs": {"frequency": 440}, "node": "sine"}, {"id": 1, "inputs": {"input0": {"id": 2}, "input1": {"id": 4}}, "node": "multiply"}, {"id": 0, "inputs": {"input": {"id": 1}, "pan": 0}, "is_output": true, "node": "stereo-panner"}]}'
ref_json = '{"buffer_inputs": [], "inputs": [], "name": "", "nodes": [{"id": 0, "inputs": {"input": {"id": 1}, "pan": 0}, "is_output": true, "node": "stereo-panner"}, {"id": 1, "inputs": {"input0": {"id": 2}, "input1": {"id": 4}}, "node": "multiply"}, {"id": 2, "inputs": {"frequency": 440}, "node": "sine"}, {"id": 4, "inputs": {"attack": 0.1, "curve": 1, "release": 0.1, "sustain": 0.5}, "node": "asr-envelope"}]}'

#--------------------------------------------------------------------------------
# Can't simply compare the to_json output to the ref_json, as ordering of objects
Expand All @@ -112,4 +112,4 @@ def __init__(self):
#--------------------------------------------------------------------------------
spec_json_deserialised = json.loads(spec_json)
ref_json_deserialised = json.loads(ref_json)
assert spec_json_deserialised == ref_json_deserialised
assert spec_json_deserialised == ref_json_deserialised

0 comments on commit 5979770

Please sign in to comment.