Config nodes not working yet, but everything is prepared.

This commit is contained in:
Sebastian
2024-12-08 02:25:57 +01:00
parent d9c97be326
commit 558829f619
7 changed files with 177 additions and 159 deletions
+7 -94
View File
@@ -5,7 +5,6 @@
#include "graph-item.h"
#include "node.h"
#include "edge.h"
//#include "graph-manager.h"
#include "datatypes.h"
#include "signal.h"
@@ -13,11 +12,6 @@
#include <iostream>
#include <memory>
/*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;
@@ -58,7 +52,7 @@ namespace VISEQ::GRAPH::EDGES {
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>()));
}
@@ -68,55 +62,10 @@ 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.getNotes().channel},
{"midi_note",N.getNotes().note},
{"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){
std::cout << "MidiNode" << std::endl;
j.at("id").get_to(N.id);
j.at("position").get_to<Vec2Df>(N.position);
j.at("distributionMode").get_to(N.distributionMode);
j.at("nodeType").get_to(N.nodeType);
j.at("midi_note_channel").get_to(N.getNotes().channel);
j.at("midi_note").get_to(N.getNotes().note);
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>()));
}
@@ -127,45 +76,11 @@ namespace VISEQ::GRAPH::NODES {
/* ----------------- CONFIG NODE -----------------*/
inline void to_json(json& j, const ConfigNode& 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.getNotes().channel},
{"midi_note",N.getNotes().note},
{"midi_cc_channel",N.midiCC.channel},
{"midi_cc",N.midiCC.value},
{"midi_pitch_bend_channel",N.midiPitchBend.channel},
{"midi_pitch_bend",N.midiPitchBend.value},
{"connections",conns}};
}
inline void from_json(const json& j, ConfigNode& N){
std::cout << "ConfigNode" << std::endl;
j.at("id").get_to(N.id);
j.at("position").get_to<Vec2Df>(N.position);
j.at("distributionMode").get_to(N.distributionMode);
j.at("nodeType").get_to(N.nodeType);
j.at("midi_note_channel").get_to(N.getNotes().channel);
j.at("midi_note").get_to(N.getNotes().note);
j.at("midi_cc_channel").get_to(N.midiCC.channel);
j.at("midi_cc").get_to(N.midiCC.value);
j.at("midi_pitch_bend_channel").get_to(N.midiPitchBend.channel);
j.at("midi_pitch_bend").get_to(N.midiPitchBend.value);
//j.at("connections").get_to(N.connections);
}
inline void to_json(json& j, const std::shared_ptr<ConfigNode>& N){
j = *N;
}
inline void from_json(const json& j, std::shared_ptr<ConfigNode>& N){
N.reset(new ConfigNode(j.get<ConfigNode>()));
}
@@ -185,11 +100,9 @@ namespace VISEQ::GRAPH::NODES {
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>();
}
if(j.at("nodeType") == NodeType::CONFIGNODE){
std::cout << j.at("nodeType") << std::endl;
N = j.template get<ConfigNode>();
}
}
@@ -197,7 +110,7 @@ namespace VISEQ::GRAPH::NODES {
inline void to_json(json& j, const SPTR_Node& N){
j = *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>()));
@@ -229,11 +142,11 @@ namespace VISEQ::BASE{
inline void from_json(const json& j, Movable& G){
std::cout << "Movable" << std::endl;
// j = json{{"position", G.position}};
j.at("position").get_to<Vec2Df>(G.position);
}
inline void from_json(json& j, const std::shared_ptr<Movable>& G){
// j = *G;
j = *G;
}
}
@@ -263,7 +176,7 @@ namespace VISEQ::SIGNAL{
inline void to_json(json& j, const std::shared_ptr<Signal>& G){
j = *G;
}
inline void from_json(const json& j, std::shared_ptr<Signal>& S){
S.reset(new Signal(j.get<Signal>()));
}