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 velocity = 0;
int gate = 0; // gate time in milliseconds
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiNote, channel, note, velocity, gate);
};
struct MidiCC{
int channel = 0;
int control = 0;
int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiCC, channel, control, value);
};
struct MidiPC{
int channel = 0;
int program = 0;
int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiPC, channel, program, value);
};
struct MidiPitchBend{
int channel = 0;
int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiPitchBend, channel, value);
};
struct MidiAftertouch{
int channel = 0;
int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiAftertouch, channel, value);
};
struct MidiPolyPressure{
int channel = 0;
int note = 0;
int value = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MidiPolyPressure, channel, note, value);
};
struct MidiOutPort{
-1
View File
@@ -490,7 +490,6 @@ namespace VISEQ::GRAPH {
}
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GraphManager, nodes, edges, selected_nodes)
};
}
+31 -39
View File
@@ -71,26 +71,25 @@ namespace VISEQ::GRAPH::NODES {
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.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.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.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"));
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"));
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));
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"));
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.note, position, VS_COLOR_SUN, "NOTE"));
}
@@ -410,23 +409,20 @@ namespace VISEQ::GRAPH::NODES {
{"position", N.position},
{"distributionMode", N.distributionMode},
{"nodeType", N.nodeType},
{"midi_note_channel",N.midiNote.channel},
{"midi_note_note",N.midiNote.note},
{"midi_note_velocity",N.midiNote.velocity},
{"midi_note_gate",N.midiNote.gate},
{"midi_cc_channel",N.midiCC.channel},
{"midi_cc_control",N.midiCC.control},
{"midi_cc_value",N.midiCC.value},
{"midi_pc_channel",N.midiPC.channel},
{"midi_pc_program",N.midiPC.program},
{"midi_pc_value",N.midiPC.value},
{"midi_pitch_bend_channel",N.midiPitchBend.channel},
{"midi_pitch_bend_value",N.midiPitchBend.value},
{"midi_aftertouch_channel",N.midiAftertouch.channel},
{"midi_aftertouch_value",N.midiAftertouch.value},
{"midi_polypressure_channel",N.midiPolyPressure.channel},
{"midi_polypressure_value",N.midiPolyPressure.value},
{"midiNote", N.midiNote},
{"midiCC", N.midiCC},
{"midiPC", N.midiPC},
{"midiPitchBend", N.midiPitchBend},
{"midiAftertouch", N.midiAftertouch},
{"midiPolyPressure", N.midiPolyPressure},
//{"midiNoteHandle", N.midiNoteHandles},
/*{"midiCCHandle", N.midiCCHandles},*/
/*{"midiPCHandle", N.midiPCHandles},*/
/*{"midiPitchBendHandle", N.midiPitchBendHandles},*/
/*{"midiAftertouchHandle", N.midiAftertouchHandles},*/
/*{"midiPolyPressureHandle", N.midiPolyPressureHandles},*/
{"connections",conns}};
}
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("distributionMode").get_to(N.distributionMode);
j.at("nodeType").get_to(N.nodeType);
j.at("midi_note_channel").get_to(N.midiNote.channel);
j.at("midi_note_note").get_to(N.midiNote.note);
j.at("midi_note_velocity").get_to(N.midiNote.velocity);
j.at("midi_note_gate").get_to(N.midiNote.gate);
j.at("midi_cc_channel").get_to(N.midiCC.channel);
j.at("midi_cc_control").get_to(N.midiCC.control);
j.at("midi_cc_value").get_to(N.midiCC.value);
j.at("midi_pc_channel").get_to(N.midiPC.channel);
j.at("midi_pc_program").get_to(N.midiPC.program);
j.at("midi_pc_value").get_to(N.midiPC.value);
j.at("midi_pitch_bend_channel").get_to(N.midiPitchBend.channel);
j.at("midi_pitch_bend_value").get_to(N.midiPitchBend.value);
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("midiNote").get_to(N.midiNote);
j.at("midiCC").get_to(N.midiCC);
j.at("midiPC").get_to(N.midiPC);
j.at("midiPitchBend").get_to(N.midiPitchBend);
j.at("midiAftertouch").get_to(N.midiAftertouch);
j.at("midiPolyPressure").get_to(N.midiPolyPressure);
/*j.at("midiNoteHandle").get_to(N.midiNoteHandles);*/
/*j.at("midiCCHandle").get_to(N.midiCCHandles);*/
/*j.at("midiPCHandle").get_to(N.midiPCHandles);*/
/*j.at("midiPitchBendHandle").get_to(N.midiPitchBendHandles);*/
/*j.at("midiAftertouchHandle").get_to(N.midiAftertouchHandles);*/
/*j.at("midiPolyPressureHandle").get_to(N.midiPolyPressureHandles);*/
//j.at("connections").get_to(N.connections);
}
+7 -2
View File
@@ -8,6 +8,7 @@
#include "raymath.h"
#include "state.h"
#include <memory>
#include <nlohmann/json.hpp>
namespace VISEQ::GRAPH::NODES{
@@ -63,7 +64,8 @@ namespace VISEQ::GRAPH::NODES{
orbit = (parentPosition + position).dist(parentPosition);
position = parentPosition.orbitAlongVector(SCREEN_MOUSE, orbit) - parentPosition;
} 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;
}
if(distance() >= maxDistance) position = parentPosition.orbitAlongVector(maxP, maxDistance) - parentPosition;
@@ -126,6 +128,9 @@ namespace VISEQ::GRAPH::NODES{
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 "midi-node.h"
#include "graph-item.h"
#include "node-handle.h"
#include "node.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 {
@@ -62,28 +103,32 @@ namespace VISEQ::GRAPH::NODES {
/* ------------------- MIDINODE ---------------------- */
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>()));
}
/*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>()));*/
/*}*/
inline void to_json(json& j, const MidiNode::NodeMidiOut& MO){
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 -----------------*/
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>()));
}
/*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>()));*/
/*}*/
/* ------------------- NODE ---------------------- */