From c3543cffce9ae1a9161f178f9aa2b8f972821c75 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 19 Dec 2024 01:00:38 +0100 Subject: [PATCH] Workaround for vector_shared_ptr_templated serialization mess. --- src/midi-node.h | 9 +++++++-- src/node-handle.h | 2 +- src/state-io.h | 33 +++++++-------------------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/midi-node.h b/src/midi-node.h index 7b8623c..5128f67 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -6,7 +6,6 @@ #include "node-handle.h" #include "node.h" #include "raylib.h" -#include "raymath.h" #include "state.h" #include #include @@ -404,6 +403,12 @@ namespace VISEQ::GRAPH::NODES { friend void to_json(json& j, const MidiNode& N){ std::vector conns; std::ranges::transform(N.connections.begin(), N.connections.end(), std::back_inserter(conns), [](VISEQ::GRAPH::EDGES::SPTR_Edge e){ return e->id;}); + std::map noteHandles; + //std::ranges::transform(N.midiNoteHandles.begin(), N.midiNoteHandles.end(), std::back_inserter(noteHandles), [](std::shared_ptr> n){ return n->position;}); + for(auto i : N.midiNoteHandles){ + noteHandles.insert(std::make_pair(i->name, i->position)); + } + j = json{ {"id", N.id}, {"position", N.position}, @@ -415,7 +420,7 @@ namespace VISEQ::GRAPH::NODES { {"midiPitchBend", N.midiPitchBend}, {"midiAftertouch", N.midiAftertouch}, {"midiPolyPressure", N.midiPolyPressure}, - //{"midiNoteHandle", N.midiNoteHandles}, + {"midiNoteHandle", noteHandles}, /*{"midiCCHandle", N.midiCCHandles},*/ /*{"midiPCHandle", N.midiPCHandles},*/ /*{"midiPitchBendHandle", N.midiPitchBendHandles},*/ diff --git a/src/node-handle.h b/src/node-handle.h index b2e5885..0d076cc 100644 --- a/src/node-handle.h +++ b/src/node-handle.h @@ -131,6 +131,6 @@ namespace VISEQ::GRAPH::NODES{ /*friend void to_json(json& j, const NodeHandle& N){*/ /* j = json{{"position",N.position}};*/ /*}*/ - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NodeHandle, position, name); + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NodeHandle, position, name); }; } diff --git a/src/state-io.h b/src/state-io.h index 6a88351..3eb260d 100644 --- a/src/state-io.h +++ b/src/state-io.h @@ -35,31 +35,11 @@ namespace nlohmann { } } }; - - /**/ + /*template */ - /*struct adl_serializer>> {*/ - /* template< typename J> */ - /* static void to_json(J& j, const std::shared_ptr>& opt) {*/ - /* if (opt) {*/ - /* j = *opt;*/ - /* } else {*/ - /* j = nullptr;*/ - /* }*/ - /* }*/ - /* template< typename J>*/ - /* static void from_json(const J& j, std::shared_ptr>& opt) {*/ - /* if (j.is_null()) {*/ - /* opt = nullptr;*/ - /* } else {*/ - /* opt.reset(new NODES::NodeHandle(j.template get>()));*/ - /* }*/ - /* }*/ - /*};*/ - - /*template class S, typename T>*/ - /*struct adl_serializer>> {*/ - /* static void to_json(json& j, const std::shared_ptr>& opt) {*/ + /*struct adl_serializer> {*/ + /* template */ + /* static void to_json(J& j, const std::shared_ptr& opt) {*/ /* if (opt) {*/ /* j = *opt;*/ /* } else {*/ @@ -67,11 +47,12 @@ namespace nlohmann { /* }*/ /* }*/ /**/ - /* static void from_json(const json& j, std::shared_ptr>& opt) {*/ + /* template */ + /* static void from_json(const J& j, std::shared_ptr& opt) {*/ /* if (j.is_null()) {*/ /* opt = nullptr;*/ /* } else {*/ - /* opt.reset(new S(j.get>()));*/ + /* opt.reset(new T(j.template get()));*/ /* }*/ /* }*/ /*};*/