json is loading, but does nothing yet
This commit is contained in:
+153
-77
@@ -4,94 +4,170 @@
|
||||
#include "graph-item.h"
|
||||
#include "node.h"
|
||||
#include "edge.h"
|
||||
#include "graph-manager.h"
|
||||
//#include "graph-manager.h"
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "signal.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
/*namespace nlohmann { */
|
||||
/* template <typename T>*/
|
||||
/* struct adl_serializer<std::shared_ptr<T>> {*/
|
||||
/* static void to_json(json& j, const std::shared_ptr<T>& opt){*/
|
||||
/* if (opt)*/
|
||||
/* {*/
|
||||
/* j = *opt;*/
|
||||
/* }*/
|
||||
/* else*/
|
||||
/* {*/
|
||||
/* j = nullptr;*/
|
||||
/* }*/
|
||||
/* }*/
|
||||
/**/
|
||||
/* static void from_json(const json& j, std::shared_ptr<T>& opt){*/
|
||||
/* if (j.is_null())*/
|
||||
/* {*/
|
||||
/* opt = nullptr;*/
|
||||
/* }*/
|
||||
/* else*/
|
||||
/* {*/
|
||||
/* opt.reset(new T(j.get<T>()));*/
|
||||
/* //opt = j.get<T>();*/
|
||||
/* }*/
|
||||
/* }*/
|
||||
/* };*/
|
||||
/*}*/
|
||||
/*using namespace VISEQ::BASE;*/
|
||||
/*using namespace VISEQ::SIGNAL;*/
|
||||
/*using namespace VISEQ::GRAPH::NODES;*/
|
||||
/*using namespace VISEQ::GRAPH::EDGES;*/
|
||||
|
||||
typedef std::shared_ptr<VISEQ::GRAPH::GraphItem> SPTR_GraphItem;
|
||||
typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;
|
||||
|
||||
namespace VISEQ::GRAPH::EDGES {
|
||||
using namespace VISEQ::GRAPH::NODES;
|
||||
|
||||
inline void to_json(json& j, const Edge& E){
|
||||
j = json{{"id",E.id}, {"start", E.start->id}, {"end",E.end->id}, {"pass_forward",E.pass_forward}, {"pass_backward", E.pass_backward}};
|
||||
}
|
||||
inline void to_json(json& j, const VISEQ::GRAPH::EDGES::Edge& E){
|
||||
j = json{{"id",E.id}, {"start", E.start->id}, {"end",E.end->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 SPTR_Edge& E){
|
||||
j = *E;
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const MidiNode& N){
|
||||
std::vector<int> conns;
|
||||
std::ranges::transform(N.connections.begin(), N.connections.end(), std::back_inserter(conns), [](SPTR_Edge e){ return e->id;});
|
||||
j = json{{"id", N.id}, {"position", N.position}, {"distributionMode", N.distributionMode},
|
||||
{"midi_note_channel",N.midi_note_channel},
|
||||
{"midi_velocity",N.midi_velocity},
|
||||
{"midi_gatel",N.midi_gate},
|
||||
{"midi_cc_channel",N.midi_cc_channel},
|
||||
{"midi_cc",N.midi_cc},
|
||||
{"midi_cc_value",N.midi_cc_value},
|
||||
{"midi_pc_channel",N.midi_pc_channel},
|
||||
{"midi_pc_value",N.midi_pc_value},
|
||||
{"midi_pitch_bend_channel",N.midi_pitch_bend_channel},
|
||||
{"midi_pitch_bend",N.midi_pitch_bend},
|
||||
{"connections",conns}};
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const std::shared_ptr<MidiNode>& N){
|
||||
j = *N;
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const GraphItem& G){
|
||||
j = json{{"id", G.id}, {"type", G.graphItemType}};
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const SPTR_GraphItem& G){
|
||||
j = *G;
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const MidiOutPort MO){
|
||||
j = json{{"port_id", MO.number}, {"enabled", MO.enabled}};
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const NodeMidiOut MO){
|
||||
j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}};
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const Node& N){
|
||||
if(N.nodeType == NodeType::MIDINODE){
|
||||
j = dynamic_cast<const MidiNode&>(N);
|
||||
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<Edge>()));
|
||||
}
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const std::shared_ptr<Node>& N){
|
||||
j = *N;
|
||||
namespace VISEQ::GRAPH::NODES {
|
||||
|
||||
/* ------------------- MIDINODE ---------------------- */
|
||||
|
||||
inline void to_json(json& j, const MidiNode& N){
|
||||
std::vector<int> conns;
|
||||
std::ranges::transform(N.connections.begin(), N.connections.end(), std::back_inserter(conns), [](VISEQ::GRAPH::EDGES::SPTR_Edge e){ return e->id;});
|
||||
|
||||
j = json{
|
||||
{"id", N.id},
|
||||
{"position", N.position},
|
||||
{"distributionMode", N.distributionMode},
|
||||
{"nodeType", N.nodeType},
|
||||
{"midi_note_channel",N.midi_note_channel},
|
||||
{"midi_velocity",N.midi_velocity},
|
||||
{"midi_gate",N.midi_gate},
|
||||
{"midi_cc_channel",N.midi_cc_channel},
|
||||
{"midi_cc",N.midi_cc},
|
||||
{"midi_cc_value",N.midi_cc_value},
|
||||
{"midi_pc_channel",N.midi_pc_channel},
|
||||
{"midi_pc_value",N.midi_pc_value},
|
||||
{"midi_pitch_bend_channel",N.midi_pitch_bend_channel},
|
||||
{"midi_pitch_bend",N.midi_pitch_bend},
|
||||
{"connections",conns}};
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, MidiNode& N){
|
||||
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("midi_note_channel").get_to(N.midi_note_channel);
|
||||
j.at("midi_velocity").get_to(N.midi_velocity);
|
||||
j.at("midi_gate").get_to(N.midi_gate);
|
||||
j.at("midi_cc_channel").get_to(N.midi_cc_channel);
|
||||
j.at("midi_cc").get_to(N.midi_cc);
|
||||
j.at("midi_cc_value").get_to(N.midi_cc_value);
|
||||
j.at("midi_pc_channel").get_to(N.midi_pc_channel);
|
||||
j.at("midi_pc_value").get_to(N.midi_pc_value);
|
||||
j.at("midi_pitch_bend_channel").get_to(N.midi_pitch_bend_channel);
|
||||
j.at("midi_pitch_bend").get_to(N.midi_pitch_bend);
|
||||
|
||||
//j.at("connections").get_to(N.connections);
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const std::shared_ptr<MidiNode>& N){
|
||||
j = *N;
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, std::shared_ptr<MidiNode>& N){
|
||||
N.reset(new MidiNode(j.get<MidiNode>()));
|
||||
}
|
||||
|
||||
|
||||
/* ------------------- NODE ---------------------- */
|
||||
|
||||
|
||||
inline void to_json(json& j, const Node& N){
|
||||
if(N.getNodeType() == NodeType::MIDINODE){
|
||||
j = dynamic_cast<const MidiNode&>(N);
|
||||
}
|
||||
}
|
||||
|
||||
inline void from_json(const json& j, Node& N){
|
||||
|
||||
if(j.at("nodeType") == NodeType::MIDINODE){
|
||||
std::cout << j.at("nodeType") << std::endl;
|
||||
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){
|
||||
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){
|
||||
N.reset(new Node(j.get<Node>()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace VISEQ::GRAPH {
|
||||
inline void to_json(json& j, const GraphItem& G){
|
||||
j = json{{"id", G.id}, {"type", G.graphItemType}};
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const SPTR_GraphItem& G){
|
||||
j = *G;
|
||||
}
|
||||
}
|
||||
|
||||
namespace VISEQ::BASE{
|
||||
inline void to_json(json& j, const Movable& G){
|
||||
j = json{{"position", G.position}};
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const std::shared_ptr<Movable>& G){
|
||||
j = *G;
|
||||
}
|
||||
}
|
||||
|
||||
namespace VISEQ::SIGNAL{
|
||||
inline void to_json(json& j, const Signal& G){
|
||||
j = json{{"position", G.position},{"start",G.start->id},{"speed",G.speed}};
|
||||
}
|
||||
|
||||
inline void to_json(json& j, const std::shared_ptr<Signal>& G){
|
||||
j = *G;
|
||||
}
|
||||
}
|
||||
|
||||
namespace VISEQ::MIDI {
|
||||
inline void to_json(json& j, const MidiOutPort MO){
|
||||
j = json{{"port_id", MO.number}, {"enabled", MO.enabled}};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user