Serialization of NodeHandle<T> stays a mystery...

This commit is contained in:
Sebastian
2024-12-16 02:10:58 +01:00
parent 996ed16c01
commit 9b75b36c41
5 changed files with 103 additions and 56 deletions
+6
View File
@@ -46,34 +46,40 @@ namespace VISEQ::MIDI{
int note = 0; int note = 0;
int velocity = 0; int velocity = 0;
int gate = 0; // gate time in milliseconds int gate = 0; // gate time in milliseconds
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiNote, channel, note, velocity, gate);
}; };
struct MidiCC{ struct MidiCC{
int channel = 0; int channel = 0;
int control = 0; int control = 0;
int value = 0; int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiCC, channel, control, value);
}; };
struct MidiPC{ struct MidiPC{
int channel = 0; int channel = 0;
int program = 0; int program = 0;
int value = 0; int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiPC, channel, program, value);
}; };
struct MidiPitchBend{ struct MidiPitchBend{
int channel = 0; int channel = 0;
int value = 0; int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiPitchBend, channel, value);
}; };
struct MidiAftertouch{ struct MidiAftertouch{
int channel = 0; int channel = 0;
int value = 0; int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiAftertouch, channel, value);
}; };
struct MidiPolyPressure{ struct MidiPolyPressure{
int channel = 0; int channel = 0;
int note = 0; int note = 0;
int value = 0; int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiPolyPressure, channel, note, value);
}; };
struct MidiOutPort{ struct MidiOutPort{
-1
View File
@@ -490,7 +490,6 @@ namespace VISEQ::GRAPH {
} }
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GraphManager, nodes, edges, selected_nodes) NLOHMANN_DEFINE_TYPE_INTRUSIVE(GraphManager, nodes, edges, selected_nodes)
}; };
} }
+31 -39
View File
@@ -71,26 +71,25 @@ namespace VISEQ::GRAPH::NODES {
void init(){ void init(){
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.note, position, VS_COLOR_GREEN, "NOTE")); midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.note, position, VS_COLOR_GREEN, "NOTE"));
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.gate, position, VS_COLOR_RED, "GATE", 10, 30000, 40, 300)); midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.gate, position, VS_COLOR_RED, "GATE", 10, 30000, 40, 300));
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.velocity, position, VS_COLOR_PURPLE, "VELOCITY")); midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.velocity, position, VS_COLOR_PURPLE, "VELOCITY"));
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.control, position, VS_COLOR_SUN, "CONTROL")); midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.control, position, VS_COLOR_SUN, "CONTROL"));
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.value, position, VS_COLOR_GREEN, "VALUE")); midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.value, position, VS_COLOR_GREEN, "VALUE"));
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.program, position, VS_COLOR_SUN, "PROGRAM")); midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.program, position, VS_COLOR_SUN, "PROGRAM"));
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.value, position, VS_COLOR_GREEN, "VALUE")); midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.value, position, VS_COLOR_GREEN, "VALUE"));
midiPitchBendHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); midiPitchBendHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
midiPitchBendHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.value, position, VS_COLOR_GREEN, "VALUE", -8192, 8192, 40, 300)); midiPitchBendHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.value, position, VS_COLOR_GREEN, "VALUE", -8192, 8192, 40, 300));
midiAftertouchHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); midiAftertouchHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
midiAftertouchHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.value, position, VS_COLOR_GREEN, "VALUE")); midiAftertouchHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.value, position, VS_COLOR_GREEN, "VALUE"));
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.value, position, VS_COLOR_GREEN, "VALUE")); midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.value, position, VS_COLOR_GREEN, "VALUE"));
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.note, position, VS_COLOR_SUN, "NOTE")); midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.note, position, VS_COLOR_SUN, "NOTE"));
} }
@@ -410,23 +409,20 @@ namespace VISEQ::GRAPH::NODES {
{"position", N.position}, {"position", N.position},
{"distributionMode", N.distributionMode}, {"distributionMode", N.distributionMode},
{"nodeType", N.nodeType}, {"nodeType", N.nodeType},
{"midi_note_channel",N.midiNote.channel}, {"midiNote", N.midiNote},
{"midi_note_note",N.midiNote.note}, {"midiCC", N.midiCC},
{"midi_note_velocity",N.midiNote.velocity}, {"midiPC", N.midiPC},
{"midi_note_gate",N.midiNote.gate}, {"midiPitchBend", N.midiPitchBend},
{"midi_cc_channel",N.midiCC.channel}, {"midiAftertouch", N.midiAftertouch},
{"midi_cc_control",N.midiCC.control}, {"midiPolyPressure", N.midiPolyPressure},
{"midi_cc_value",N.midiCC.value}, //{"midiNoteHandle", N.midiNoteHandles},
{"midi_pc_channel",N.midiPC.channel}, /*{"midiCCHandle", N.midiCCHandles},*/
{"midi_pc_program",N.midiPC.program}, /*{"midiPCHandle", N.midiPCHandles},*/
{"midi_pc_value",N.midiPC.value}, /*{"midiPitchBendHandle", N.midiPitchBendHandles},*/
{"midi_pitch_bend_channel",N.midiPitchBend.channel}, /*{"midiAftertouchHandle", N.midiAftertouchHandles},*/
{"midi_pitch_bend_value",N.midiPitchBend.value}, /*{"midiPolyPressureHandle", N.midiPolyPressureHandles},*/
{"midi_aftertouch_channel",N.midiAftertouch.channel},
{"midi_aftertouch_value",N.midiAftertouch.value},
{"midi_polypressure_channel",N.midiPolyPressure.channel},
{"midi_polypressure_value",N.midiPolyPressure.value},
{"connections",conns}}; {"connections",conns}};
} }
friend void from_json(const json& j, MidiNode& N){ friend void from_json(const json& j, MidiNode& N){
@@ -436,22 +432,18 @@ namespace VISEQ::GRAPH::NODES {
j.at("position").get_to<Vec2Df>(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.midiNote.channel); j.at("midiNote").get_to(N.midiNote);
j.at("midi_note_note").get_to(N.midiNote.note); j.at("midiCC").get_to(N.midiCC);
j.at("midi_note_velocity").get_to(N.midiNote.velocity); j.at("midiPC").get_to(N.midiPC);
j.at("midi_note_gate").get_to(N.midiNote.gate); j.at("midiPitchBend").get_to(N.midiPitchBend);
j.at("midi_cc_channel").get_to(N.midiCC.channel); j.at("midiAftertouch").get_to(N.midiAftertouch);
j.at("midi_cc_control").get_to(N.midiCC.control); j.at("midiPolyPressure").get_to(N.midiPolyPressure);
j.at("midi_cc_value").get_to(N.midiCC.value); /*j.at("midiNoteHandle").get_to(N.midiNoteHandles);*/
j.at("midi_pc_channel").get_to(N.midiPC.channel); /*j.at("midiCCHandle").get_to(N.midiCCHandles);*/
j.at("midi_pc_program").get_to(N.midiPC.program); /*j.at("midiPCHandle").get_to(N.midiPCHandles);*/
j.at("midi_pc_value").get_to(N.midiPC.value); /*j.at("midiPitchBendHandle").get_to(N.midiPitchBendHandles);*/
j.at("midi_pitch_bend_channel").get_to(N.midiPitchBend.channel); /*j.at("midiAftertouchHandle").get_to(N.midiAftertouchHandles);*/
j.at("midi_pitch_bend_value").get_to(N.midiPitchBend.value); /*j.at("midiPolyPressureHandle").get_to(N.midiPolyPressureHandles);*/
j.at("midi_aftertouch_channel").get_to(N.midiAftertouch.channel);
j.at("midi_aftertouch_value").get_to(N.midiAftertouch.value);
j.at("midi_polypressure_channel").get_to(N.midiPolyPressure.channel);
j.at("midi_polypressure_value").get_to(N.midiPolyPressure.value);
//j.at("connections").get_to(N.connections); //j.at("connections").get_to(N.connections);
} }
+7 -2
View File
@@ -8,6 +8,7 @@
#include "raymath.h" #include "raymath.h"
#include "state.h" #include "state.h"
#include <memory> #include <memory>
#include <nlohmann/json.hpp>
namespace VISEQ::GRAPH::NODES{ namespace VISEQ::GRAPH::NODES{
@@ -63,7 +64,8 @@ namespace VISEQ::GRAPH::NODES{
orbit = (parentPosition + position).dist(parentPosition); orbit = (parentPosition + position).dist(parentPosition);
position = parentPosition.orbitAlongVector(SCREEN_MOUSE, orbit) - parentPosition; position = parentPosition.orbitAlongVector(SCREEN_MOUSE, orbit) - parentPosition;
} else { } else {
orbit = parentPosition.dist(SCREEN_MOUSE); float step = (maxDistance - minDistance) / (maxValue - minValue);
orbit = round(parentPosition.dist(SCREEN_MOUSE) / step) * step;
position = parentPosition.orbitAlongVector(maxP, orbit) - parentPosition; position = parentPosition.orbitAlongVector(maxP, orbit) - parentPosition;
} }
if(distance() >= maxDistance) position = parentPosition.orbitAlongVector(maxP, maxDistance) - parentPosition; if(distance() >= maxDistance) position = parentPosition.orbitAlongVector(maxP, maxDistance) - parentPosition;
@@ -126,6 +128,9 @@ namespace VISEQ::GRAPH::NODES{
return false; return false;
} }
// NLOHMANN_DEFINE_TYPE_INTRUSIVE(NodeHandle<T>, position, parentPosition, col, name, minValue, maxValue, minDistance, maxDistance); /*friend void to_json(json& j, const NodeHandle<T>& N){*/
/* j = json{{"position",N.position}};*/
/*}*/
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NodeHandle<T>, position, name);
}; };
} }
+59 -14
View File
@@ -3,6 +3,7 @@
#include "config-node.h" #include "config-node.h"
#include "midi-node.h" #include "midi-node.h"
#include "graph-item.h" #include "graph-item.h"
#include "node-handle.h"
#include "node.h" #include "node.h"
#include "edge.h" #include "edge.h"
@@ -34,6 +35,46 @@ namespace nlohmann {
} }
} }
}; };
/**/
/*template <typename T>*/
/*struct adl_serializer<std::shared_ptr<NODES::NodeHandle<T>>> {*/
/* template< typename J> */
/* static void to_json(J& j, const std::shared_ptr<NODES::NodeHandle<T>>& opt) {*/
/* if (opt) {*/
/* j = *opt;*/
/* } else {*/
/* j = nullptr;*/
/* }*/
/* }*/
/* template< typename J>*/
/* static void from_json(const J& j, std::shared_ptr<NODES::NodeHandle<T>>& opt) {*/
/* if (j.is_null()) {*/
/* opt = nullptr;*/
/* } else {*/
/* opt.reset(new NODES::NodeHandle<T>(j.template get<NODES::NodeHandle<T>>()));*/
/* }*/
/* }*/
/*};*/
/*template <template<typename> class S, typename T>*/
/*struct adl_serializer<std::shared_ptr<S<T>>> {*/
/* static void to_json(json& j, const std::shared_ptr<S<T>>& opt) {*/
/* if (opt) {*/
/* j = *opt;*/
/* } else {*/
/* j = nullptr;*/
/* }*/
/* }*/
/**/
/* static void from_json(const json& j, std::shared_ptr<S<T>>& opt) {*/
/* if (j.is_null()) {*/
/* opt = nullptr;*/
/* } else {*/
/* opt.reset(new S<T>(j.get<S<T>>()));*/
/* }*/
/* }*/
/*};*/
} }
namespace VISEQ::GRAPH::EDGES { namespace VISEQ::GRAPH::EDGES {
@@ -62,28 +103,32 @@ namespace VISEQ::GRAPH::NODES {
/* ------------------- MIDINODE ---------------------- */ /* ------------------- MIDINODE ---------------------- */
inline void to_json(json& j, const std::shared_ptr<MidiNode>& N){ /*inline void to_json(json& j, const std::shared_ptr<MidiNode>& N){*/
j = *N; /* j = *N;*/
} /*}*/
/**/
inline void from_json(const json& j, std::shared_ptr<MidiNode>& N){ /*inline void from_json(const json& j, std::shared_ptr<MidiNode>& N){*/
N.reset(new MidiNode(j.get<MidiNode>())); /* N.reset(new MidiNode(j.get<MidiNode>()));*/
} /*}*/
inline void to_json(json& j, const MidiNode::NodeMidiOut& MO){ inline void to_json(json& j, const MidiNode::NodeMidiOut& MO){
j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}}; j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}};
} }
/*template< typename T>*/
/*inline void to_json(json& j, const std::shared_ptr<NodeHandle<T>>& NH){*/
/* j = json{{"position", NH->position}};*/
/*}*/
/* ----------------- CONFIG NODE -----------------*/ /* ----------------- CONFIG NODE -----------------*/
inline void to_json(json& j, const std::shared_ptr<ConfigNode>& N){ /*inline void to_json(json& j, const std::shared_ptr<ConfigNode>& N){*/
j = *N; /* j = *N;*/
} /*}*/
/**/
inline void from_json(const json& j, std::shared_ptr<ConfigNode>& N){ /*inline void from_json(const json& j, std::shared_ptr<ConfigNode>& N){*/
N.reset(new ConfigNode(j.get<ConfigNode>())); /* N.reset(new ConfigNode(j.get<ConfigNode>()));*/
} /*}*/
/* ------------------- NODE ---------------------- */ /* ------------------- NODE ---------------------- */