json is loading, but does nothing yet

This commit is contained in:
Sebastian
2024-11-03 03:48:49 +01:00
parent a4ea20b2b3
commit 7bdd68bdcc
16 changed files with 1174 additions and 1104 deletions
+1
View File
@@ -3,3 +3,4 @@ build/**
viseq
viseq.exe
compile_commands.json
state.json
+9 -25
View File
@@ -27,29 +27,13 @@ using json = nlohmann::json;
#include <math.h>
#include "libremidi/libremidi.hpp"
enum Distribution {GEOMETRIC, ROUNDROBIN, RANDOM};
// Types
/*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;*/
namespace VISEQ::GRAPH::NODES {
enum Distribution {GEOMETRIC, ROUNDROBIN, RANDOM};
}
// App Settings
namespace VISEQ::APP{
struct AppSettings{
int mode = 0;
int width;
@@ -60,15 +44,15 @@ struct AppSettings{
float speed = 16.0f;
int gui_selected_midi_out;
};
}
// Graph
namespace VISEQ::GRAPH{
enum GraphItemType {NODE, EDGE};
enum NodeType {OSCNODE, MIDINODE};
}
// MIDI
namespace VISEQ::MIDI{
struct MidiOutPort{
libremidi::output_port port;
int number;
@@ -83,8 +67,8 @@ struct MidiOut{
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MidiOut, number)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MidiOutPort, number, enabled)
namespace MIDI{
inline std::vector<std::string> Fractions = {"1/32","1/16","3/32","1/8","5/32","3/16","7/32","1/4","9/32","5/16","11/32","3/8","13/32","7/16","15/32","1/2","17/32","9/16","19/32","5/8","21/32","11/16","23/32","3/4","25/32","13/16","27/32","7/8","29/32","15/16","31/32","1/1"};
inline std::vector<std::string> Notes = {
"C-1", "C#-1", "D-1", "D#-1", "E-1", "F-1", "F#-1", "G-1",
"G#-1", "A-1", "A#-1", "B-1", "C0", "C#0", "D0", "D#0",
+12 -10
View File
@@ -1,16 +1,20 @@
#pragma once
#include "datatypes.h"
#include "graph-item.h"
#include <memory>
#include "node.h"
using namespace VISEQ::GRAPH;
namespace VISEQ::GRAPH::EDGES {
class Edge : public GraphItem{
public:
Edge() {}
Edge(SPTR_Node start, SPTR_Node end) : start(start), end(end) {}
Edge(std::shared_ptr<NODES::Node> start, std::shared_ptr<NODES::Node> end) : start(start), end(end) {}
SPTR_Node start;
SPTR_Node end;
std::shared_ptr<NODES::Node> start;
std::shared_ptr<NODES::Node> end;
bool pass_forward = true;
bool pass_backward = true;
@@ -24,15 +28,13 @@ class Edge : public GraphItem{
virtual bool GActive() {return active;}
SPTR_Node getNextNode(SPTR_Node origin){
std::shared_ptr<NODES::Node> getNextNode(std::shared_ptr<NODES::Node> origin){
return start == origin ? end : start;
}
void draw(Vec2Df mouse_pos, Camera2D cam) {}
};
/*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)
typedef std::shared_ptr<Edge> SPTR_Edge;
typedef std::vector<SPTR_Edge> VEC_SPTR_Edge;
}
+2 -8
View File
@@ -5,6 +5,7 @@
#include <memory>
#include <vector>
namespace VISEQ::GRAPH {
class GraphItem{
public:
@@ -17,14 +18,7 @@ class GraphItem{
virtual GraphItemType getType() {return graphItemType;}
virtual ~GraphItem() = default;
/*void to_json(json& j, const GraphItem& G){*/
/* j = json{{"id",id},{"graphItemType",graphItemType},{"neighbors",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)
+21 -28
View File
@@ -8,9 +8,9 @@
#include "nlohmann/json.hpp"
#include "button.h"
#include "node.h"
#include "midi-node.h"
#include "edge.h"
#include "node.h"
#include <algorithm>
#include <cstdio>
@@ -26,16 +26,10 @@
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;
using namespace VISEQ::GRAPH::NODES;
using namespace VISEQ::GRAPH::EDGES;
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;
namespace VISEQ::GRAPH {
class GraphManager{
@@ -43,32 +37,24 @@ class GraphManager{
GraphManager() {}
VEC_SPTR_Node nodes;
VEC_SPTR_Edge edges;
NODES::VEC_SPTR_Node nodes;
EDGES::VEC_SPTR_Edge edges;
VEC_SPTR_Edge remove_edges;
VEC_SPTR_Edge split_edges;
EDGES::VEC_SPTR_Edge remove_edges;
EDGES::VEC_SPTR_Edge split_edges;
std::map<SPTR_Node, int> counter;
std::map<NODES::SPTR_Node, int> counter;
/*void to_json(json& j, const GraphManager& G){*/
/* j = json{{"nodes", G.nodes}, {"edges", G.edges}};*/
/*}*/
/**/
/*void from_json(const json& j, GraphManager& G){*/
/**/
/*}*/
SPTR_Node getRandomNode(){
NODES::SPTR_Node getRandomNode(){
VEC_SPTR_GraphItem o;
std::ranges::sample(nodes, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
return std::dynamic_pointer_cast<Node>(o.front());
return std::dynamic_pointer_cast<VISEQ::GRAPH::NODES::Node>(o.front());
}
SPTR_Edge getRandomEdge(){
EDGES::SPTR_Edge getRandomEdge(){
VEC_SPTR_GraphItem o;
std::ranges::sample(edges, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
return std::dynamic_pointer_cast<Edge>(o.front());
return std::dynamic_pointer_cast<VISEQ::GRAPH::EDGES::Edge>(o.front());
}
void copyNodes(VEC_SPTR_Node _nodes, Vec2Df position){
@@ -293,4 +279,11 @@ class GraphManager{
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(GraphManager, nodes, edges)
inline void to_json(json& j, const GraphManager& G){
j = json{{"nodes", G.nodes}, {"edges", G.edges}};
}
inline void from_json(const json& j, GraphManager& G){
j.at("nodes").get_to(G.nodes); // = json{{"nodes", G.nodes}, {"edges", G.edges}};
}
}
+23 -7
View File
@@ -6,6 +6,10 @@
*
*/
#include "graph-manager.h"
#include "vmath.h"
#include <filesystem>
#include <fstream>
#define RAYGUI_IMPLEMENTATION
#include <raylib.h>
#include <raymath.h>
@@ -24,9 +28,11 @@
#include <iterator>
#include <memory>
#include "state-io.h"
using json = nlohmann::json;
AppState app;
VISEQ::APP::AppState app;
Vec2Df mouse_pos;
Vec2Df drag_start;
@@ -72,6 +78,13 @@ int main(){
camera.rotation = 0.0f;
camera.zoom = 1.0f;
if(std::filesystem::exists("state.json")){
std::ifstream f("state.json");
json graph = json::parse(f);
app.gm = graph["graphmanager"].template get<VISEQ::GRAPH::GraphManager>();
} else {
for(int i = 0; i < 4; ++i){
app.gm.addMidiNode(Vec2Df{(float)i * app.settings.grid*4 + 7 * app.settings.grid, 2 * app.settings.grid*4});
}
@@ -82,9 +95,9 @@ int main(){
for(int i = 0; i < 8; ++i){
app.gm.addConnection(app.gm.nodes[i], app.gm.nodes[(i+1) % 8]);
}
app.sm.addSignalAtNode(app.gm.nodes.front());
}
app.sm.startSignalThread();
enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, DRAG_NODE, CONNECT_NODE, DRAW_SELECTION, DELETE_SELECTED_NODES, COPY_SELECTED_NODES, PASTE_SELECTED_NODES};
@@ -223,7 +236,7 @@ int main(){
float pol_r = steps;
float pol_theta = Vector2Angle(Vec2Df{1,0},(mouse_pos - dragNode->neighbor->position));
Vec2Df polar = VMath::polarToCartesian(pol_r, pol_theta);
Vec2Df polar = VISEQ::VMATH::polarToCartesian(pol_r, pol_theta);
dragNode->position = dragNode->neighbor->position + polar;
} else {
dragNode->position = mouse_pos + dragNode->drag_offset;
@@ -330,8 +343,8 @@ int main(){
midiNode->midi_pitch_bend += wheel;
break;}
};
if(midiNode->midi_note < 0 ) midiNode->midi_note = app.sm.midi.midiNotes.size()-1;
if(midiNode->midi_note >= app.sm.midi.midiNotes.size() ) midiNode->midi_note = 0;
if(midiNode->midi_note < 0 ) midiNode->midi_note = VISEQ::MIDI::Notes.size()-1;
if(midiNode->midi_note >= VISEQ::MIDI::Notes.size() ) midiNode->midi_note = 0;
if(midiNode->midi_cc < 0 ) midiNode->midi_cc = 127;
if(midiNode->midi_cc > 127 ) midiNode->midi_cc = 0;
@@ -390,7 +403,10 @@ int main(){
EndDrawing();
}
std::cout << std::setw(4) << json(app.gm) << std::endl;
std::ofstream file("state.json");
file << json(app);
std::cout << std::setw(4) << json(app) << std::endl;
CloseWindow();
+8 -9
View File
@@ -7,18 +7,18 @@
#define RADIUS 14.0f
namespace VISEQ::GRAPH::NODES {
class MidiNode : public Node{
public:
struct NodeMidiOut{
int i;
std::string name;
bool enabled;
};
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NodeMidiOut, i, name, enabled)
class MidiNode : public Node{
public:
MidiNode() {}
MidiNode(Vec2Df position) : Node(position) {}
@@ -63,7 +63,7 @@ class MidiNode : public Node{
float time = 0;
float last = 0;
virtual NodeType getNodeType() override {return nodeType;}
virtual NodeType getNodeType() const override {return nodeType;}
void setMidiPort(int midi_port, bool state){
midi_outs[midi_port].enabled = state;
@@ -168,5 +168,4 @@ class MidiNode : public Node{
if(highlighted) DrawCircleLinesV(position, radius+2, (Color){255, 0, 0, 200});
}
};
//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)
}
+4 -21
View File
@@ -8,9 +8,10 @@
#include <iostream>
#include <map>
#include <memory>
#include <numbers>
#include "datatypes.h"
namespace VISEQ::MIDI {
struct NoteTimer{
int midi_out;
int channel;
@@ -28,26 +29,6 @@ class Midi {
enumerate();
}
std::vector<std::string> midiNotes = {
"C-1", "C#-1", "D-1", "D#-1", "E-1", "F-1", "F#-1", "G-1",
"G#-1", "A-1", "A#-1", "B-1", "C0", "C#0", "D0", "D#0",
"E0", "F0", "F#0", "G0", "G#0", "A0", "A#0", "B0",
"C1", "C#1", "D1", "D#1", "E1", "F1", "F#1", "G1",
"G#1", "A1", "A#1", "B1", "C2", "C#2", "D2", "D#2",
"E2", "F2", "F#2", "G2", "G#2", "A2", "A#2", "B2",
"C3", "C#3", "D3", "D#3", "E3", "F3", "F#3", "G3",
"G#3", "A3", "A#3", "B3", "C4", "C#4", "D4", "D#4",
"E4", "F4", "F#4", "G4", "G#4", "A4", "A#4", "B4",
"C5", "C#5", "D5", "D#5", "E5", "F5", "F#5", "G5",
"G#5", "A5", "A#5", "B5", "C6", "C#6", "D6", "D#6",
"E6", "F6", "F#6", "G6", "G#6", "A6", "A#6", "B6",
"C7", "C#7", "D7", "D#7", "E7", "F7", "F#7", "G7",
"G#7", "A7", "A#7", "B7", "C8", "C#8", "D8", "D#8",
"E8", "F8", "F#8", "G8", "G#8", "A8", "A#8", "B8",
"C9", "C#9", "D9", "D#9", "E9", "F9", "F#9", "G9",
"G#9", "A9", "A#9", "B9", "C10"
};
libremidi::observer obs;
std::map<int, std::shared_ptr<libremidi::midi_out>> midi_outs;
@@ -127,3 +108,5 @@ class Midi {
}
}
};
}
+2 -5
View File
@@ -2,7 +2,7 @@
#include "datatypes.h"
namespace VISEQ::BASE {
class Movable{
public:
@@ -37,9 +37,6 @@ class Movable{
virtual void update(double frametime) {};
virtual void update() {};
/*virtual void to_json(json& j, const Movable& M){*/
/* j = json{{"position", M.position}, {"direction", M.direction}, {"speed", M.speed}};*/
/*}*/
};
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Movable, position, direction, speed)
}
+8 -15
View File
@@ -3,18 +3,17 @@
#include <memory>
#include <raylib.h>
#include "nlohmann/json.hpp"
#include "datatypes.h"
#include "graph-item.h"
#include "moveable.h"
namespace VISEQ::GRAPH::EDGES{
class Edge;
}
typedef std::shared_ptr<Edge> SPTR_Edge;
typedef std::vector<SPTR_Edge> VEC_SPTR_Edge;
namespace VISEQ::GRAPH::NODES {
class Node : public Movable, public GraphItem{
class Node : public BASE::Movable, public GraphItem{
public:
Node() {}
@@ -25,14 +24,14 @@ class Node : public Movable, public GraphItem{
std::shared_ptr<Node> neighbor;
VEC_SPTR_Edge connections;
std::vector<std::shared_ptr<VISEQ::GRAPH::EDGES::Edge>> connections;
Distribution distributionMode = Distribution::GEOMETRIC;
float radius = 15.0f;
bool config = false;
virtual NodeType getNodeType() {return nodeType;}
virtual NodeType getNodeType() const {return nodeType;}
virtual void SMode(int mode) {};
virtual int GGate() {return 0;};
@@ -41,13 +40,7 @@ class Node : public Movable, public GraphItem{
void draw(Vec2Df mouse_pos, Camera2D cam) override {}
};
typedef std::shared_ptr<Node> SPTR_Node;
typedef std::shared_ptr<VISEQ::GRAPH::NODES::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}};*/
/*}*/
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Node, nodeType, neighbor, connections, distributionMode)
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Node, id, nodeType, distributionMode)
}
+13 -1
View File
@@ -10,13 +10,20 @@
#include <memory>
#include <thread>
using namespace VISEQ::GRAPH;
namespace VISEQ::SIGNAL {
typedef std::shared_ptr<Signal> SPTR_Signal;
typedef std::vector<SPTR_Signal> VEC_SPTR_Signal;
class SignalManager{
public:
SignalManager() {}
SignalManager(GraphManager *gm, std::mutex *mutex) : mutex(mutex), gm(gm) {}
Midi midi;
VISEQ::MIDI::Midi midi;
std::mutex *mutex;
GraphManager *gm;
@@ -114,3 +121,8 @@ class SignalManager{
}
};
inline void to_json(json& j, const SignalManager& G){
j = json{{"signals", G.signals}};
}
}
+10 -6
View File
@@ -1,23 +1,25 @@
#pragma once
#include <raylib.h>
#include "datatypes.h"
#include "moveable.h"
#include "node.h"
#include "edge.h"
class Signal : public Movable{
using namespace VISEQ::GRAPH;
namespace VISEQ::SIGNAL {
class Signal : public BASE::Movable{
public:
Signal();
Signal(Vec2Df position, float r, float _speed, Color color) : Movable(position, Vec2Df(0,0), _speed), radius(r), color(color) {}
SPTR_Node next;
SPTR_Node last;
SPTR_Edge edge;
NODES::SPTR_Node next;
NODES::SPTR_Node last;
EDGES::SPTR_Edge edge;
SPTR_Node start;
NODES::SPTR_Node start;
bool at_target = false;
@@ -38,3 +40,5 @@ class Signal : public Movable{
DrawCircle(position.x, position.y, radius, color);
}
};
}
+121 -45
View File
@@ -4,57 +4,60 @@
#include "graph-item.h"
#include "node.h"
#include "edge.h"
#include "graph-manager.h"
//#include "graph-manager.h"
#include "datatypes.h"
#include "signal.h"
#include <iostream>
#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>();*/
/* }*/
/* }*/
/* };*/
/*}*/
/*using namespace VISEQ::BASE;*/
/*using namespace VISEQ::SIGNAL;*/
/*using namespace VISEQ::GRAPH::NODES;*/
/*using namespace VISEQ::GRAPH::EDGES;*/
typedef std::shared_ptr<VISEQ::GRAPH::GraphItem> SPTR_GraphItem;
typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;
namespace VISEQ::GRAPH::EDGES {
using namespace VISEQ::GRAPH::NODES;
inline void to_json(json& j, const Edge& E){
inline void to_json(json& j, const VISEQ::GRAPH::EDGES::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){
inline void from_json(const json& j, Edge& E){
j.at("id").get_to(E.id);
j.at("pass_forward").get_to(E.pass_forward);
j.at("pass_backward").get_to(E.pass_backward);
}
inline void to_json(json& j, const VISEQ::GRAPH::EDGES::SPTR_Edge& E){
j = *E;
}
inline void from_json(const json& j, VISEQ::GRAPH::EDGES::SPTR_Edge& E){
E.reset(new Edge(j.get<Edge>()));
}
}
namespace VISEQ::GRAPH::NODES {
/* ------------------- MIDINODE ---------------------- */
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},
std::ranges::transform(N.connections.begin(), N.connections.end(), std::back_inserter(conns), [](VISEQ::GRAPH::EDGES::SPTR_Edge e){ return e->id;});
j = json{
{"id", N.id},
{"position", N.position},
{"distributionMode", N.distributionMode},
{"nodeType", N.nodeType},
{"midi_note_channel",N.midi_note_channel},
{"midi_velocity",N.midi_velocity},
{"midi_gatel",N.midi_gate},
{"midi_gate",N.midi_gate},
{"midi_cc_channel",N.midi_cc_channel},
{"midi_cc",N.midi_cc},
{"midi_cc_value",N.midi_cc_value},
@@ -65,10 +68,73 @@ inline void to_json(json& j, const MidiNode& N){
{"connections",conns}};
}
inline void from_json(const json& j, MidiNode& N){
j.at("id").get_to(N.id);
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.midi_note_channel);
j.at("midi_velocity").get_to(N.midi_velocity);
j.at("midi_gate").get_to(N.midi_gate);
j.at("midi_cc_channel").get_to(N.midi_cc_channel);
j.at("midi_cc").get_to(N.midi_cc);
j.at("midi_cc_value").get_to(N.midi_cc_value);
j.at("midi_pc_channel").get_to(N.midi_pc_channel);
j.at("midi_pc_value").get_to(N.midi_pc_value);
j.at("midi_pitch_bend_channel").get_to(N.midi_pitch_bend_channel);
j.at("midi_pitch_bend").get_to(N.midi_pitch_bend);
//j.at("connections").get_to(N.connections);
}
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>()));
}
/* ------------------- NODE ---------------------- */
inline void to_json(json& j, const Node& N){
if(N.getNodeType() == NodeType::MIDINODE){
j = dynamic_cast<const MidiNode&>(N);
}
}
inline void from_json(const json& j, Node& N){
if(j.at("nodeType") == NodeType::MIDINODE){
std::cout << j.at("nodeType") << std::endl;
N = j.template get<MidiNode>();
}
/*j.at("id").get_to(N.id);*/
/*j.at("position").get_to(N.position);*/
/*j.at("distributionMode").get_to(N.distributionMode);*/
/*j.at("nodeType").get_to(N.nodeType);*/
//j.at("connections").get_to(N.connections);
}
inline void to_json(json& j, const SPTR_Node& N){
j = *N;
}
inline void to_json(json& j, const MidiNode::NodeMidiOut MO){
j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}};
}
inline void from_json(const json& j, std::shared_ptr<Node>& N){
N.reset(new Node(j.get<Node>()));
}
}
namespace VISEQ::GRAPH {
inline void to_json(json& j, const GraphItem& G){
j = json{{"id", G.id}, {"type", G.graphItemType}};
}
@@ -76,22 +142,32 @@ inline void to_json(json& j, const GraphItem& G){
inline void to_json(json& j, const SPTR_GraphItem& G){
j = *G;
}
}
namespace VISEQ::BASE{
inline void to_json(json& j, const Movable& G){
j = json{{"position", G.position}};
}
inline void to_json(json& j, const std::shared_ptr<Movable>& G){
j = *G;
}
}
namespace VISEQ::SIGNAL{
inline void to_json(json& j, const Signal& G){
j = json{{"position", G.position},{"start",G.start->id},{"speed",G.speed}};
}
inline void to_json(json& j, const std::shared_ptr<Signal>& G){
j = *G;
}
}
namespace VISEQ::MIDI {
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;
}
+18 -8
View File
@@ -1,6 +1,5 @@
#pragma once
#include "edge.h"
#include "datatypes.h"
#include "graph-manager.h"
#include "midi-node.h"
@@ -13,6 +12,8 @@
#include <ranges>
#include <vector>
namespace VISEQ::APP {
class AppState{
public:
@@ -26,13 +27,13 @@ class AppState{
std::mutex mutex;
GraphManager gm;
SignalManager sm;
VISEQ::GRAPH::GraphManager gm;
VISEQ::SIGNAL::SignalManager sm;
AppUI ui;
UI::AppUI ui;
void updateMidiPorts(){
for(auto&n : gm.nodes | RANGE_FILTER([](SPTR_Node n){return n->getNodeType() == NodeType::MIDINODE;})){
for(auto&n : gm.nodes | RANGE_FILTER([](VISEQ::GRAPH::NODES::SPTR_Node n){return n->getNodeType() == NodeType::MIDINODE;})){
auto nc = std::dynamic_pointer_cast<MidiNode>(n);
for(auto& mo : sm.midi.midi_out_ports){
if(!nc->midi_outs.contains(mo.number) && mo.enabled){
@@ -98,7 +99,7 @@ class AppState{
if(!c->end->selected) adjacent_nodes.push_back(c->end);
}
auto reroute_signals = sm.signals | RANGE_FILTER([nodes](SPTR_Signal s){return std::ranges::contains(nodes, s->next);});
auto reroute_signals = sm.signals | RANGE_FILTER([nodes](SIGNAL::SPTR_Signal s){return std::ranges::contains(nodes, s->next);});
for(auto s : reroute_signals){
float dist = 10000000;
@@ -113,14 +114,14 @@ class AppState{
s->last = next_node;
}
auto rebase_signals = sm.signals | RANGE_FILTER([nodes](SPTR_Signal s){return std::ranges::contains(nodes, s->start);});
auto rebase_signals = sm.signals | RANGE_FILTER([nodes](SIGNAL::SPTR_Signal s){return std::ranges::contains(nodes, s->start);});
for(auto s : rebase_signals){
s->start = s->next;
}
for(auto n : adjacent_nodes){
std::erase_if(n->connections, [n, nodes](SPTR_Edge c){ return std::ranges::contains(nodes, c->start) || std::ranges::contains(nodes, c->end);});
std::erase_if(n->connections, [n, nodes](VISEQ::GRAPH::EDGES::SPTR_Edge c){ return std::ranges::contains(nodes, c->start) || std::ranges::contains(nodes, c->end);});
}
for(auto n : nodes){
@@ -144,3 +145,12 @@ class AppState{
mutex.unlock();
}
};
inline void to_json(json& j, const AppState& A){
j = json{{"graphmanager", A.gm}, {"signalmanager", A.sm}};
}
inline void from_json(const json& j, AppState& A){
j.at("graphmanager").get_to(A.gm); // = json{{"graphmanager", A.gm}, {"signalmanager", A.sm}};
}
}
+6 -4
View File
@@ -12,14 +12,15 @@
#include <memory>
#include <ranges>
namespace VISEQ::APP::UI{
class AppUI{
public:
AppUI(AppSettings *settings, SignalManager *sm, GraphManager *gm) : settings(settings), gm(gm), sm(sm) {}
AppUI() {}
AppUI(AppSettings *settings, SIGNAL::SignalManager *sm, GraphManager *gm) : settings(settings), gm(gm), sm(sm) {}
AppSettings *settings;
GraphManager *gm;
SignalManager *sm;
SIGNAL::SignalManager *sm;
void init(){
GuiLoadStyleDark();
@@ -128,7 +129,7 @@ class AppUI{
GuiLabel((Rectangle){np.x + 20, np.y + y_cc_note , 100, 20}, "NOTE");
float v = mn->midi_note;
GuiLabel((Rectangle){np.x + 210, np.y + y_cc_note , 20, 20}, sm->midi.midiNotes[(int)round(v)].c_str());
GuiLabel((Rectangle){np.x + 210, np.y + y_cc_note , 20, 20}, MIDI::Notes[(int)round(v)].c_str());
GuiLabel((Rectangle){np.x + 160, np.y + y_cc_note , 40, 20}, std::format("{}",mn->midi_note).c_str());
GuiSlider((Rectangle){np.x + 20, np.y + y_cc_note + 30, 220, 20}, "", "", &v, 0, 127);
mn->midi_note = round(v);
@@ -185,3 +186,4 @@ class AppUI{
}
};
}
+6 -2
View File
@@ -7,7 +7,7 @@
using json = nlohmann::json;
namespace VMath{
namespace VISEQ::VMATH{
template<typename T>
class Vec2D{
@@ -158,4 +158,8 @@ namespace VMath{
}
}
using Vec2Df = VMath::Vec2D<float>;
using Vec2Df = VISEQ::VMATH::Vec2D<float>;