fishy loss of changes here...
This commit is contained in:
+23
-25
@@ -2,8 +2,7 @@
|
||||
|
||||
#include "connection.h"
|
||||
#include "datatypes.h"
|
||||
#include "node-manager.h"
|
||||
#include "connection-manager.h"
|
||||
#include "graph-manager.h"
|
||||
#include "signal-manager.h"
|
||||
#include "ui.h"
|
||||
|
||||
@@ -15,7 +14,7 @@
|
||||
class AppState{
|
||||
public:
|
||||
|
||||
AppState() : cm(&nm), sm(&nm, &cm, &mutex), ui(&settings, &nm, &cm, &sm) {}
|
||||
AppState() : sm(&gm, &mutex), ui(&settings, &sm, &gm) {}
|
||||
|
||||
enum States {IDLE, CONFIG};
|
||||
|
||||
@@ -25,14 +24,13 @@ class AppState{
|
||||
|
||||
std::mutex mutex;
|
||||
|
||||
ConnectionManager cm;
|
||||
GraphManager gm;
|
||||
SignalManager sm;
|
||||
NodeManager nm;
|
||||
|
||||
AppUI ui;
|
||||
|
||||
void updateMidiPorts(){
|
||||
for(auto&n : nm.nodes | std::views::values){
|
||||
for(auto&n : gm.nodes | std::views::values){
|
||||
for(auto& mo : sm.midi.midi_out_ports){
|
||||
if(!n.midi_outs.contains(mo.number) && mo.enabled){
|
||||
n.midi_outs[mo.number] = {mo.number, mo.port.port_name, false};
|
||||
@@ -45,16 +43,16 @@ class AppState{
|
||||
}
|
||||
|
||||
void copyNodesAndConnections(Vec2D<float> position){
|
||||
auto copy_nodes_ids = nm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n){return n.copied;}) | std::views::transform([](Node n){return n.id;}) | std::ranges::to<std::vector<int>>();
|
||||
auto copy_nodes_ids = gm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n){return n.copied;}) | std::views::transform([](Node n){return n.id;}) | std::ranges::to<std::vector<int>>();
|
||||
|
||||
std::vector<Connection> copy_connections;
|
||||
std::ranges::copy_if(cm.connections, std::back_inserter(copy_connections), [copy_nodes_ids](Connection c){return std::ranges::contains(copy_nodes_ids, c.v1) && std::ranges::contains(copy_nodes_ids, c.v2);});
|
||||
std::ranges::copy_if(gm.connections, std::back_inserter(copy_connections), [copy_nodes_ids](Connection c){return std::ranges::contains(copy_nodes_ids, c.v1) && std::ranges::contains(copy_nodes_ids, c.v2);});
|
||||
|
||||
for(auto &n : copy_nodes_ids){
|
||||
int old_id = n;
|
||||
int new_id = nm.copyNode(n, position + nm.nodes[n].drag_offset);
|
||||
nm.nodes[new_id].copied = false;
|
||||
nm.nodes[new_id].selected = true;
|
||||
int new_id = gm.copyNode(n, position + gm.nodes[n].drag_offset);
|
||||
gm.nodes[new_id].copied = false;
|
||||
gm.nodes[new_id].selected = true;
|
||||
|
||||
for(auto &c : copy_connections){
|
||||
if(c.v1 == old_id) c.v1 = new_id;
|
||||
@@ -62,29 +60,29 @@ class AppState{
|
||||
}
|
||||
}
|
||||
|
||||
cm.connections.insert(cm.connections.end(), copy_connections.cbegin(), copy_connections.cend());
|
||||
gm.connections.insert(gm.connections.end(), copy_connections.cbegin(), copy_connections.cend());
|
||||
}
|
||||
|
||||
void removeNodes(){
|
||||
|
||||
for(auto &n : nm.nodes){
|
||||
for(auto &n : gm.nodes){
|
||||
n.second.highlighted = false;
|
||||
}
|
||||
|
||||
auto erase_nodes = nm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n){return n.erase;});
|
||||
auto erase_nodes = gm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n){return n.erase;});
|
||||
|
||||
std::vector<int> erase_nodes_ids;
|
||||
for(auto &e : erase_nodes){
|
||||
erase_nodes_ids.push_back(e.id);
|
||||
}
|
||||
|
||||
auto erase_connections = cm.connections | std::ranges::views::filter([erase_nodes_ids](Connection c){ return std::ranges::contains(erase_nodes_ids, c.v1) || std::ranges::contains(erase_nodes_ids, c.v2);});
|
||||
auto erase_connections = gm.connections | std::ranges::views::filter([erase_nodes_ids](Connection c){ return std::ranges::contains(erase_nodes_ids, c.v1) || std::ranges::contains(erase_nodes_ids, c.v2);});
|
||||
|
||||
std::vector<int> adjacent_nodes_ids;
|
||||
|
||||
for(auto &c : erase_connections){
|
||||
if(!nm.nodes.at(c.v1).selected) adjacent_nodes_ids.push_back(c.v1);
|
||||
if(!nm.nodes.at(c.v2).selected) adjacent_nodes_ids.push_back(c.v2);
|
||||
if(!gm.nodes.at(c.v1).selected) adjacent_nodes_ids.push_back(c.v1);
|
||||
if(!gm.nodes.at(c.v2).selected) adjacent_nodes_ids.push_back(c.v2);
|
||||
}
|
||||
|
||||
auto reroute_signals = sm.signals | std::ranges::views::filter([erase_nodes_ids](Signal s){
|
||||
@@ -95,8 +93,8 @@ class AppState{
|
||||
float dist = 10000000;
|
||||
int next_id = -1;
|
||||
for(int i : adjacent_nodes_ids){
|
||||
if(nm.nodes.at(i).position.dist(&s.position) < dist) {
|
||||
dist = nm.nodes.at(i).position.dist(&s.position);
|
||||
if(gm.nodes.at(i).position.dist(&s.position) < dist) {
|
||||
dist = gm.nodes.at(i).position.dist(&s.position);
|
||||
next_id = i;
|
||||
}
|
||||
}
|
||||
@@ -113,19 +111,19 @@ class AppState{
|
||||
}
|
||||
|
||||
for(auto &n : erase_nodes){
|
||||
std::erase_if(cm.connections, [n](Connection c){ return c.v1 == n.id || c.v2 == n.id;});
|
||||
std::erase_if(gm.connections, [n](Connection c){ return c.v1 == n.id || c.v2 == n.id;});
|
||||
}
|
||||
std::erase_if(nm.nodes, [](std::pair<int, Node> n){ return n.second.erase;});
|
||||
nm.keys.clear();
|
||||
std::ranges::copy(nm.nodes | std::ranges::views::keys, std::back_inserter(nm.keys));
|
||||
std::erase_if(gm.nodes, [](std::pair<int, Node> n){ return n.second.erase;});
|
||||
gm.keys.clear();
|
||||
std::ranges::copy(gm.nodes | std::ranges::views::keys, std::back_inserter(gm.keys));
|
||||
}
|
||||
|
||||
void draw(Vec2D<float> *mouse_pos, Camera2D *camera){
|
||||
mutex.lock();
|
||||
updateMidiPorts();
|
||||
mutex.unlock();
|
||||
nm.drawNodes(mouse_pos, camera);
|
||||
cm.drawConnections(mouse_pos, camera);
|
||||
gm.drawNodes(mouse_pos, camera);
|
||||
gm.drawConnections(mouse_pos, camera);
|
||||
sm.drawSignals(mouse_pos, camera);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user