partial reload from json working, but edges make problems

This commit is contained in:
Sebastian
2024-11-03 15:15:42 +01:00
parent 7bdd68bdcc
commit bfd8bb192e
5 changed files with 46 additions and 26 deletions
+1 -1
View File
@@ -3,4 +3,4 @@ build/**
viseq viseq
viseq.exe viseq.exe
compile_commands.json compile_commands.json
state.json *.json
+1 -1
View File
@@ -284,6 +284,6 @@ namespace VISEQ::GRAPH {
} }
inline void from_json(const json& j, GraphManager& G){ 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<VEC_SPTR_Node>(G.nodes); // = json{{"nodes", G.nodes}, {"edges", G.edges}};
} }
} }
+21 -3
View File
@@ -7,6 +7,7 @@
*/ */
#include "graph-manager.h" #include "graph-manager.h"
#include "node.h"
#include "vmath.h" #include "vmath.h"
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@@ -82,7 +83,24 @@ int main(){
std::ifstream f("state.json"); std::ifstream f("state.json");
json graph = json::parse(f); json graph = json::parse(f);
app.gm = graph["graphmanager"].template get<VISEQ::GRAPH::GraphManager>(); // app.gm = graph["graphmanager"].get<VISEQ::GRAPH::GraphManager>();
for(auto n : graph.at("graphmanager").at("nodes")){
std::shared_ptr<MidiNode> mn = n;
app.gm.nodes.push_back(mn);
/*app.gm.addMidiNode(n.at("position").get<Vec2Df>());*/
/*app.gm.nodes.back().midi_note_channel = n.at("midi_note_channel").get<int>();*/
}
for(auto e : graph.at("graphmanager").at("edges")){
int start_id = e.at("start").get<int>();
int end_id = e.at("end").get<int>();
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>();
VEC_SPTR_Node end = app.gm.nodes | RANGE_FILTER([end_id](SPTR_Node n){return n->id == end_id;}) | std::ranges::to<VEC_SPTR_Node>();
if(!start.empty() && !end.empty()) app.gm.addConnection(start.front(), end.front());
}
} else { } else {
for(int i = 0; i < 4; ++i){ for(int i = 0; i < 4; ++i){
@@ -403,8 +421,8 @@ int main(){
EndDrawing(); EndDrawing();
} }
std::ofstream file("state.json"); //std::ofstream file("state.json");
file << json(app); //file << json(app);
std::cout << std::setw(4) << json(app) << std::endl; std::cout << std::setw(4) << json(app) << std::endl;
+19 -19
View File
@@ -69,8 +69,10 @@ namespace VISEQ::GRAPH::NODES {
} }
inline void from_json(const json& j, MidiNode& N){ inline void from_json(const json& j, MidiNode& N){
std::cout << "MidiNode" << std::endl;
j.at("id").get_to(N.id); j.at("id").get_to(N.id);
j.at("position").get_to(N.position); j.at("position").get_to<Vec2Df>(N.position);
j.at("distributionMode").get_to(N.distributionMode); j.at("distributionMode").get_to(N.distributionMode);
j.at("nodeType").get_to(N.nodeType); j.at("nodeType").get_to(N.nodeType);
j.at("midi_note_channel").get_to(N.midi_note_channel); j.at("midi_note_channel").get_to(N.midi_note_channel);
@@ -95,6 +97,10 @@ namespace VISEQ::GRAPH::NODES {
N.reset(new MidiNode(j.get<MidiNode>())); N.reset(new MidiNode(j.get<MidiNode>()));
} }
inline void to_json(json& j, const MidiNode::NodeMidiOut& MO){
j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}};
}
/* ------------------- NODE ---------------------- */ /* ------------------- NODE ---------------------- */
@@ -111,23 +117,14 @@ namespace VISEQ::GRAPH::NODES {
std::cout << j.at("nodeType") << std::endl; std::cout << j.at("nodeType") << std::endl;
N = j.template get<MidiNode>(); N = j.template get<MidiNode>();
} }
/*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){ inline void to_json(json& j, const SPTR_Node& N){
j = *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<Node>& N){ inline void from_json(const json& j, std::shared_ptr<Node>& N){
std::cout << "SPTR_Node" << std::endl;
N.reset(new Node(j.get<Node>())); N.reset(new Node(j.get<Node>()));
} }
@@ -136,6 +133,7 @@ namespace VISEQ::GRAPH::NODES {
namespace VISEQ::GRAPH { namespace VISEQ::GRAPH {
inline void to_json(json& j, const GraphItem& G){ inline void to_json(json& j, const GraphItem& G){
std::cout << "Movable" << std::endl;
j = json{{"id", G.id}, {"type", G.graphItemType}}; j = json{{"id", G.id}, {"type", G.graphItemType}};
} }
@@ -146,12 +144,22 @@ namespace VISEQ::GRAPH {
namespace VISEQ::BASE{ namespace VISEQ::BASE{
inline void to_json(json& j, const Movable& G){ inline void to_json(json& j, const Movable& G){
std::cout << "Movable" << std::endl;
j = json{{"position", G.position}}; j = json{{"position", G.position}};
} }
inline void to_json(json& j, const std::shared_ptr<Movable>& G){ inline void to_json(json& j, const std::shared_ptr<Movable>& G){
j = *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<Movable>& G){
// j = *G;
}
} }
namespace VISEQ::SIGNAL{ namespace VISEQ::SIGNAL{
@@ -163,11 +171,3 @@ namespace VISEQ::SIGNAL{
j = *G; j = *G;
} }
} }
namespace VISEQ::MIDI {
inline void to_json(json& j, const MidiOutPort MO){
j = json{{"port_id", MO.number}, {"enabled", MO.enabled}};
}
}
+4 -2
View File
@@ -2,6 +2,7 @@
#include "raylib.h" #include "raylib.h"
#include <cmath> #include <cmath>
#include <iostream>
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
@@ -107,12 +108,13 @@ namespace VISEQ::VMATH{
}; };
template<typename T> template<typename T>
void to_json(json& j, const Vec2D<T> V){ void to_json(json& j, const Vec2D<T>& V){
j = json{{"x",V.x},{"y",V.y}}; j = json{{"x",V.x},{"y",V.y}};
} }
template<typename T> template<typename T>
void from_json(const json& j, Vec2D<T> V){ void from_json(const json& j, Vec2D<T>& V){
std::cout << "Vec2D" << std::endl;
j.at("x").get_to(V.x); j.at("x").get_to(V.x);
j.at("y").get_to(V.y); j.at("y").get_to(V.y);
} }