connecting and moving works. midi out also
This commit is contained in:
@@ -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(){
|
||||
|
||||
}
|
||||
};
|
||||
+12
-16
@@ -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<float> drag_origin;
|
||||
Vec2D<float> drag_offset;
|
||||
|
||||
Node* connecting_from;
|
||||
|
||||
@@ -128,9 +128,7 @@ int main(){
|
||||
|
||||
BeginMode2D(camera);
|
||||
|
||||
bool hovering = false;
|
||||
|
||||
for( auto& n : nodes){
|
||||
for(auto& n : nodes){
|
||||
Vec2D<float> connector_position = n.position - ((n.position - mouse_pos)).norm() * (n.radius + 10.0f);
|
||||
float dist_connector = (connector_position - mouse_pos).length();
|
||||
|
||||
@@ -156,9 +154,11 @@ 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
|
||||
@@ -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,16 +194,13 @@ 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");
|
||||
|
||||
|
||||
+12
-1
@@ -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<Node*> connections;
|
||||
|
||||
Node* get_next(){
|
||||
next = (next+1) % connections.size();
|
||||
return connections[next];
|
||||
}
|
||||
|
||||
void draw(Vec2D<float> *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});
|
||||
|
||||
Reference in New Issue
Block a user