From d881ef43a35e3d73bd0d35f64032ff949c11727b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 12 Jan 2026 00:16:36 +0100 Subject: [PATCH] compiling but mouse interaction is dead --- Makefile | 24 +---- src/Makefile | 40 +++++++++ src/app-manager.cpp | 10 +++ src/app-manager.h | 9 +- src/config-node.cpp | 8 ++ src/config-node.h | 3 + src/edge.cpp | 36 ++++++++ src/edge.h | 17 ++-- src/graph-manager.cpp | 8 ++ src/graph-manager.h | 3 + src/main.cpp | 1 - src/midi-node.cpp | 8 ++ src/midi-node.h | 8 +- src/node.cpp | 36 ++++++++ src/node.h | 8 +- src/signal-manager.cpp | 198 ++++++++++++++++++++++------------------- src/signal-manager.h | 5 +- src/signal.cpp | 30 +++++++ src/signal.h | 8 +- src/state-io.h | 166 ++++++++++------------------------ src/state.cpp | 2 +- src/state.h | 2 +- src/ui.cpp | 1 - 23 files changed, 374 insertions(+), 257 deletions(-) create mode 100644 src/Makefile create mode 100644 src/edge.cpp diff --git a/Makefile b/Makefile index 343962e..a639f4a 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,16 @@ CXX = g++ -CXXFLAGS = -std=c++23 -Wall -g -fno-omit-frame-pointer -gdwarf-4 -Og -Wnarrowing -DLIBREMIDI_ALSA=1 -DLIBREMIDI_HEADER_ONLY=1 -CXXINC = -isysteminclude LDLIBS = -lraylib -lasound -llibremidi -pthread LDFLAGS = -Llib -L/usr/lib -L/usr/local/lib -hdr_files = ${wildcard src/*.h} - -src_files = ${wildcard src/*.cpp} -#src_files += ${wildcard include/libremidi/*.cpp} +hdr_files = $(wildcard src/*.h) all: viseq -viseq: $(src_files) $(hdr_files) +viseq: mkdir -p build - $(CXX) ${wildcard build/*.o} -o viseq $(LDFLAGS) $(LDLIBS) - -$(src_files): %.cpp : %_src - $(CXX) -c $@ -o build/$(*F).o $(CXXFLAGS) $(CXXINC) - -$(hdr_files): %.h : %_hdr - $(NOECHO) $(NOOP) - -%_src: - $(NOECHO) $(NOOP) - -%_hdr: - $(NOECHO) $(NOOP) + cd src; $(MAKE) + $(CXX) $(wildcard build/*.o) -o viseq $(LDFLAGS) $(LDLIBS) clean: rm -f build/* diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..ba078b7 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,40 @@ +CXX = g++ +CXXFLAGS = -std=c++23 -Wall -g -fno-omit-frame-pointer -gdwarf-4 -Og -Wnarrowing -DLIBREMIDI_ALSA=1 -DLIBREMIDI_HEADER_ONLY=1 +CXXINC = -I../include -isysteminclude + +obj_files = main.o app-manager.o graph-manager.o signal-manager.o interaction-manager.o ui.o node.o midi-node.o config-node.o modifier-node.o midi.o signal.o canvas.o state.o edge.o + + +all: $(obj_files) + +$(obj_files): %.o : %.cpp + $(CXX) -c $^ -o ../build/$@ $(CXXFLAGS) $(CXXINC) + +#all: viseq + +#viseq: main.o app-manager.o graph-manager.o signal-manager.o interaction-manager.o ui.o node.o midi-node.o config-node.o modifier-node.o midi.o signal.o canvas.o state.o edge.o +# $(CXX) ${wildcard build/*.o} -o viseq $(LDFLAGS) $(LDLIBS) + +#main.o: +# $(CXX) -c src/main.cpp -o ../build/main.o $(CXXFLAGS) $(CXXINC) +# +#app-manager.o: +# $(CXX) -c src/app-manager.cpp -o ../build/app-manager.o $(CXXFLAGS) $(CXXINC) + + + +#src/canvas.cpp +#src/signal.cpp +#src/midi.cpp +#src/node.cpp +#src/graph-manager.cpp +#src/modifier-node.cpp +#src/config-node.cpp +#src/midi-node.cpp +#src/ui.cpp +#src/state.cpp +#src/edge.cpp +#src/interaction-manager.cpp +#src/signal-manager.cpp +#src/app-manager.cpp +#src/main.cpp diff --git a/src/app-manager.cpp b/src/app-manager.cpp index 2d8ca17..89abaa8 100644 --- a/src/app-manager.cpp +++ b/src/app-manager.cpp @@ -1,5 +1,15 @@ #include "app-manager.h" +#include "interaction-manager.h" +#include "nlohmann/json.hpp" +#include "graph-manager.h" +#include "midi-node.h" +#include "state.h" +#include "ui.h" + +#include +#include + namespace VISEQ::APP{ void AppManager::init(){ canvas->camera.target = (Vector2){ state->settings.width/2.0f, state->settings.height/2.0f }; diff --git a/src/app-manager.h b/src/app-manager.h index 6ae03fc..c0f80f3 100644 --- a/src/app-manager.h +++ b/src/app-manager.h @@ -1,15 +1,10 @@ #pragma once -#include -#include #include "interaction-manager.h" #include "nlohmann/json.hpp" -#include "datatypes.h" #include "canvas.h" #include "graph-manager.h" #include "midi-node.h" -#include "node.h" -#include "raylib.h" #include "signal-manager.h" #include "state.h" #include "ui.h" @@ -34,8 +29,6 @@ namespace VISEQ::APP { UI::AppUI ui; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppManager, gm, sm); - void init(); void close(); void startSignals(); @@ -45,5 +38,7 @@ namespace VISEQ::APP { void draw(); void drawUI(); }; + + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(AppManager, gm, sm) } diff --git a/src/config-node.cpp b/src/config-node.cpp index 660a0bf..5557bc5 100644 --- a/src/config-node.cpp +++ b/src/config-node.cpp @@ -282,4 +282,12 @@ namespace VISEQ::GRAPH::NODES { //j.at("connections").get_to(N.connections); } + + void to_json(json& j, const std::shared_ptr& N){ + j = *N; + } + + void from_json(const json& j, std::shared_ptr& N){ + N.reset(new ConfigNode(j.get())); + } }; diff --git a/src/config-node.h b/src/config-node.h index 477afc2..952f3a4 100644 --- a/src/config-node.h +++ b/src/config-node.h @@ -42,7 +42,10 @@ namespace VISEQ::GRAPH::NODES { void update() override; void interact(); void draw(Vec2Df mouse, Camera2D cam) override; + friend void to_json(json& j, const ConfigNode& N); friend void from_json(const json& j, ConfigNode& N); + friend void to_json(json& j, const std::shared_ptr& N); + friend void from_json(const json& j, std::shared_ptr& N); }; } diff --git a/src/edge.cpp b/src/edge.cpp new file mode 100644 index 0000000..9e4dd70 --- /dev/null +++ b/src/edge.cpp @@ -0,0 +1,36 @@ +#include "edge.h" + +#include +#include "node.h" + +namespace VISEQ::GRAPH::EDGES { + bool Edge::GActive() {return active;} + + EdgeType Edge::getEdgeType() const {return edgeType;} + + std::weak_ptr Edge::getNextNode(std::weak_ptr origin){ + return start.lock() == origin.lock() ? end : start; + } + + void Edge::draw(Vec2Df mouse_pos, Camera2D cam) {} + + void to_json(json& j, const VISEQ::GRAPH::EDGES::Edge& E){ + j = json{{"id",E.id}, {"start", E.start.lock()->id}, {"end",E.end.lock()->id}, {"pass_forward",E.pass_forward}, {"pass_backward", E.pass_backward}}; + } + + 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); + } + + void to_json(json& j, const VISEQ::GRAPH::EDGES::SPTR_Edge& E){ + j = *E; + } + + void from_json(const json& j, VISEQ::GRAPH::EDGES::SPTR_Edge& E){ + E.reset(new Edge(j.get())); + } + + +} diff --git a/src/edge.h b/src/edge.h index 4515109..24517f2 100644 --- a/src/edge.h +++ b/src/edge.h @@ -35,15 +35,14 @@ namespace VISEQ::GRAPH::EDGES { float connector_offset = 8.0f; float switches_offset = 25.0f; - virtual bool GActive() {return active;} - - virtual EdgeType getEdgeType() const {return edgeType;} - - std::weak_ptr getNextNode(std::weak_ptr origin){ - return start.lock() == origin.lock() ? end : start; - } - - void draw(Vec2Df mouse_pos, Camera2D cam) {} + virtual bool GActive(); + virtual EdgeType getEdgeType() const; + std::weak_ptr getNextNode(std::weak_ptr origin); + void draw(Vec2Df mouse_pos, Camera2D cam); + friend void to_json(json& j, const Edge& E); + friend void from_json(const json& j, Edge& E); + friend void to_json(json& j, const std::shared_ptr& E); + friend void from_json(const json& j, std::shared_ptr& E); }; typedef std::shared_ptr SPTR_Edge; diff --git a/src/graph-manager.cpp b/src/graph-manager.cpp index 1dab649..ce6731e 100644 --- a/src/graph-manager.cpp +++ b/src/graph-manager.cpp @@ -460,4 +460,12 @@ namespace VISEQ::GRAPH{ n->draw(mouse_pos, camera); } } + + void to_json(json& j, const std::shared_ptr& G){ + j = *G; + } + + void from_json(const json& j, std::shared_ptr& G){ + G.reset(new GraphManager(j.get())); + } } diff --git a/src/graph-manager.h b/src/graph-manager.h index a34dbb5..4e0c86d 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -80,6 +80,9 @@ namespace VISEQ::GRAPH { void drawNodes(Vec2Df mouse_pos, Camera2D camera); NLOHMANN_DEFINE_TYPE_INTRUSIVE(GraphManager, nodes, edges, selected_nodes) + + friend void from_json(const json& j, std::shared_ptr& G); + friend void to_json(json& j, const std::shared_ptr& G); }; } diff --git a/src/main.cpp b/src/main.cpp index b9ea6a9..faf141a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,6 @@ #include #include -#include #include diff --git a/src/midi-node.cpp b/src/midi-node.cpp index 960b65f..e36a0a6 100644 --- a/src/midi-node.cpp +++ b/src/midi-node.cpp @@ -387,5 +387,13 @@ namespace VISEQ::GRAPH::NODES { i++; } } + + void to_json(json& j, const std::shared_ptr& N){ + j = *N; + } + + void from_json(const json& j, std::shared_ptr& N){ + N.reset(new MidiNode(j.get())); + } } diff --git a/src/midi-node.h b/src/midi-node.h index a9975bc..e9cc84a 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -85,7 +85,11 @@ namespace VISEQ::GRAPH::NODES { void modMidiPolyPressure(int incr); void interact(); void draw(Vec2Df mouse, Camera2D cam) override ; - friend void to_json(json& j, const MidiNode& N); - friend void from_json(const json& j, MidiNode& N); + + friend void to_json(json& j, const MidiNode& N); + friend void from_json(const json& j, MidiNode& N); + friend void to_json(json& j, const std::shared_ptr& N); + friend void from_json(const json& j, std::shared_ptr& N); }; + } diff --git a/src/node.cpp b/src/node.cpp index d986b81..6735099 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -9,6 +9,9 @@ #include "state.h" #include "vmath.h" +#include "midi-node.h" +#include "config-node.h" + namespace VISEQ::GRAPH::NODES { void Node::setMode(int _mode) {mode = _mode;} @@ -70,4 +73,37 @@ namespace VISEQ::GRAPH::NODES { c->draw(); } } + + void to_json(json& j, const Node& N){ + if(N.getNodeType() == NodeType::MIDINODE){ + j = dynamic_cast(N); + } + if(N.getNodeType() == NodeType::CONFIGNODE){ + j = dynamic_cast(N); + } + } + + void from_json(const json& j, Node& N){ + + if(j.at("nodeType") == NodeType::MIDINODE){ + N = j.template get(); + } + if(j.at("nodeType") == NodeType::CONFIGNODE){ + N = j.template get(); + } + } + + void to_json(json& j, const SPTR_Node& N){ + j = *N; + } + + void from_json(const json& j, std::shared_ptr& N){ + std::cout << "SPTR_Node" << std::endl; + if(N->getNodeType() == NodeType::MIDINODE){ + N.reset(new MidiNode(j.get())); + } + if(N->getNodeType() == NodeType::CONFIGNODE){ + N.reset(new ConfigNode(j.get())); + } + } } diff --git a/src/node.h b/src/node.h index 03a6d6a..5693408 100644 --- a/src/node.h +++ b/src/node.h @@ -18,8 +18,7 @@ namespace VISEQ::GRAPH::NODES { class Node : public BASE::Draggable, public GraphItem, public std::enable_shared_from_this { public: - - Node() {std::cout << "Node constructor" << std::endl;} + Node() {} Node(float x, float y) : Draggable(Vec2Df(x, y)) {} Node(Vec2Df p) : Draggable(p) {} @@ -54,6 +53,11 @@ namespace VISEQ::GRAPH::NODES { void draw(Vec2Df mp, Camera2D cam) override; void draw() override; + friend void to_json(json& j, const Node& N); + friend void from_json(const json& j, Node& N); + friend void to_json(json& j, const std::shared_ptr& N); + friend void from_json(const json& j, std::shared_ptr& N); + }; typedef std::shared_ptr SPTR_Node; diff --git a/src/signal-manager.cpp b/src/signal-manager.cpp index 487fda2..e1fe7ac 100644 --- a/src/signal-manager.cpp +++ b/src/signal-manager.cpp @@ -10,122 +10,132 @@ #include #include +namespace VISEQ::SIGNAL { -void VISEQ::SIGNAL::SignalManager::pause(){ - play = false; -} - -void VISEQ::SIGNAL::SignalManager::stop(){ - play = false; - reset(); -} - -void VISEQ::SIGNAL::SignalManager::start(){ - play = true; -} - -void VISEQ::SIGNAL::SignalManager::reset(){ - for(auto &s : signals){ - s->position = s->start.lock()->position + Vec2Df{0.1, 0.1}; - s->next = s->start; - s->last = s->start; + void SignalManager::pause(){ + play = false; } - gm->reset(); -} -void VISEQ::SIGNAL::SignalManager::startSignalThread(){ - std::thread t1(&SignalManager::updateSignals, this); - t1.detach(); -} + void SignalManager::stop(){ + play = false; + reset(); + } -void VISEQ::SIGNAL::SignalManager::stopSignalThread(){ - loop = false; -} + void SignalManager::start(){ + play = true; + } -void VISEQ::SIGNAL::SignalManager::addSignalAtNode(WPTR_Node node){ - Color c = {(unsigned char)(20 + (rand() % 200)), 100, (unsigned char)(20 + (int)(rand() % 200)), 200}; - signals.emplace_back(std::make_shared(node.lock()->position + Vec2Df{0.5f, 0.5f}, 8.0f, 480, c)); // position + 1 or else it does not render. why? no idea! - signals.back()->next = node; - signals.back()->last = node; - signals.back()->start = node; -} - -void VISEQ::SIGNAL::SignalManager::rerouteSignal(VEC_SPTR_Node nodes, VEC_WPTR_Node adjacent_nodes){ - auto reroute_signals = signals | RANGE_FILTER([nodes](SIGNAL::SPTR_Signal s){return std::ranges::contains(nodes, s->next.lock());}); - - for(auto s : reroute_signals){ - float dist = 10000000; - SPTR_Node next_node; - for(auto n : adjacent_nodes){ - if(n.lock()->position.dist(s->position) < dist) { - dist = n.lock()->position.dist(s->position); - next_node = n.lock(); - } + void SignalManager::reset(){ + for(auto &s : signals){ + s->position = s->start.lock()->position + Vec2Df{0.1, 0.1}; + s->next = s->start; + s->last = s->start; } - s->next = next_node; - s->last = next_node; + gm->reset(); } -} - -void VISEQ::SIGNAL::SignalManager::rebaseSignal(VEC_SPTR_Node nodes){ - auto rebase_signals = signals | RANGE_FILTER([nodes](SIGNAL::SPTR_Signal s){return std::ranges::contains(nodes, s->start.lock());}); - - for(auto s : rebase_signals){ - s->start = s->next; + void SignalManager::startSignalThread(){ + std::thread t1(&SignalManager::updateSignals, this); + t1.detach(); } -} -void VISEQ::SIGNAL::SignalManager::removeSignal(std::shared_ptr s){ - erase_signals.push_back(s); -} + void SignalManager::stopSignalThread(){ + loop = false; + } -void VISEQ::SIGNAL::SignalManager::updateSignals(){ - auto last = std::chrono::high_resolution_clock::now(); - while(loop){ - std::chrono::duration diff = std::chrono::high_resolution_clock::now() - last; - if((int)diff.count() >= 250){ - mutex->lock(); - if(play){ - for(auto& s : signals){ - s->direction = (s->next.lock()->position - s->position).norm(); - s->update(diff.count()); - if(s->position.dist(s->next.lock()->position) < 0.6f) { - WPTR_Node next_node = gm->next(s->next, s->last); - s->next.lock()->trigger(); + void SignalManager::addSignalAtNode(WPTR_Node node){ + Color c = {(unsigned char)(20 + (rand() % 200)), 100, (unsigned char)(20 + (int)(rand() % 200)), 200}; + signals.emplace_back(std::make_shared(node.lock()->position + Vec2Df{0.5f, 0.5f}, 8.0f, 480, c)); // position + 1 or else it does not render. why? no idea! + signals.back()->next = node; + signals.back()->last = node; + signals.back()->start = node; + } - if(next_node.lock() != s->next.lock() && !next_node.expired() && s->next.lock()->getNodeType() == NodeType::MIDINODE) { - auto midinode = std::dynamic_pointer_cast(s->next.lock()); - for(auto &m : midinode->midi_outs){ - if(m.second.enabled) { - if(midinode->send_note) midi.note(m.second.i, midinode->getNotes().channel, (int)Clamp(midinode->getNotes().note + s->midi_note_offset, 0, 127), midinode->getNotes().velocity, midinode->getNotes().gate); - if(midinode->send_cc) midi.cc(m.second.i, midinode->getCC().channel, midinode->getCC().control, (int)Clamp(midinode->getCC().value + s->midi_cc_offset, 0, 127)); - if(midinode->send_pitch_bend) midi.pitch_bend(m.second.i, midinode->getPitchBend().channel, midinode->getPitchBend().value); + void SignalManager::rerouteSignal(VEC_SPTR_Node nodes, VEC_WPTR_Node adjacent_nodes){ + auto reroute_signals = signals | RANGE_FILTER([nodes](SIGNAL::SPTR_Signal s){return std::ranges::contains(nodes, s->next.lock());}); + + for(auto s : reroute_signals){ + float dist = 10000000; + SPTR_Node next_node; + for(auto n : adjacent_nodes){ + if(n.lock()->position.dist(s->position) < dist) { + dist = n.lock()->position.dist(s->position); + next_node = n.lock(); + } + } + s->next = next_node; + s->last = next_node; + } + + } + + void SignalManager::rebaseSignal(VEC_SPTR_Node nodes){ + auto rebase_signals = signals | RANGE_FILTER([nodes](SIGNAL::SPTR_Signal s){return std::ranges::contains(nodes, s->start.lock());}); + + for(auto s : rebase_signals){ + s->start = s->next; + } + } + + void SignalManager::removeSignal(std::shared_ptr s){ + erase_signals.push_back(s); + } + + void SignalManager::updateSignals(){ + auto last = std::chrono::high_resolution_clock::now(); + while(loop){ + std::chrono::duration diff = std::chrono::high_resolution_clock::now() - last; + if((int)diff.count() >= 250){ + mutex->lock(); + if(play){ + for(auto& s : signals){ + s->direction = (s->next.lock()->position - s->position).norm(); + s->update(diff.count()); + if(s->position.dist(s->next.lock()->position) < 0.6f) { + WPTR_Node next_node = gm->next(s->next, s->last); + s->next.lock()->trigger(); + + if(next_node.lock() != s->next.lock() && !next_node.expired() && s->next.lock()->getNodeType() == NodeType::MIDINODE) { + auto midinode = std::dynamic_pointer_cast(s->next.lock()); + for(auto &m : midinode->midi_outs){ + if(m.second.enabled) { + if(midinode->send_note) midi.note(m.second.i, midinode->getNotes().channel, (int)Clamp(midinode->getNotes().note + s->midi_note_offset, 0, 127), midinode->getNotes().velocity, midinode->getNotes().gate); + if(midinode->send_cc) midi.cc(m.second.i, midinode->getCC().channel, midinode->getCC().control, (int)Clamp(midinode->getCC().value + s->midi_cc_offset, 0, 127)); + if(midinode->send_pitch_bend) midi.pitch_bend(m.second.i, midinode->getPitchBend().channel, midinode->getPitchBend().value); + } } + s->last = s->next; + s->next = next_node; } - s->last = s->next; - s->next = next_node; } } } + midi.update(); + mutex->unlock(); + last = std::chrono::high_resolution_clock::now(); } - midi.update(); - mutex->unlock(); - last = std::chrono::high_resolution_clock::now(); } } -} -void VISEQ::SIGNAL::SignalManager::drawSignals(Vec2Df mouse_pos, Camera2D camera){ - mutex->lock(); - if(!erase_signals.empty()){ - for(auto s: erase_signals){ - std::erase(signals, s); + void SignalManager::drawSignals(Vec2Df mouse_pos, Camera2D camera){ + mutex->lock(); + if(!erase_signals.empty()){ + for(auto s: erase_signals){ + std::erase(signals, s); + } + erase_signals.clear(); } - erase_signals.clear(); + for(auto s : signals){ + s->draw(mouse_pos, camera); + } + mutex->unlock(); } - for(auto s : signals){ - s->draw(mouse_pos, camera); + + void to_json(json& j, const std::shared_ptr& G){ + j = *G; + } + + void from_json(const json& j, std::shared_ptr& G){ + G.reset(new SignalManager(j.get())); } - mutex->unlock(); } diff --git a/src/signal-manager.h b/src/signal-manager.h index f29fa2a..005a53a 100644 --- a/src/signal-manager.h +++ b/src/signal-manager.h @@ -50,6 +50,9 @@ namespace VISEQ::SIGNAL { void drawSignals(Vec2Df mouse_pos, Camera2D camera); NLOHMANN_DEFINE_TYPE_INTRUSIVE(SignalManager, signals) - + + friend void from_json(const json& j, std::shared_ptr& G); + friend void to_json(json& j, const std::shared_ptr& G); + }; } diff --git a/src/signal.cpp b/src/signal.cpp index c123514..6058eb5 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -22,4 +22,34 @@ namespace VISEQ::SIGNAL { void Signal::draw(Vec2Df mouse, Camera2D cam) { DrawCircle(position.x, position.y, radius, color); } + + void to_json(json& j, const Signal& S){ + std::map fc = {{"r",S.color.r},{"g",S.color.g},{"b",S.color.b},{"a",S.color.a}}; + j = json{{"color",fc},{"position", S.position},{"radius",S.radius},{"start",S.start.lock()->id},{"next",S.next.lock()->id},{"last",S.last.lock()->id},{"speed",S.speed},{"midi_note_offset",S.midi_note_offset},{"midi_cc_offset",S.midi_cc_offset},{"multiplier",S.multiplier}}; + } + + void from_json(const json& j, Signal& S){ + + Color c; + c.r = j.at("color")["r"].get(); + c.g = j.at("color")["g"].get(); + c.b = j.at("color")["b"].get(); + c.a = j.at("color")["a"].get(); + + j.at("position").get_to(S.position); + j.at("speed").get_to(S.speed); + j.at("radius").get_to(S.radius); + j.at("midi_note_offset").get_to(S.midi_note_offset); + j.at("midi_cc_offset").get_to(S.midi_cc_offset); + + S.color = c; + } + + void to_json(json& j, const std::shared_ptr& S){ + j = *S; + } + + void from_json(const json& j, std::shared_ptr& S){ + S.reset(new Signal(j.get())); + } } diff --git a/src/signal.h b/src/signal.h index 5edb5d9..587faf5 100644 --- a/src/signal.h +++ b/src/signal.h @@ -38,7 +38,13 @@ namespace VISEQ::SIGNAL { void reset(); void toStart(); void update(double t_delta); - void draw(Vec2Df mouse, Camera2D cam) ; + void draw(Vec2Df mouse, Camera2D cam); + + friend void to_json(json& j, const Signal& S); + friend void from_json(const json& j, Signal& S); + friend void to_json(json& j, const std::shared_ptr& S); + friend void from_json(const json& j, std::shared_ptr& S); + }; } diff --git a/src/state-io.h b/src/state-io.h index ccd7154..1bc3b39 100644 --- a/src/state-io.h +++ b/src/state-io.h @@ -15,94 +15,26 @@ typedef std::shared_ptr SPTR_GraphItem; typedef std::vector VEC_SPTR_GraphItem; -namespace nlohmann { - template - 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 T(j.get())); - } - } - }; -} - -namespace VISEQ::GRAPH::EDGES { - using namespace VISEQ::GRAPH::NODES; - - inline void to_json(json& j, const VISEQ::GRAPH::EDGES::Edge& E){ - j = json{{"id",E.id}, {"start", E.start.lock()->id}, {"end",E.end.lock()->id}, {"pass_forward",E.pass_forward}, {"pass_backward", E.pass_backward}}; - } - - 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())); - } -} - -namespace VISEQ::GRAPH::NODES { - - /* ------------------- MIDINODE ---------------------- */ - - inline void to_json(json& j, const MidiNode::NodeMidiOut& MO){ - j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}}; - } - - /* ------------------- NODE ---------------------- */ - - inline void to_json(json& j, const Node& N){ - if(N.getNodeType() == NodeType::MIDINODE){ - j = dynamic_cast(N); - } - if(N.getNodeType() == NodeType::CONFIGNODE){ - j = dynamic_cast(N); - } - } - - inline void from_json(const json& j, Node& N){ - - if(j.at("nodeType") == NodeType::MIDINODE){ - N = j.template get(); - } - if(j.at("nodeType") == NodeType::CONFIGNODE){ - N = j.template get(); - } - } - - inline void to_json(json& j, const SPTR_Node& N){ - j = *N; - } - - inline void from_json(const json& j, std::shared_ptr& N){ - std::cout << "SPTR_Node" << std::endl; - if(N->getNodeType() == NodeType::MIDINODE){ - N.reset(new MidiNode(j.get())); - } - if(N->getNodeType() == NodeType::CONFIGNODE){ - N.reset(new ConfigNode(j.get())); - } - } - -} - +//namespace nlohmann { +// template +// 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 T(j.get())); +// } +// } +// }; +//} namespace VISEQ::GRAPH { inline void to_json(json& j, const GraphItem& G){ @@ -136,35 +68,35 @@ namespace VISEQ::BASE{ } namespace VISEQ::SIGNAL{ - inline void to_json(json& j, const Signal& G){ - std::map fc = {{"r",G.color.r},{"g",G.color.g},{"b",G.color.b},{"a",G.color.a}}; - j = json{{"color",fc},{"position", G.position},{"radius",G.radius},{"start",G.start.lock()->id},{"next",G.next.lock()->id},{"last",G.last.lock()->id},{"speed",G.speed},{"midi_note_offset",G.midi_note_offset},{"midi_cc_offset",G.midi_cc_offset},{"multiplier",G.multiplier}}; - } - - inline void from_json(const json& j, Signal& S){ - - Color c; - c.r = j.at("color")["r"].get(); - c.g = j.at("color")["g"].get(); - c.b = j.at("color")["b"].get(); - c.a = j.at("color")["a"].get(); - - j.at("position").get_to(S.position); - j.at("speed").get_to(S.speed); - j.at("radius").get_to(S.radius); - j.at("midi_note_offset").get_to(S.midi_note_offset); - j.at("midi_cc_offset").get_to(S.midi_cc_offset); - - S.color = c; - } - - inline void to_json(json& j, const std::shared_ptr& G){ - j = *G; - } - - inline void from_json(const json& j, std::shared_ptr& S){ - S.reset(new Signal(j.get())); - } +// inline void to_json(json& j, const Signal& G){ +// std::map fc = {{"r",G.color.r},{"g",G.color.g},{"b",G.color.b},{"a",G.color.a}}; +// j = json{{"color",fc},{"position", G.position},{"radius",G.radius},{"start",G.start.lock()->id},{"next",G.next.lock()->id},{"last",G.last.lock()->id},{"speed",G.speed},{"midi_note_offset",G.midi_note_offset},{"midi_cc_offset",G.midi_cc_offset},{"multiplier",G.multiplier}}; +// } +// +// inline void from_json(const json& j, Signal& S){ +// +// Color c; +// c.r = j.at("color")["r"].get(); +// c.g = j.at("color")["g"].get(); +// c.b = j.at("color")["b"].get(); +// c.a = j.at("color")["a"].get(); +// +// j.at("position").get_to(S.position); +// j.at("speed").get_to(S.speed); +// j.at("radius").get_to(S.radius); +// j.at("midi_note_offset").get_to(S.midi_note_offset); +// j.at("midi_cc_offset").get_to(S.midi_cc_offset); +// +// S.color = c; +// } +// +// inline void to_json(json& j, const std::shared_ptr& G){ +// j = *G; +// } +// +// inline void from_json(const json& j, std::shared_ptr& S){ +// S.reset(new Signal(j.get())); +// } } diff --git a/src/state.cpp b/src/state.cpp index d733e73..2fb8393 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -64,7 +64,7 @@ namespace VISEQ::APP{ old_istate = istate; } - inline static std::shared_ptr get() { + std::shared_ptr State::get() { if(!State::instance){ State::instance.reset(new State()); } diff --git a/src/state.h b/src/state.h index a2926ce..a331dd4 100644 --- a/src/state.h +++ b/src/state.h @@ -92,7 +92,7 @@ namespace VISEQ::APP{ void update(Camera2D camera); inline static std::shared_ptr instance; - inline static std::shared_ptr get(); + static std::shared_ptr get(); }; } diff --git a/src/ui.cpp b/src/ui.cpp index 278f6f3..951edd4 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -4,7 +4,6 @@ #include "midi-node.h" #include "raylib.h" #include "raygui/raygui.h" -#include "raygui/dark/style_dark.h" #include "datatypes.h"