diff --git a/.gitignore b/.gitignore index ec5578d..7326a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ build/** viseq viseq.exe compile_commands.json -state.json +*.json diff --git a/src/graph-manager.h b/src/graph-manager.h index d6f61b2..72aa4ff 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -284,6 +284,6 @@ namespace VISEQ::GRAPH { } inline void from_json(const json& j, GraphManager& G){ - j.at("nodes").get_to(G.nodes); // = json{{"nodes", G.nodes}, {"edges", G.edges}}; + j.at("nodes").template get_to(G.nodes); // = json{{"nodes", G.nodes}, {"edges", G.edges}}; } } diff --git a/src/main.cpp b/src/main.cpp index 213fae1..13b7091 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ */ #include "graph-manager.h" +#include "node.h" #include "vmath.h" #include #include @@ -82,7 +83,24 @@ int main(){ std::ifstream f("state.json"); json graph = json::parse(f); - app.gm = graph["graphmanager"].template get(); +// app.gm = graph["graphmanager"].get(); + for(auto n : graph.at("graphmanager").at("nodes")){ + std::shared_ptr mn = n; + app.gm.nodes.push_back(mn); + /*app.gm.addMidiNode(n.at("position").get());*/ + /*app.gm.nodes.back().midi_note_channel = n.at("midi_note_channel").get();*/ + } + + for(auto e : graph.at("graphmanager").at("edges")){ + int start_id = e.at("start").get(); + int end_id = e.at("end").get(); + + VEC_SPTR_Node start = app.gm.nodes | RANGE_FILTER([start_id](SPTR_Node n){return n->id == start_id;}) | std::ranges::to(); + VEC_SPTR_Node end = app.gm.nodes | RANGE_FILTER([end_id](SPTR_Node n){return n->id == end_id;}) | std::ranges::to(); + + if(!start.empty() && !end.empty()) app.gm.addConnection(start.front(), end.front()); + + } } else { for(int i = 0; i < 4; ++i){ @@ -403,8 +421,8 @@ int main(){ EndDrawing(); } - std::ofstream file("state.json"); - file << json(app); + //std::ofstream file("state.json"); + //file << json(app); std::cout << std::setw(4) << json(app) << std::endl; diff --git a/src/state-io.h b/src/state-io.h index 0ba95ab..f2ac1ab 100644 --- a/src/state-io.h +++ b/src/state-io.h @@ -69,8 +69,10 @@ namespace VISEQ::GRAPH::NODES { } inline void from_json(const json& j, MidiNode& N){ + std::cout << "MidiNode" << std::endl; + j.at("id").get_to(N.id); - j.at("position").get_to(N.position); + j.at("position").get_to(N.position); j.at("distributionMode").get_to(N.distributionMode); j.at("nodeType").get_to(N.nodeType); j.at("midi_note_channel").get_to(N.midi_note_channel); @@ -94,6 +96,10 @@ namespace VISEQ::GRAPH::NODES { 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}}; + } /* ------------------- NODE ---------------------- */ @@ -111,23 +117,14 @@ namespace VISEQ::GRAPH::NODES { std::cout << j.at("nodeType") << std::endl; N = j.template get(); } - - /*j.at("id").get_to(N.id);*/ - /*j.at("position").get_to(N.position);*/ - /*j.at("distributionMode").get_to(N.distributionMode);*/ - /*j.at("nodeType").get_to(N.nodeType);*/ - //j.at("connections").get_to(N.connections); } inline void to_json(json& j, const SPTR_Node& N){ j = *N; } - - inline void to_json(json& j, const MidiNode::NodeMidiOut MO){ - j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}}; - } inline void from_json(const json& j, std::shared_ptr& N){ + std::cout << "SPTR_Node" << std::endl; N.reset(new Node(j.get())); } @@ -136,6 +133,7 @@ namespace VISEQ::GRAPH::NODES { namespace VISEQ::GRAPH { inline void to_json(json& j, const GraphItem& G){ + std::cout << "Movable" << std::endl; j = json{{"id", G.id}, {"type", G.graphItemType}}; } @@ -146,12 +144,22 @@ namespace VISEQ::GRAPH { 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 = json{{"position", G.position}}; + } + + inline void from_json(json& j, const std::shared_ptr& G){ + // j = *G; + } } namespace VISEQ::SIGNAL{ @@ -163,11 +171,3 @@ namespace VISEQ::SIGNAL{ j = *G; } } - -namespace VISEQ::MIDI { - inline void to_json(json& j, const MidiOutPort MO){ - j = json{{"port_id", MO.number}, {"enabled", MO.enabled}}; - } -} - - diff --git a/src/vmath.h b/src/vmath.h index 3a23c46..c944a03 100644 --- a/src/vmath.h +++ b/src/vmath.h @@ -2,6 +2,7 @@ #include "raylib.h" #include +#include #include "nlohmann/json.hpp" @@ -107,12 +108,13 @@ namespace VISEQ::VMATH{ }; template - void to_json(json& j, const Vec2D V){ + void to_json(json& j, const Vec2D& V){ j = json{{"x",V.x},{"y",V.y}}; } template - void from_json(const json& j, Vec2D V){ + void from_json(const json& j, Vec2D& V){ + std::cout << "Vec2D" << std::endl; j.at("x").get_to(V.x); j.at("y").get_to(V.y); }