diff --git a/src/connection.h b/src/connection.h new file mode 100644 index 0000000..4163783 --- /dev/null +++ b/src/connection.h @@ -0,0 +1,17 @@ +#pragma once + +#include "node.h" + +class Connection{ + + public: + Connection() {} + Connection(Node* from, Node* to) : from(from), to(to) {} + + Node* from; + Node* to; + + void draw(){ + + } +}; diff --git a/src/main.cpp b/src/main.cpp index ec56a11..3689048 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,14 +98,14 @@ int main(){ nodes.emplace(nodes.end(), Node((float)(rand() % 2160 + 200), (float)(rand() % 1040 + 200), 15.0f)); } - for(int i = 0; i < 1; i++){ + for(int i = 0; i < 2; i++){ signals.emplace(signals.end(), Signal(0, 0, 5.0f, 2.0f)); signals[i].next = &nodes[0]; } midi_out.open_port(midi_out_ports[2]); - Vec2D drag_origin; + Vec2D drag_offset; Node* connecting_from; @@ -128,14 +128,12 @@ int main(){ BeginMode2D(camera); - bool hovering = false; - - for( auto& n : nodes){ + for(auto& n : nodes){ Vec2D connector_position = n.position - ((n.position - mouse_pos)).norm() * (n.radius + 10.0f); float dist_connector = (connector_position - mouse_pos).length(); float dist = (n.position - mouse_pos).length(); - + // connect nodes if( (dist <= n.radius + 25.0f && dist > n.radius) || n.connecting){ n.hover_connect = true; @@ -156,11 +154,13 @@ int main(){ n.connecting = false; } - if(mouse_released && n.hover_connect) { - n.connections.push_back(connecting_from); - connecting_from->connections.push_back(&n); + if(mouse_released && (n.hover_connect || n.hover_move)) { + if(&n != connecting_from){ + n.connections.push_back(connecting_from); + connecting_from->connections.push_back(&n); + } } - + // move node if((n.position - mouse_pos).length() <= n.radius || n.picked_up){ n.hover_move = true; @@ -170,12 +170,11 @@ int main(){ if(mouse_clicked && n.hover_move){ n.picked_up = true; - drag_origin = mouse_pos; + drag_offset = n.position - mouse_pos; } if(mouse_down && n.picked_up){ - n.position = mouse_pos - (n.position - drag_origin); + n.position = mouse_pos + drag_offset; } - if(mouse_down && n.hover_move) hovering = true; if(mouse_released) { n.picked_up = false; @@ -195,15 +194,12 @@ int main(){ s.direction = s.next->position - s.position; if(s.position.dist(&s.next->position) < s.speed * 1.5) { if(s.next->connections.size() > 0) { - s.next = s.next->connections[0]; + s.next = s.next->get_next(); + midi_out.send_message(libremidi::channel_events::control_change(2, 10, 50)); } - //midi_out.send_message(libremidi::channel_events::control_change(2, 10, 50)); } s.draw(&mouse_pos); } - - if(!hovering && mouse_clicked) { - } EndMode2D(); GuiWindowBox((Rectangle){16,16,232,400}, "config"); diff --git a/src/node.h b/src/node.h index 3850f21..6722b47 100644 --- a/src/node.h +++ b/src/node.h @@ -17,14 +17,25 @@ class Node : public Movable{ float radius; - int id; bool picked_up = false; bool hover_move = false; bool hover_connect = false; bool connecting = false; + int next = 0; + + int midi_out = 0; + + int midi_note = 0; + int midi_cc = 0; + std::vector connections; + Node* get_next(){ + next = (next+1) % connections.size(); + return connections[next]; + } + void draw(Vec2D *mouse) { if(!hover_move) DrawCircle(position.x, position.y, radius, (Color){180, 210, 115, 255}); if(hover_move) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255});