still in the middle of json export, last attempt did not work
This commit is contained in:
+14
-45
@@ -31,54 +31,23 @@ enum Distribution {GEOMETRIC, ROUNDROBIN, RANDOM};
|
||||
|
||||
// Types
|
||||
|
||||
class GraphItem;
|
||||
class Node;
|
||||
class Edge;
|
||||
class Signal;
|
||||
/*class GraphItem;*/
|
||||
/*class Node;*/
|
||||
/*class Edge;*/
|
||||
/*class Signal;*/
|
||||
|
||||
#define RANGE_FILTER(L) std::ranges::views::filter(L)
|
||||
|
||||
typedef std::shared_ptr<GraphItem> SPTR_GraphItem;
|
||||
typedef std::shared_ptr<Node> SPTR_Node;
|
||||
typedef std::shared_ptr<Edge> SPTR_Edge;
|
||||
|
||||
typedef std::shared_ptr<Signal> SPTR_Signal;
|
||||
|
||||
typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;
|
||||
typedef std::vector<SPTR_Node> VEC_SPTR_Node;
|
||||
typedef std::vector<SPTR_Edge> VEC_SPTR_Edge;
|
||||
typedef std::vector<SPTR_Signal> VEC_SPTR_Signal;
|
||||
|
||||
using Vec2Df = VMath::Vec2D<float>;
|
||||
|
||||
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>();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*typedef std::shared_ptr<GraphItem> SPTR_GraphItem;*/
|
||||
/*typedef std::shared_ptr<Node> SPTR_Node;*/
|
||||
/*typedef std::shared_ptr<Edge> SPTR_Edge;*/
|
||||
/**/
|
||||
/*typedef std::shared_ptr<Signal> SPTR_Signal;*/
|
||||
/**/
|
||||
/*typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;*/
|
||||
/*typedef std::vector<SPTR_Node> VEC_SPTR_Node;*/
|
||||
/*typedef std::vector<SPTR_Edge> VEC_SPTR_Edge;*/
|
||||
/*typedef std::vector<SPTR_Signal> VEC_SPTR_Signal;*/
|
||||
|
||||
// App Settings
|
||||
struct AppSettings{
|
||||
|
||||
+6
-4
@@ -28,9 +28,11 @@ class Edge : public GraphItem{
|
||||
return start == origin ? end : start;
|
||||
}
|
||||
|
||||
void draw(Vec2Df mouse_pos, Camera2D cam) {
|
||||
|
||||
}
|
||||
void draw(Vec2Df mouse_pos, Camera2D cam) {}
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Edge, id, start, end, pass_forward, pass_backward)
|
||||
|
||||
/*typedef std::shared_ptr<Edge> SPTR_Edge;*/
|
||||
/*typedef std::vector<SPTR_Edge> VEC_SPTR_Edge;*/
|
||||
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Edge, id, start, end, pass_forward, pass_backward)
|
||||
|
||||
+5
-1
@@ -23,4 +23,8 @@ class GraphItem{
|
||||
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GraphItem, id, graphItemType, neighbors)
|
||||
|
||||
/*typedef std::shared_ptr<GraphItem> SPTR_GraphItem;*/
|
||||
/*typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;*/
|
||||
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GraphItem, id, graphItemType, neighbors)
|
||||
|
||||
+14
-11
@@ -8,8 +8,8 @@
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "button.h"
|
||||
#include "midi-node.h"
|
||||
#include "node.h"
|
||||
#include "midi-node.h"
|
||||
#include "edge.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -22,8 +22,21 @@
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
#include "state-io.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
typedef std::shared_ptr<GraphItem> SPTR_GraphItem;
|
||||
typedef std::shared_ptr<Node> SPTR_Node;
|
||||
typedef std::shared_ptr<Edge> SPTR_Edge;
|
||||
|
||||
typedef std::shared_ptr<Signal> SPTR_Signal;
|
||||
|
||||
typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;
|
||||
typedef std::vector<SPTR_Node> VEC_SPTR_Node;
|
||||
typedef std::vector<SPTR_Edge> VEC_SPTR_Edge;
|
||||
typedef std::vector<SPTR_Signal> VEC_SPTR_Signal;
|
||||
|
||||
class GraphManager{
|
||||
|
||||
public:
|
||||
@@ -280,14 +293,4 @@ class GraphManager{
|
||||
|
||||
};
|
||||
|
||||
inline void to_json(json& j, const Node& 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{{"neighbor", N.neighbor}, {"nodeType", N.nodeType}, {"distributionMode", N.distributionMode}, {"connections", conns}};
|
||||
|
||||
}
|
||||
inline void from_json(const json& j, Node& N) {
|
||||
|
||||
}
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GraphManager, nodes, edges)
|
||||
|
||||
+3
-1
@@ -83,7 +83,6 @@ int main(){
|
||||
app.gm.addConnection(app.gm.nodes[i], app.gm.nodes[(i+1) % 8]);
|
||||
}
|
||||
|
||||
std::cout << std::setw(2) << json(app.gm) << std::endl;
|
||||
|
||||
app.sm.addSignalAtNode(app.gm.nodes.front());
|
||||
app.sm.startSignalThread();
|
||||
@@ -96,6 +95,7 @@ int main(){
|
||||
|
||||
VEC_SPTR_Node copied_nodes;
|
||||
|
||||
|
||||
while(!WindowShouldClose()){
|
||||
|
||||
BeginDrawing();
|
||||
@@ -390,6 +390,8 @@ int main(){
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
std::cout << std::setw(4) << json(app.gm) << std::endl;
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ struct NodeMidiOut{
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NodeMidiOut, i, name, enabled)
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NodeMidiOut, i, name, enabled)
|
||||
|
||||
class MidiNode : public Node{
|
||||
|
||||
@@ -169,4 +169,4 @@ class MidiNode : public Node{
|
||||
}
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MidiNode, id, nodeType, send_note, send_cc, send_pc, send_pitch_bend, midi_outs, mode, midi_note_channel, midi_note, midi_velocity, midi_gate, midi_cc_channel, midi_cc, midi_cc_value, midi_pc_channel, midi_pc, midi_pc_value, midi_pitch_bend_channel, midi_pitch_bend)
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MidiNode, id, nodeType, send_note, send_cc, send_pc, send_pitch_bend, midi_outs, mode, midi_note_channel, midi_note, midi_velocity, midi_gate, midi_cc_channel, midi_cc, midi_cc_value, midi_pc_channel, midi_pc, midi_pc_value, midi_pitch_bend_channel, midi_pitch_bend)
|
||||
|
||||
+1
-1
@@ -42,4 +42,4 @@ class Movable{
|
||||
/*}*/
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Movable, position, direction, speed)
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Movable, position, direction, speed)
|
||||
|
||||
+11
-1
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <raylib.h>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
@@ -8,6 +9,11 @@
|
||||
#include "graph-item.h"
|
||||
#include "moveable.h"
|
||||
|
||||
class Edge;
|
||||
|
||||
typedef std::shared_ptr<Edge> SPTR_Edge;
|
||||
typedef std::vector<SPTR_Edge> VEC_SPTR_Edge;
|
||||
|
||||
class Node : public Movable, public GraphItem{
|
||||
|
||||
public:
|
||||
@@ -17,7 +23,7 @@ class Node : public Movable, public GraphItem{
|
||||
|
||||
NodeType nodeType;
|
||||
|
||||
SPTR_Node neighbor;
|
||||
std::shared_ptr<Node> neighbor;
|
||||
|
||||
VEC_SPTR_Edge connections;
|
||||
|
||||
@@ -35,6 +41,10 @@ class Node : public Movable, public GraphItem{
|
||||
void draw(Vec2Df mouse_pos, Camera2D cam) override {}
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Node> SPTR_Node;
|
||||
typedef std::vector<SPTR_Node> VEC_SPTR_Node;
|
||||
|
||||
|
||||
/*inline void to_json(json& j, const std::shared_ptr<Node>& N){*/
|
||||
/* j = json{{"id", N->id}, {"nodeType",N->nodeType}};*/
|
||||
/*}*/
|
||||
|
||||
+3
-1
@@ -1,10 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "moveable.h"
|
||||
|
||||
#include "node.h"
|
||||
#include "edge.h"
|
||||
|
||||
class Signal : public Movable{
|
||||
public:
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include "midi-node.h"
|
||||
#include "graph-item.h"
|
||||
#include "node.h"
|
||||
#include "edge.h"
|
||||
#include "graph-manager.h"
|
||||
|
||||
#include "datatypes.h"
|
||||
|
||||
#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>();*/
|
||||
/* }*/
|
||||
/* }*/
|
||||
/* };*/
|
||||
/*}*/
|
||||
|
||||
|
||||
|
||||
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 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 std::shared_ptr<Node>& N){
|
||||
j = *N;
|
||||
}
|
||||
|
||||
+2
-1
@@ -156,5 +156,6 @@ namespace VMath{
|
||||
Vec2D<T> polarToCartesian(T r, T q) {
|
||||
return Vec2D<T>{r * cos(q), r * sin(q)};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using Vec2Df = VMath::Vec2D<float>;
|
||||
|
||||
Reference in New Issue
Block a user