Running again. Next step: making connections work again!
This commit is contained in:
+13
-9
@@ -62,30 +62,34 @@ namespace VISEQ::APP {
|
||||
std::ifstream f("state.json");
|
||||
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;
|
||||
std::shared_ptr<Node> hid;
|
||||
for(auto n : graph.at("graphmanager").at("nodes")){
|
||||
std::shared_ptr<MidiNode> mn = n;
|
||||
if(mn->id > highest_id) {
|
||||
highest_id = mn->id;
|
||||
Node hid;
|
||||
for(auto n : graph.at("gm").at("nodes")){
|
||||
MidiNode mn = n.template get<MidiNode>();
|
||||
if(mn.id > highest_id) {
|
||||
highest_id = mn.id;
|
||||
hid = mn;
|
||||
}
|
||||
}
|
||||
|
||||
for(auto e : graph.at("graphmanager").at("edges")){
|
||||
for(auto e : graph.at("gm").at("edges")){
|
||||
if(e.at("id") > highest_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;
|
||||
gm->addNode(mn);
|
||||
//app.gm->nodes.push_back(mn);
|
||||
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 end_id = e.at("end").get<int>();
|
||||
|
||||
@@ -103,7 +107,7 @@ namespace VISEQ::APP {
|
||||
}
|
||||
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 next_id = s.at("next").get<int>();
|
||||
int last_id = s.at("last").get<int>();
|
||||
|
||||
+4
-3
@@ -8,9 +8,10 @@
|
||||
#include "state.h"
|
||||
#include "vmath.h"
|
||||
#include <fcntl.h>
|
||||
#include <memory>
|
||||
|
||||
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:
|
||||
Connector() {}
|
||||
|
||||
@@ -31,8 +32,8 @@ namespace VISEQ::GRAPH {
|
||||
return GraphItemType::CONNECTOR;
|
||||
}
|
||||
|
||||
std::shared_ptr<Connectable> getPtr(){
|
||||
return std::static_pointer_cast<Connector>(shared_from_this());
|
||||
std::shared_ptr<Connector> getPtr(){
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
virtual bool hovering() override {
|
||||
|
||||
+1
-7
@@ -3,10 +3,9 @@
|
||||
#include "raylib.h"
|
||||
#include "datatypes.h"
|
||||
#include "vmath.h"
|
||||
#include <memory>
|
||||
|
||||
namespace VISEQ::GRAPH {
|
||||
class GraphItem : public std::enable_shared_from_this<GraphItem>{
|
||||
class GraphItem {
|
||||
|
||||
public:
|
||||
GraphItem() {newId(-1);}
|
||||
@@ -17,13 +16,8 @@ namespace VISEQ::GRAPH {
|
||||
|
||||
GraphItemType gItemType;
|
||||
|
||||
|
||||
int id = 0;
|
||||
|
||||
std::shared_ptr<GraphItem> getptr(){
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
void newId(int start){
|
||||
static int _id;
|
||||
if(start > -1) _id = start;
|
||||
|
||||
+7
-2
@@ -73,13 +73,18 @@ namespace VISEQ::GRAPH {
|
||||
nodes.insert(nodes.end(), node);
|
||||
}
|
||||
|
||||
void addNodeAndUpdate(SPTR_Node node){
|
||||
addNode(node);
|
||||
node->update();
|
||||
}
|
||||
|
||||
void addConnection(WPTR_Node from, WPTR_Node to){
|
||||
if(from.lock() != to.lock()) {
|
||||
edges.emplace_back(std::make_shared<Edge>());
|
||||
edges.back()->start = from;
|
||||
edges.back()->end = to;
|
||||
// edges.back()->start_conn = from.lock()->connectors.back(); // TODO: crashes on start
|
||||
// edges.back()->end_conn = to.lock()->connectors.back();
|
||||
edges.back()->start_conn = from.lock()->connectors.back(); // TODO: crashes on start
|
||||
edges.back()->end_conn = to.lock()->connectors.back();
|
||||
from.lock()->connections.push_back(edges.back());
|
||||
to.lock()->connections.push_back(edges.back());
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
#include <memory>
|
||||
|
||||
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:
|
||||
ScaleHandle(){}
|
||||
|
||||
float radius = 6;
|
||||
|
||||
std::shared_ptr<ScaleHandle> getPtr(){
|
||||
return std::static_pointer_cast<ScaleHandle>(shared_from_this());
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
virtual GRAPH::GraphItemType getType() override {
|
||||
|
||||
+5
-1
@@ -19,7 +19,7 @@ namespace VISEQ::GRAPH::NODES {
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
MidiNode() {}
|
||||
MidiNode() : Node() {std::cout << "MidiNode Constructor std" << std::endl;}
|
||||
MidiNode(Vec2Df position) : Node(position) {}
|
||||
|
||||
NodeType nodeType = NodeType::MIDINODE;
|
||||
@@ -63,6 +63,10 @@ namespace VISEQ::GRAPH::NODES {
|
||||
float time = 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;}
|
||||
|
||||
void setMidiPort(int midi_port, bool _state){
|
||||
|
||||
+6
-6
@@ -17,7 +17,7 @@ namespace VISEQ::GRAPH::EDGES{
|
||||
|
||||
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:
|
||||
|
||||
@@ -36,13 +36,17 @@ namespace VISEQ::GRAPH::NODES {
|
||||
|
||||
float radius = 15.0f;
|
||||
bool config = false;
|
||||
|
||||
std::shared_ptr<Node> getPtr(){
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
virtual bool hovering() override {
|
||||
return CheckCollisionPointCircle(SCREEN_MOUSE, position, radius);
|
||||
}
|
||||
|
||||
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){
|
||||
@@ -63,10 +67,6 @@ namespace VISEQ::GRAPH::NODES {
|
||||
return GraphItemType::NODE;
|
||||
}
|
||||
|
||||
std::shared_ptr<Node> getPtr(){
|
||||
return std::static_pointer_cast<Node>(shared_from_this());
|
||||
}
|
||||
|
||||
void update() override{
|
||||
if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER});
|
||||
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
|
||||
|
||||
+18
-28
@@ -20,35 +20,25 @@
|
||||
typedef std::shared_ptr<VISEQ::GRAPH::GraphItem> SPTR_GraphItem;
|
||||
typedef std::vector<SPTR_GraphItem> VEC_SPTR_GraphItem;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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>()));
|
||||
}
|
||||
}
|
||||
};
|
||||
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>()));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace VISEQ::GRAPH::EDGES {
|
||||
|
||||
Reference in New Issue
Block a user