#pragma once #include "config-node.h" #include "midi-node.h" #include "graph-item.h" #include "node-handle.h" #include "node.h" #include "edge.h" #include "datatypes.h" #include "signal.h" #include #include typedef std::shared_ptr SPTR_GraphItem; typedef std::vector VEC_SPTR_GraphItem; namespace nlohmann { template struct adl_serializer> { static void to_json(json& j, const std::shared_ptr& opt) { if (opt) { j = *opt; } else { j = nullptr; } } static void from_json(const json& j, std::shared_ptr& opt) { if (j.is_null()) { opt = nullptr; } else { opt.reset(new T(j.get())); } } }; /*template */ /*struct adl_serializer> {*/ /* template */ /* static void to_json(J& j, const std::shared_ptr& opt) {*/ /* if (opt) {*/ /* j = *opt;*/ /* } else {*/ /* j = nullptr;*/ /* }*/ /* }*/ /**/ /* template */ /* static void from_json(const J& j, std::shared_ptr& opt) {*/ /* if (j.is_null()) {*/ /* opt = nullptr;*/ /* } else {*/ /* opt.reset(new T(j.template get()));*/ /* }*/ /* }*/ /*};*/ } namespace VISEQ::GRAPH::EDGES { using namespace VISEQ::GRAPH::NODES; inline void to_json(json& j, const VISEQ::GRAPH::EDGES::Edge& E){ j = json{{"id",E.id}, {"start", E.start.lock()->id}, {"end",E.end.lock()->id}, {"pass_forward",E.pass_forward}, {"pass_backward", E.pass_backward}}; } inline void from_json(const json& j, Edge& E){ j.at("id").get_to(E.id); j.at("pass_forward").get_to(E.pass_forward); j.at("pass_backward").get_to(E.pass_backward); } inline void to_json(json& j, const VISEQ::GRAPH::EDGES::SPTR_Edge& E){ j = *E; } inline void from_json(const json& j, VISEQ::GRAPH::EDGES::SPTR_Edge& E){ E.reset(new Edge(j.get())); } } namespace VISEQ::GRAPH::NODES { /* ------------------- MIDINODE ---------------------- */ /*inline void to_json(json& j, const std::shared_ptr& N){*/ /* j = *N;*/ /*}*/ /**/ /*inline void from_json(const json& j, std::shared_ptr& N){*/ /* N.reset(new MidiNode(j.get()));*/ /*}*/ inline void to_json(json& j, const MidiNode::NodeMidiOut& MO){ j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}}; } /*template< typename T>*/ /*inline void to_json(json& j, const std::shared_ptr>& NH){*/ /* j = json{{"position", NH->position}};*/ /*}*/ /* ----------------- CONFIG NODE -----------------*/ /*inline void to_json(json& j, const std::shared_ptr& N){*/ /* j = *N;*/ /*}*/ /**/ /*inline void from_json(const json& j, std::shared_ptr& N){*/ /* N.reset(new ConfigNode(j.get()));*/ /*}*/ /* ------------------- NODE ---------------------- */ inline void to_json(json& j, const Node& N){ if(N.getNodeType() == NodeType::MIDINODE){ j = dynamic_cast(N); } if(N.getNodeType() == NodeType::CONFIGNODE){ j = dynamic_cast(N); } } inline void from_json(const json& j, Node& N){ if(j.at("nodeType") == NodeType::MIDINODE){ N = j.template get(); } if(j.at("nodeType") == NodeType::CONFIGNODE){ N = j.template get(); } } inline void to_json(json& j, const SPTR_Node& N){ j = *N; } inline void from_json(const json& j, std::shared_ptr& N){ std::cout << "SPTR_Node" << std::endl; if(N->getNodeType() == NodeType::MIDINODE){ N.reset(new MidiNode(j.get())); } if(N->getNodeType() == NodeType::CONFIGNODE){ N.reset(new ConfigNode(j.get())); } } } namespace VISEQ::GRAPH { inline void to_json(json& j, const GraphItem& G){ std::cout << "Movable" << std::endl; j = json{{"id", G.id}, {"type", G.gItemType}}; } inline void to_json(json& j, const SPTR_GraphItem& G){ j = *G; } } namespace VISEQ::BASE{ inline void to_json(json& j, const Movable& G){ std::cout << "Movable" << std::endl; j = json{{"position", G.position}}; } inline void to_json(json& j, const std::shared_ptr& G){ j = *G; } inline void from_json(const json& j, Movable& G){ std::cout << "Movable" << std::endl; j.at("position").get_to(G.position); } inline void from_json(json& j, const std::shared_ptr& G){ j = *G; } } namespace VISEQ::SIGNAL{ inline void to_json(json& j, const Signal& G){ std::map fc = {{"r",G.color.r},{"g",G.color.g},{"b",G.color.b},{"a",G.color.a}}; j = json{{"color",fc},{"position", G.position},{"radius",G.radius},{"start",G.start.lock()->id},{"next",G.next.lock()->id},{"last",G.last.lock()->id},{"speed",G.speed},{"midi_note_offset",G.midi_note_offset},{"midi_cc_offset",G.midi_cc_offset},{"multiplier",G.multiplier}}; } inline void from_json(const json& j, Signal& S){ Color c; c.r = j.at("color")["r"].get(); c.g = j.at("color")["g"].get(); c.b = j.at("color")["b"].get(); c.a = j.at("color")["a"].get(); j.at("position").get_to(S.position); j.at("speed").get_to(S.speed); j.at("radius").get_to(S.radius); j.at("midi_note_offset").get_to(S.midi_note_offset); j.at("midi_cc_offset").get_to(S.midi_cc_offset); S.color = c; } inline void to_json(json& j, const std::shared_ptr& G){ j = *G; } inline void from_json(const json& j, std::shared_ptr& S){ S.reset(new Signal(j.get())); } }