2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* VISEQ - Visual Sequencer
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "SFML/Graphics/Text.hpp"
|
|
|
|
|
#include "libremidi/libremidi.hpp"
|
|
|
|
|
#include "libremidi/message.hpp"
|
|
|
|
|
#include "libremidi/observer_configuration.hpp"
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
#include <SFML/Graphics/RectangleShape.hpp>
|
2024-10-09 02:01:23 +02:00
|
|
|
#include <SFML/Main.hpp>
|
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
#include <SFML/Graphics/RenderWindow.hpp>
|
2024-10-10 02:59:27 +02:00
|
|
|
#include <SFML/System/Vector2.hpp>
|
2024-10-09 02:01:23 +02:00
|
|
|
#include <SFML/Window.hpp>
|
|
|
|
|
#include <SFML/OpenGL.hpp>
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
#include <SFML/Window/Mouse.hpp>
|
2024-10-09 02:01:23 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
#include "node.h"
|
|
|
|
|
#include "signal.h"
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
Vec2D<float> mouse_pos;
|
|
|
|
|
Vec2D<float> drag_start;
|
|
|
|
|
|
|
|
|
|
bool mouse_pressed = false;
|
|
|
|
|
bool mouse_clicked = false;
|
|
|
|
|
bool mouse_touched = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
|
|
|
|
sf::RenderWindow window(sf::VideoMode({2560,1440}), "VISEQ");
|
|
|
|
|
window.setFramerateLimit(120);
|
|
|
|
|
|
|
|
|
|
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++){
|
|
|
|
|
nodes.emplace(nodes.end(), Node((float)(rand() % 2000 + 280), (float)(rand() % 1000 + 220), 15.0f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 10; i++){
|
|
|
|
|
signals.emplace(signals.end(), Signal(2560.f/2.f, 1440.f/2.f, 5.0f));
|
|
|
|
|
signals[i].target_node_id = rand() % 9;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
midi_out.open_port(midi_out_ports[2]);
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
Vec2D<float> drag_origin;
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
sf::Clock deltaClock;
|
|
|
|
|
|
|
|
|
|
while(window.isOpen()){
|
|
|
|
|
sf::Event event;
|
|
|
|
|
while(window.pollEvent(event) ){
|
|
|
|
|
|
|
|
|
|
if(event.type == sf::Event::Closed){
|
|
|
|
|
window.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
sf::Vector2i mp = sf::Mouse::getPosition(window);
|
|
|
|
|
Vec2D<float> mouse_pos = {(float)mp.x, (float)mp.y};
|
2024-10-09 02:01:23 +02:00
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
bool mouse_toggled = false;
|
|
|
|
|
mouse_pressed = sf::Mouse::isButtonPressed(sf::Mouse::Button::Left);
|
|
|
|
|
|
|
|
|
|
if(!mouse_pressed && mouse_clicked) mouse_clicked = false;
|
|
|
|
|
if(mouse_pressed && !mouse_clicked){
|
|
|
|
|
mouse_clicked = true;
|
|
|
|
|
mouse_toggled = true;
|
|
|
|
|
drag_start = mouse_pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.clear(sf::Color(46,46,46));
|
|
|
|
|
|
|
|
|
|
bool hovering = false;
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
for( auto& n : nodes){
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
if((n.position - mouse_pos).length() <= n.radius && !hovering) {
|
|
|
|
|
n.hover_move = true;
|
|
|
|
|
hovering = true;
|
|
|
|
|
} else {
|
|
|
|
|
n.hover_move = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
if(mouse_clicked && n.hover_move){
|
|
|
|
|
n.clicked = true;
|
|
|
|
|
}
|
2024-10-10 02:59:27 +02:00
|
|
|
if(mouse_toggled) drag_origin = n.position;
|
2024-10-09 02:01:23 +02:00
|
|
|
if(mouse_pressed && n.clicked){
|
2024-10-10 02:59:27 +02:00
|
|
|
n.position = mouse_pos - (drag_start - drag_origin);
|
2024-10-09 02:01:23 +02:00
|
|
|
}
|
|
|
|
|
if(!mouse_pressed) n.clicked = false;
|
|
|
|
|
n.update();
|
|
|
|
|
n.draw(&window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for( auto& n : signals){
|
|
|
|
|
n.speed = 2.0f;
|
|
|
|
|
n.direction = nodes[n.target_node_id].position - n.position;
|
|
|
|
|
if(n.position.dist(&nodes[n.target_node_id].position) < n.speed * 1.5) {
|
|
|
|
|
n.target_node_id++;
|
|
|
|
|
midi_out.send_message(libremidi::channel_events::control_change(2, n.target_node_id, 50));
|
|
|
|
|
}
|
|
|
|
|
if(n.target_node_id == 10) n.target_node_id = 0;
|
|
|
|
|
n.update();
|
|
|
|
|
n.draw(&window);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
if(!hovering && mouse_clicked) {
|
|
|
|
|
Vec2D<float> ref = {1.f,0.f};
|
|
|
|
|
Vec2D<float> lineVec = mouse_pos - drag_start;
|
|
|
|
|
float width = lineVec.length();
|
|
|
|
|
float angle = ref.angleDeg(lineVec);
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape line;
|
|
|
|
|
line.setSize(sf::Vector2f(width, 2));
|
|
|
|
|
line.setPosition(drag_start.x, drag_start.y);
|
|
|
|
|
line.setRotation(angle);
|
|
|
|
|
line.setFillColor(sf::Color(100,0,0));
|
|
|
|
|
window.draw(line);
|
|
|
|
|
}
|
2024-10-09 02:01:23 +02:00
|
|
|
//window.draw();
|
|
|
|
|
window.display();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
|