connecting and moving works. midi out also

This commit is contained in:
Sebastian
2024-10-13 15:07:19 +02:00
parent 1e7eacb893
commit 313bf767c6
3 changed files with 43 additions and 19 deletions
+14 -18
View File
@@ -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,14 +128,12 @@ 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();
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");