2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* VISEQ - Visual Sequencer
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
/*Background: (46, 46, 46); #2e2e2e*/
|
|
|
|
|
/*Comments: (121, 121, 121); #797979*/
|
|
|
|
|
/*White: (214, 214, 214); #d6d6d6*/
|
|
|
|
|
/*Yellow: (229, 181, 103); #e5b567*/
|
|
|
|
|
/*Green: (180, 210, 115); #b4d273*/
|
|
|
|
|
/*Orange: (232, 125, 62); #e87d3e*/
|
|
|
|
|
/*Purple: (158, 134, 200); #9e86c8*/
|
|
|
|
|
/*Pink: (176, 82, 121); #b05279*/
|
|
|
|
|
/*Blue: (108, 153, 187); #6c99bb*/
|
|
|
|
|
|
|
|
|
|
#include <raylib.h>
|
|
|
|
|
#include <raymath.h>
|
|
|
|
|
|
|
|
|
|
#define RAYGUI_IMPLEMENTATION
|
|
|
|
|
#include "raygui/raygui.h"
|
|
|
|
|
#include "raygui/dark/style_dark.h"
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
#include "libremidi/libremidi.hpp"
|
|
|
|
|
#include "libremidi/message.hpp"
|
|
|
|
|
#include "libremidi/observer_configuration.hpp"
|
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <cmath>
|
2024-10-13 04:22:09 +02:00
|
|
|
#include <map>
|
2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
#include "node.h"
|
|
|
|
|
#include "signal.h"
|
2024-10-15 02:59:26 +02:00
|
|
|
#include "connection.h"
|
|
|
|
|
|
|
|
|
|
#include "connection-manager.h"
|
2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
libremidi::observer obs;
|
|
|
|
|
libremidi::midi_out midi_out;
|
|
|
|
|
|
|
|
|
|
std::vector<libremidi::input_port> midi_in_ports;
|
|
|
|
|
std::vector<libremidi::output_port> midi_out_ports;
|
|
|
|
|
|
|
|
|
|
std::vector<Node> nodes;
|
|
|
|
|
std::vector<Signal> signals;
|
2024-10-15 02:59:26 +02:00
|
|
|
//std::vector<Connection> connections;
|
|
|
|
|
ConnectionManager cm;
|
2024-10-13 04:22:09 +02:00
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
Vec2D<float> mouse_pos;
|
|
|
|
|
Vec2D<float> drag_start;
|
|
|
|
|
|
|
|
|
|
bool mouse_clicked = false;
|
|
|
|
|
bool mouse_touched = false;
|
2024-10-13 04:22:09 +02:00
|
|
|
bool mouse_dragging = false;
|
2024-10-09 02:01:23 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
enum States {IDLE, CONFIG};
|
|
|
|
|
|
|
|
|
|
struct AppState{
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
States state;
|
|
|
|
|
} app;
|
2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
InitWindow(2560, 1440, "VISEQ");
|
|
|
|
|
|
|
|
|
|
GuiLoadStyleDark();
|
|
|
|
|
|
|
|
|
|
int monitor = 0; //GetCurrentMonitor();
|
|
|
|
|
|
|
|
|
|
SetWindowMonitor(monitor);
|
|
|
|
|
|
|
|
|
|
app.width = GetMonitorWidth(monitor);
|
|
|
|
|
app.height = GetMonitorHeight(monitor);
|
|
|
|
|
|
|
|
|
|
Camera2D camera = { 0 };
|
|
|
|
|
camera.target = (Vector2){ app.width/2.0f, app.height/2.0f };
|
|
|
|
|
camera.offset = (Vector2){ app.width/2.0f, app.height/2.0f };
|
|
|
|
|
camera.rotation = 0.0f;
|
|
|
|
|
camera.zoom = 1.0f;
|
|
|
|
|
|
|
|
|
|
SetTargetFPS(120);
|
|
|
|
|
|
|
|
|
|
ToggleFullscreen();
|
2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
for(const libremidi::input_port& port : obs.get_input_ports()){
|
|
|
|
|
midi_in_ports.push_back(port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(const libremidi::output_port& port : obs.get_output_ports()){
|
|
|
|
|
midi_out_ports.push_back(port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 10; i++){
|
2024-10-13 04:22:09 +02:00
|
|
|
nodes.emplace(nodes.end(), Node((float)(rand() % 2160 + 200), (float)(rand() % 1040 + 200), 15.0f));
|
2024-10-09 02:01:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-13 15:07:19 +02:00
|
|
|
for(int i = 0; i < 2; i++){
|
2024-10-15 02:59:26 +02:00
|
|
|
signals.emplace(signals.end(), Signal(1280, 720, 5.0f, 2.0f));
|
2024-10-13 04:22:09 +02:00
|
|
|
signals[i].next = &nodes[0];
|
2024-10-09 02:01:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
midi_out.open_port(midi_out_ports[2]);
|
|
|
|
|
|
2024-10-13 15:07:19 +02:00
|
|
|
Vec2D<float> drag_offset;
|
2024-10-09 02:01:23 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
Node* connecting_from;
|
2024-10-15 02:59:26 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
while(!WindowShouldClose()){
|
2024-10-09 02:01:23 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
Vector2 mp = GetScreenToWorld2D(GetMousePosition(), camera);
|
2024-10-10 02:59:27 +02:00
|
|
|
Vec2D<float> mouse_pos = {(float)mp.x, (float)mp.y};
|
2024-10-09 02:01:23 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
bool mouse_down = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
|
|
|
|
|
bool mouse_clicked = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
|
|
|
|
bool mouse_released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
2024-10-10 02:59:27 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
if(mouse_clicked){
|
2024-10-10 02:59:27 +02:00
|
|
|
drag_start = mouse_pos;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
BeginDrawing();
|
2024-10-09 02:01:23 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
ClearBackground((Color){46,46,46});
|
|
|
|
|
|
|
|
|
|
BeginMode2D(camera);
|
|
|
|
|
|
2024-10-13 15:07:19 +02:00
|
|
|
for(auto& n : nodes){
|
2024-10-13 04:22:09 +02:00
|
|
|
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();
|
2024-10-13 15:07:19 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
// connect nodes
|
|
|
|
|
if( (dist <= n.radius + 25.0f && dist > n.radius) || n.connecting){
|
|
|
|
|
n.hover_connect = true;
|
|
|
|
|
} else {
|
|
|
|
|
n.hover_connect = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(dist_connector <= 6.0f && mouse_clicked) {
|
|
|
|
|
connecting_from = &n;
|
|
|
|
|
n.connecting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(n.connecting && mouse_down){
|
|
|
|
|
DrawLine(connector_position.x, connector_position.y, mouse_pos.x, mouse_pos.y, (Color){229, 181, 103, 255});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(mouse_released && n.connecting) {
|
|
|
|
|
n.connecting = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-13 15:07:19 +02:00
|
|
|
if(mouse_released && (n.hover_connect || n.hover_move)) {
|
2024-10-15 02:59:26 +02:00
|
|
|
if(&n != connecting_from && connecting_from != nullptr){
|
|
|
|
|
cm.connections.emplace(cm.connections.end(), connecting_from, &n);
|
|
|
|
|
connecting_from = nullptr;
|
2024-10-13 15:07:19 +02:00
|
|
|
}
|
2024-10-13 04:22:09 +02:00
|
|
|
}
|
2024-10-13 15:07:19 +02:00
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
// move node
|
|
|
|
|
if((n.position - mouse_pos).length() <= n.radius || n.picked_up){
|
|
|
|
|
n.hover_move = true;
|
|
|
|
|
} else {
|
|
|
|
|
n.hover_move = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(mouse_clicked && n.hover_move){
|
|
|
|
|
n.picked_up = true;
|
2024-10-13 15:07:19 +02:00
|
|
|
drag_offset = n.position - mouse_pos;
|
2024-10-13 04:22:09 +02:00
|
|
|
}
|
|
|
|
|
if(mouse_down && n.picked_up){
|
2024-10-13 15:07:19 +02:00
|
|
|
n.position = mouse_pos + drag_offset;
|
2024-10-13 04:22:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(mouse_released) {
|
|
|
|
|
n.picked_up = false;
|
|
|
|
|
}
|
|
|
|
|
n.draw(&mouse_pos);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-15 02:59:26 +02:00
|
|
|
cm.draw();
|
2024-10-13 04:22:09 +02:00
|
|
|
|
2024-10-15 02:59:26 +02:00
|
|
|
for(auto& s : signals){
|
2024-10-13 04:22:09 +02:00
|
|
|
s.direction = s.next->position - s.position;
|
|
|
|
|
if(s.position.dist(&s.next->position) < s.speed * 1.5) {
|
2024-10-15 02:59:26 +02:00
|
|
|
Node* n = cm.next(s.next);
|
|
|
|
|
if(n != s.next && n != nullptr) {
|
|
|
|
|
s.next = n;
|
2024-10-13 15:07:19 +02:00
|
|
|
midi_out.send_message(libremidi::channel_events::control_change(2, 10, 50));
|
2024-10-13 04:22:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
s.draw(&mouse_pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndMode2D();
|
|
|
|
|
GuiWindowBox((Rectangle){16,16,232,400}, "config");
|
|
|
|
|
|
|
|
|
|
GuiButton((Rectangle){32, 64, 96, 20}, "button");
|
|
|
|
|
|
|
|
|
|
EndDrawing();
|
2024-10-09 02:01:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
CloseWindow();
|
|
|
|
|
|
|
|
|
|
return 0;
|
2024-10-09 02:01:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
|