98 lines
2.3 KiB
C++
98 lines
2.3 KiB
C++
|
|
#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;
|
||
|
|
}
|
||
|
|
|