From 9b75b36c41026edad3d1dd8d0efe913534f17fcd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 16 Dec 2024 02:10:58 +0100 Subject: [PATCH] Serialization of NodeHandle stays a mystery... --- src/datatypes.h | 6 ++++ src/graph-manager.h | 1 - src/midi-node.h | 70 +++++++++++++++++++------------------------ src/node-handle.h | 9 ++++-- src/state-io.h | 73 ++++++++++++++++++++++++++++++++++++--------- 5 files changed, 103 insertions(+), 56 deletions(-) diff --git a/src/datatypes.h b/src/datatypes.h index 455a373..06ac360 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -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{ diff --git a/src/graph-manager.h b/src/graph-manager.h index 1a98e20..fc64799 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -490,7 +490,6 @@ namespace VISEQ::GRAPH { } NLOHMANN_DEFINE_TYPE_INTRUSIVE(GraphManager, nodes, edges, selected_nodes) - }; } diff --git a/src/midi-node.h b/src/midi-node.h index e1c3d9a..7b8623c 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -71,26 +71,25 @@ namespace VISEQ::GRAPH::NODES { void init(){ midiNoteHandles.emplace_back(std::make_shared>(midiNote.note, position, VS_COLOR_GREEN, "NOTE")); - midiNoteHandles.emplace_back(std::make_shared>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); + midiNoteHandles.emplace_back(std::make_shared>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); midiNoteHandles.emplace_back(std::make_shared>(midiNote.gate, position, VS_COLOR_RED, "GATE", 10, 30000, 40, 300)); midiNoteHandles.emplace_back(std::make_shared>(midiNote.velocity, position, VS_COLOR_PURPLE, "VELOCITY")); - midiCCHandles.emplace_back(std::make_shared>(midiCC.control, position, VS_COLOR_SUN, "CONTROL")); - midiCCHandles.emplace_back(std::make_shared>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); + midiCCHandles.emplace_back(std::make_shared>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); midiCCHandles.emplace_back(std::make_shared>(midiCC.value, position, VS_COLOR_GREEN, "VALUE")); midiPCHandles.emplace_back(std::make_shared>(midiPC.program, position, VS_COLOR_SUN, "PROGRAM")); - midiPCHandles.emplace_back(std::make_shared>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); + midiPCHandles.emplace_back(std::make_shared>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); midiPCHandles.emplace_back(std::make_shared>(midiPC.value, position, VS_COLOR_GREEN, "VALUE")); - midiPitchBendHandles.emplace_back(std::make_shared>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); + midiPitchBendHandles.emplace_back(std::make_shared>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); midiPitchBendHandles.emplace_back(std::make_shared>(midiPitchBend.value, position, VS_COLOR_GREEN, "VALUE", -8192, 8192, 40, 300)); - midiAftertouchHandles.emplace_back(std::make_shared>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); + midiAftertouchHandles.emplace_back(std::make_shared>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); midiAftertouchHandles.emplace_back(std::make_shared>(midiAftertouch.value, position, VS_COLOR_GREEN, "VALUE")); - midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", 0, 15, 40, 150)); + midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.value, position, VS_COLOR_GREEN, "VALUE")); midiPolyPressureHandles.emplace_back(std::make_shared>(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(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); } diff --git a/src/node-handle.h b/src/node-handle.h index 83c854c..b2e5885 100644 --- a/src/node-handle.h +++ b/src/node-handle.h @@ -8,6 +8,7 @@ #include "raymath.h" #include "state.h" #include +#include 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, position, parentPosition, col, name, minValue, maxValue, minDistance, maxDistance); + /*friend void to_json(json& j, const NodeHandle& N){*/ + /* j = json{{"position",N.position}};*/ + /*}*/ + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NodeHandle, position, name); }; } diff --git a/src/state-io.h b/src/state-io.h index c4dbaeb..6a88351 100644 --- a/src/state-io.h +++ b/src/state-io.h @@ -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 */ + /*struct adl_serializer>> {*/ + /* template< typename J> */ + /* static void to_json(J& j, const std::shared_ptr>& opt) {*/ + /* if (opt) {*/ + /* j = *opt;*/ + /* } else {*/ + /* j = nullptr;*/ + /* }*/ + /* }*/ + /* template< typename J>*/ + /* static void from_json(const J& j, std::shared_ptr>& opt) {*/ + /* if (j.is_null()) {*/ + /* opt = nullptr;*/ + /* } else {*/ + /* opt.reset(new NODES::NodeHandle(j.template get>()));*/ + /* }*/ + /* }*/ + /*};*/ + + /*template class S, typename T>*/ + /*struct adl_serializer>> {*/ + /* static void to_json(json& j, const std::shared_ptr>& opt) {*/ + /* if (opt) {*/ + /* j = *opt;*/ + /* } else {*/ + /* j = nullptr;*/ + /* }*/ + /* }*/ + /**/ + /* static void from_json(const json& j, std::shared_ptr>& opt) {*/ + /* if (j.is_null()) {*/ + /* opt = nullptr;*/ + /* } else {*/ + /* opt.reset(new S(j.get>()));*/ + /* }*/ + /* }*/ + /*};*/ } namespace VISEQ::GRAPH::EDGES { @@ -62,28 +103,32 @@ namespace VISEQ::GRAPH::NODES { /* ------------------- MIDINODE ---------------------- */ - inline void to_json(json& j, const std::shared_ptr& N){ - j = *N; - } - - inline void from_json(const json& j, std::shared_ptr& N){ - N.reset(new MidiNode(j.get())); - } + /*inline void to_json(json& j, const std::shared_ptr& N){*/ + /* j = *N;*/ + /*}*/ + /**/ + /*inline void from_json(const json& j, std::shared_ptr& N){*/ + /* N.reset(new MidiNode(j.get()));*/ + /*}*/ 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>& NH){*/ + /* j = json{{"position", NH->position}};*/ + /*}*/ /* ----------------- CONFIG NODE -----------------*/ - inline void to_json(json& j, const std::shared_ptr& N){ - j = *N; - } - - inline void from_json(const json& j, std::shared_ptr& N){ - N.reset(new ConfigNode(j.get())); - } + /*inline void to_json(json& j, const std::shared_ptr& N){*/ + /* j = *N;*/ + /*}*/ + /**/ + /*inline void from_json(const json& j, std::shared_ptr& N){*/ + /* N.reset(new ConfigNode(j.get()));*/ + /*}*/ /* ------------------- NODE ---------------------- */