2024-11-02 23:12:38 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-12-07 03:44:03 +01:00
|
|
|
#include "config-node.h"
|
2024-11-02 23:12:38 +01:00
|
|
|
#include "midi-node.h"
|
|
|
|
|
#include "graph-item.h"
|
|
|
|
|
#include "node.h"
|
|
|
|
|
#include "edge.h"
|
|
|
|
|
|
|
|
|
|
#include "datatypes.h"
|
2024-11-03 03:48:49 +01:00
|
|
|
#include "signal.h"
|
2024-11-02 23:12:38 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
#include <iostream>
|
2024-11-02 23:12:38 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
typedef std::shared_ptr<VISEQ::GRAPH::GraphItem> SPTR_GraphItem;
|
|
|
|
|
typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;
|
2024-11-02 23:12:38 +01:00
|
|
|
|
2024-12-05 00:01:42 +01:00
|
|
|
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>()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-12-04 01:43:06 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
namespace VISEQ::GRAPH::EDGES {
|
|
|
|
|
using namespace VISEQ::GRAPH::NODES;
|
2024-11-02 23:12:38 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
inline void to_json(json& j, const VISEQ::GRAPH::EDGES::Edge& E){
|
2024-12-03 01:25:49 +01:00
|
|
|
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}};
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2024-11-02 23:12:38 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
inline void to_json(json& j, const VISEQ::GRAPH::EDGES::SPTR_Edge& E){
|
|
|
|
|
j = *E;
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
inline void from_json(const json& j, VISEQ::GRAPH::EDGES::SPTR_Edge& E){
|
|
|
|
|
E.reset(new Edge(j.get<Edge>()));
|
|
|
|
|
}
|
2024-11-02 23:12:38 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
namespace VISEQ::GRAPH::NODES {
|
|
|
|
|
|
|
|
|
|
/* ------------------- MIDINODE ---------------------- */
|
|
|
|
|
|
|
|
|
|
inline void to_json(json& j, const std::shared_ptr<MidiNode>& N){
|
|
|
|
|
j = *N;
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
inline void from_json(const json& j, std::shared_ptr<MidiNode>& N){
|
|
|
|
|
N.reset(new MidiNode(j.get<MidiNode>()));
|
|
|
|
|
}
|
2024-11-03 15:15:42 +01:00
|
|
|
|
|
|
|
|
inline void to_json(json& j, const MidiNode::NodeMidiOut& MO){
|
|
|
|
|
j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}};
|
|
|
|
|
}
|
2024-11-03 03:48:49 +01:00
|
|
|
|
2024-12-07 03:44:03 +01:00
|
|
|
/* ----------------- CONFIG NODE -----------------*/
|
2024-11-03 03:48:49 +01:00
|
|
|
|
2024-12-07 03:44:03 +01:00
|
|
|
|
|
|
|
|
inline void to_json(json& j, const std::shared_ptr<ConfigNode>& N){
|
|
|
|
|
j = *N;
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
|
2024-12-07 03:44:03 +01:00
|
|
|
inline void from_json(const json& j, std::shared_ptr<ConfigNode>& N){
|
|
|
|
|
N.reset(new ConfigNode(j.get<ConfigNode>()));
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
/* ------------------- NODE ---------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void to_json(json& j, const Node& N){
|
|
|
|
|
if(N.getNodeType() == NodeType::MIDINODE){
|
|
|
|
|
j = dynamic_cast<const MidiNode&>(N);
|
|
|
|
|
}
|
2024-12-07 03:44:03 +01:00
|
|
|
if(N.getNodeType() == NodeType::CONFIGNODE){
|
|
|
|
|
j = dynamic_cast<const ConfigNode&>(N);
|
|
|
|
|
}
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void from_json(const json& j, Node& N){
|
|
|
|
|
|
|
|
|
|
if(j.at("nodeType") == NodeType::MIDINODE){
|
|
|
|
|
N = j.template get<MidiNode>();
|
2024-12-07 03:44:03 +01:00
|
|
|
}
|
|
|
|
|
if(j.at("nodeType") == NodeType::CONFIGNODE){
|
|
|
|
|
N = j.template get<ConfigNode>();
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void to_json(json& j, const SPTR_Node& N){
|
|
|
|
|
j = *N;
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
inline void from_json(const json& j, std::shared_ptr<Node>& N){
|
2024-11-03 15:15:42 +01:00
|
|
|
std::cout << "SPTR_Node" << std::endl;
|
2024-11-03 03:48:49 +01:00
|
|
|
N.reset(new Node(j.get<Node>()));
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-02 23:12:38 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
|
|
|
|
|
namespace VISEQ::GRAPH {
|
|
|
|
|
inline void to_json(json& j, const GraphItem& G){
|
2024-11-03 15:15:42 +01:00
|
|
|
std::cout << "Movable" << std::endl;
|
2024-11-24 03:08:06 +01:00
|
|
|
j = json{{"id", G.id}, {"type", G.gItemType}};
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void to_json(json& j, const SPTR_GraphItem& G){
|
|
|
|
|
j = *G;
|
|
|
|
|
}
|
2024-11-02 23:12:38 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
namespace VISEQ::BASE{
|
|
|
|
|
inline void to_json(json& j, const Movable& G){
|
2024-11-03 15:15:42 +01:00
|
|
|
std::cout << "Movable" << std::endl;
|
2024-11-03 03:48:49 +01:00
|
|
|
j = json{{"position", G.position}};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void to_json(json& j, const std::shared_ptr<Movable>& G){
|
|
|
|
|
j = *G;
|
|
|
|
|
}
|
2024-11-03 15:15:42 +01:00
|
|
|
|
|
|
|
|
inline void from_json(const json& j, Movable& G){
|
|
|
|
|
std::cout << "Movable" << std::endl;
|
2024-12-08 02:25:57 +01:00
|
|
|
j.at("position").get_to<Vec2Df>(G.position);
|
2024-11-03 15:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void from_json(json& j, const std::shared_ptr<Movable>& G){
|
2024-12-08 02:25:57 +01:00
|
|
|
j = *G;
|
2024-11-03 15:15:42 +01:00
|
|
|
}
|
2024-11-02 23:12:38 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
namespace VISEQ::SIGNAL{
|
|
|
|
|
inline void to_json(json& j, const Signal& G){
|
2024-11-04 01:00:59 +01:00
|
|
|
std::map<std::string, int> fc = {{"r",G.color.r},{"g",G.color.g},{"b",G.color.b},{"a",G.color.a}};
|
2024-12-03 01:25:49 +01:00
|
|
|
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}};
|
2024-11-04 01:00:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void from_json(const json& j, Signal& S){
|
|
|
|
|
|
|
|
|
|
Color c;
|
|
|
|
|
c.r = j.at("color")["r"].get<int>();
|
|
|
|
|
c.g = j.at("color")["g"].get<int>();
|
|
|
|
|
c.b = j.at("color")["b"].get<int>();
|
|
|
|
|
c.a = j.at("color")["a"].get<int>();
|
|
|
|
|
|
|
|
|
|
j.at("position").get_to<Vec2Df>(S.position);
|
|
|
|
|
j.at("speed").get_to<float>(S.speed);
|
|
|
|
|
j.at("radius").get_to<float>(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;
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void to_json(json& j, const std::shared_ptr<Signal>& G){
|
|
|
|
|
j = *G;
|
2024-11-02 23:12:38 +01:00
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
|
2024-11-04 01:00:59 +01:00
|
|
|
inline void from_json(const json& j, std::shared_ptr<Signal>& S){
|
|
|
|
|
S.reset(new Signal(j.get<Signal>()));
|
|
|
|
|
}
|
2024-11-02 23:12:38 +01:00
|
|
|
}
|
2024-11-04 01:00:59 +01:00
|
|
|
|
|
|
|
|
|