Running again. Next step: making connections work again!

This commit is contained in:
Sebastian
2024-12-05 00:01:42 +01:00
parent 036c6f4723
commit b6c2029386
8 changed files with 56 additions and 58 deletions
+13 -9
View File
@@ -62,30 +62,34 @@ namespace VISEQ::APP {
std::ifstream f("state.json"); std::ifstream f("state.json");
json graph = json::parse(f); json graph = json::parse(f);
for(auto n : graph.at("gm").at("nodes")){
gm->addNodeAndUpdate(n.template get<std::shared_ptr<MidiNode>>());
}
int highest_id = 0; int highest_id = 0;
std::shared_ptr<Node> hid; Node hid;
for(auto n : graph.at("graphmanager").at("nodes")){ for(auto n : graph.at("gm").at("nodes")){
std::shared_ptr<MidiNode> mn = n; MidiNode mn = n.template get<MidiNode>();
if(mn->id > highest_id) { if(mn.id > highest_id) {
highest_id = mn->id; highest_id = mn.id;
hid = mn; hid = mn;
} }
} }
for(auto e : graph.at("graphmanager").at("edges")){ for(auto e : graph.at("gm").at("edges")){
if(e.at("id") > highest_id){ if(e.at("id") > highest_id){
highest_id = e.at("id"); highest_id = e.at("id");
} }
} }
for(auto n : graph.at("graphmanager").at("nodes")){ for(auto n : graph.at("gm").at("nodes")){
std::shared_ptr<MidiNode> mn = n; std::shared_ptr<MidiNode> mn = n;
gm->addNode(mn); gm->addNode(mn);
//app.gm->nodes.push_back(mn); //app.gm->nodes.push_back(mn);
std::cout << std::format("adding node {}", mn->id) << std::endl; std::cout << std::format("adding node {}", mn->id) << std::endl;
} }
for(auto e : graph.at("graphmanager").at("edges")){ for(auto e : graph.at("gm").at("edges")){
int start_id = e.at("start").get<int>(); int start_id = e.at("start").get<int>();
int end_id = e.at("end").get<int>(); int end_id = e.at("end").get<int>();
@@ -103,7 +107,7 @@ namespace VISEQ::APP {
} }
gm->lastEdge().lock()->newId(highest_id); gm->lastEdge().lock()->newId(highest_id);
for(auto s : graph.at("signalmanager").at("signals")){ for(auto s : graph.at("sm").at("signals")){
int start_id = s.at("start").get<int>(); int start_id = s.at("start").get<int>();
int next_id = s.at("next").get<int>(); int next_id = s.at("next").get<int>();
int last_id = s.at("last").get<int>(); int last_id = s.at("last").get<int>();
+4 -3
View File
@@ -8,9 +8,10 @@
#include "state.h" #include "state.h"
#include "vmath.h" #include "vmath.h"
#include <fcntl.h> #include <fcntl.h>
#include <memory>
namespace VISEQ::GRAPH { namespace VISEQ::GRAPH {
class Connector : public BASE::Connectable, public GraphItem{ class Connector : public BASE::Connectable, public GraphItem, public std::enable_shared_from_this<Connector> {
public: public:
Connector() {} Connector() {}
@@ -31,8 +32,8 @@ namespace VISEQ::GRAPH {
return GraphItemType::CONNECTOR; return GraphItemType::CONNECTOR;
} }
std::shared_ptr<Connectable> getPtr(){ std::shared_ptr<Connector> getPtr(){
return std::static_pointer_cast<Connector>(shared_from_this()); return shared_from_this();
} }
virtual bool hovering() override { virtual bool hovering() override {
+1 -7
View File
@@ -3,10 +3,9 @@
#include "raylib.h" #include "raylib.h"
#include "datatypes.h" #include "datatypes.h"
#include "vmath.h" #include "vmath.h"
#include <memory>
namespace VISEQ::GRAPH { namespace VISEQ::GRAPH {
class GraphItem : public std::enable_shared_from_this<GraphItem>{ class GraphItem {
public: public:
GraphItem() {newId(-1);} GraphItem() {newId(-1);}
@@ -17,13 +16,8 @@ namespace VISEQ::GRAPH {
GraphItemType gItemType; GraphItemType gItemType;
int id = 0; int id = 0;
std::shared_ptr<GraphItem> getptr(){
return shared_from_this();
}
void newId(int start){ void newId(int start){
static int _id; static int _id;
if(start > -1) _id = start; if(start > -1) _id = start;
+7 -2
View File
@@ -73,13 +73,18 @@ namespace VISEQ::GRAPH {
nodes.insert(nodes.end(), node); nodes.insert(nodes.end(), node);
} }
void addNodeAndUpdate(SPTR_Node node){
addNode(node);
node->update();
}
void addConnection(WPTR_Node from, WPTR_Node to){ void addConnection(WPTR_Node from, WPTR_Node to){
if(from.lock() != to.lock()) { if(from.lock() != to.lock()) {
edges.emplace_back(std::make_shared<Edge>()); edges.emplace_back(std::make_shared<Edge>());
edges.back()->start = from; edges.back()->start = from;
edges.back()->end = to; edges.back()->end = to;
// edges.back()->start_conn = from.lock()->connectors.back(); // TODO: crashes on start edges.back()->start_conn = from.lock()->connectors.back(); // TODO: crashes on start
// edges.back()->end_conn = to.lock()->connectors.back(); edges.back()->end_conn = to.lock()->connectors.back();
from.lock()->connections.push_back(edges.back()); from.lock()->connections.push_back(edges.back());
to.lock()->connections.push_back(edges.back()); to.lock()->connections.push_back(edges.back());
} }
+2 -2
View File
@@ -16,14 +16,14 @@
#include <memory> #include <memory>
namespace VISEQ::INTERACTION{ namespace VISEQ::INTERACTION{
class ScaleHandle : public BASE::Draggable, public GraphItem{ class ScaleHandle : public BASE::Draggable, public GraphItem, public std::enable_shared_from_this<ScaleHandle>{
public: public:
ScaleHandle(){} ScaleHandle(){}
float radius = 6; float radius = 6;
std::shared_ptr<ScaleHandle> getPtr(){ std::shared_ptr<ScaleHandle> getPtr(){
return std::static_pointer_cast<ScaleHandle>(shared_from_this()); return shared_from_this();
} }
virtual GRAPH::GraphItemType getType() override { virtual GRAPH::GraphItemType getType() override {
+5 -1
View File
@@ -19,7 +19,7 @@ namespace VISEQ::GRAPH::NODES {
bool enabled; bool enabled;
}; };
MidiNode() {} MidiNode() : Node() {std::cout << "MidiNode Constructor std" << std::endl;}
MidiNode(Vec2Df position) : Node(position) {} MidiNode(Vec2Df position) : Node(position) {}
NodeType nodeType = NodeType::MIDINODE; NodeType nodeType = NodeType::MIDINODE;
@@ -63,6 +63,10 @@ namespace VISEQ::GRAPH::NODES {
float time = 0; float time = 0;
float last = 0; float last = 0;
std::shared_ptr<MidiNode> getPtr(){
return std::static_pointer_cast<MidiNode>(shared_from_this());
}
virtual NodeType getNodeType() const override {return nodeType;} virtual NodeType getNodeType() const override {return nodeType;}
void setMidiPort(int midi_port, bool _state){ void setMidiPort(int midi_port, bool _state){
+6 -6
View File
@@ -17,7 +17,7 @@ namespace VISEQ::GRAPH::EDGES{
namespace VISEQ::GRAPH::NODES { namespace VISEQ::GRAPH::NODES {
class Node : public BASE::Draggable, public GraphItem { class Node : public BASE::Draggable, public GraphItem, public std::enable_shared_from_this<Node> {
public: public:
@@ -36,13 +36,17 @@ namespace VISEQ::GRAPH::NODES {
float radius = 15.0f; float radius = 15.0f;
bool config = false; bool config = false;
std::shared_ptr<Node> getPtr(){
return shared_from_this();
}
virtual bool hovering() override { virtual bool hovering() override {
return CheckCollisionPointCircle(SCREEN_MOUSE, position, radius); return CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
} }
void addConnector() { void addConnector() {
connectors.emplace_back(std::make_shared<Connector>(GraphItem::getptr(), position, radius + 5.0f)); connectors.emplace_back(std::make_shared<Connector>(getPtr(), position, radius + 5.0f));
} }
void removeConnector(std::weak_ptr<Connector> connector){ void removeConnector(std::weak_ptr<Connector> connector){
@@ -63,10 +67,6 @@ namespace VISEQ::GRAPH::NODES {
return GraphItemType::NODE; return GraphItemType::NODE;
} }
std::shared_ptr<Node> getPtr(){
return std::static_pointer_cast<Node>(shared_from_this());
}
void update() override{ void update() override{
if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER}); if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER});
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP}); if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
+18 -28
View File
@@ -20,35 +20,25 @@
typedef std::shared_ptr<VISEQ::GRAPH::GraphItem> SPTR_GraphItem; typedef std::shared_ptr<VISEQ::GRAPH::GraphItem> SPTR_GraphItem;
typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem; typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;
namespace nlohmann namespace nlohmann {
{ template <typename T>
template <typename T> struct adl_serializer<std::shared_ptr<T>> {
struct adl_serializer<std::shared_ptr<T>> static void to_json(json& j, const std::shared_ptr<T>& opt) {
{ if (opt) {
static void to_json(json& j, const std::shared_ptr<T>& opt) j = *opt;
{ } else {
if (opt) j = nullptr;
{ }
j = *opt; }
}
else
{
j = nullptr;
}
}
static void from_json(const json& j, std::shared_ptr<T>& opt) static void from_json(const json& j, std::shared_ptr<T>& opt) {
{ if (j.is_null()) {
if (j.is_null()) opt = nullptr;
{ } else {
opt = nullptr; opt.reset(new T(j.get<T>()));
} }
else }
{ };
opt.reset(new T(j.get<T>()));
}
}
};
} }
namespace VISEQ::GRAPH::EDGES { namespace VISEQ::GRAPH::EDGES {