very, very simple WP with midi CC out

This commit is contained in:
Sebastian
2024-10-09 02:01:23 +02:00
commit 3d6fc151f1
126 changed files with 19539 additions and 0 deletions
+289
View File
@@ -0,0 +1,289 @@
/*
*
* VISEQ - Visual Sequencer
*
*
*/
#include "SFML/Graphics/Text.hpp"
#include "libremidi/libremidi.hpp"
#include "libremidi/message.hpp"
#include "libremidi/observer_configuration.hpp"
#include <SFML/Main.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#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]);
sf::Clock deltaClock;
while(window.isOpen()){
sf::Event event;
while(window.pollEvent(event) ){
if(event.type == sf::Event::Closed){
window.close();
}
}
window.clear();
for( auto& n : nodes){
if(mouse_clicked && n.hover_move){
n.clicked = true;
}
if(mouse_pressed && n.clicked){
n.position = mouse_pos;
}
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);
}
//window.draw();
window.display();
}
}
/***/
/*SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv){*/
/**/
/* if (not SDL_Init(SDL_INIT_VIDEO)) {*/
/* SDL_Log("Unable to initialize SDL: %s", SDL_GetError());*/
/* return SDL_APP_FAILURE;*/
/* }*/
/**/
/* SDL_Window* window = SDL_CreateWindow("Window", 1920, 1080, SDL_WINDOW_OPENGL|SDL_WINDOW_FULLSCREEN);*/
/* if (not window){*/
/* SDL_Log("Unable to create window: %s", SDL_GetError());*/
/* return SDL_APP_FAILURE;*/
/* }*/
/**/
/* gl = SDL_GL_CreateContext(window);*/
/**/
/* SDL_ShowWindow(window);*/
/**/
/* int window_width;*/
/* int window_height;*/
/* SDL_GetWindowSize(window, &window_width, &window_height);*/
/**/
/**/
/*// cairo_device_t* device = cairo_glx_device_create();*/
/**/
/* sdl_cairo_surface = SDL_CreateSurface(renderer_width, renderer_height, SDL_PIXELFORMAT_RGBA32);*/
/**/
/* int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, sdl_cairo_surface->w);*/
/* cr_surface = cairo_image_surface_create_for_data((unsigned char*) sdl_cairo_surface->pixels, CAIRO_FORMAT_RGB24, sdl_cairo_surface->w, sdl_cairo_surface->h, stride);*/
/**/
/* cr = cairo_create(cr_surface);*/
/* SDL_Log("%d", cairo_surface_status(cr_surface));*/
/**/
/* int cairo_x_multiplier = renderer_width / window_width;*/
/* int cairo_y_multiplier = renderer_height / window_height;*/
/**/
/* cairo_surface_set_device_scale(cr_surface, cairo_x_multiplier, cairo_y_multiplier);*/
/**/
/* 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(i*10.0f, i*10.0f, 15.0f));*/
/* }*/
/**/
/* for(int i = 0; i < 10; i++){*/
/* signals.emplace(signals.end(), Signal(i*10.0f, i*10.0f, 5.0f));*/
/* }*/
/**/
/* IMGUI_CHECKVERSION();*/
/* ImGui::CreateContext();*/
/* io = ImGui::GetIO(); (void)io;*/
/**/
/* ImGui::StyleColorsDark();*/
/* //ImGui::StyleColorsLight();*/
/**/
/* // Setup Platform/Renderer backends*/
/* ImGui_ImplSDL3_InitForSDLRenderer(window, renderer);*/
/* ImGui_ImplSDLRenderer3_Init(renderer);*/
/**/
/* *appstate = new AppContext{*/
/* window,*/
/* renderer,*/
/* (float)window_width,*/
/* (float)window_height*/
/* };*/
/**/
/* return SDL_APP_CONTINUE;*/
/*}*/
/**/
/*SDL_AppResult SDL_AppIterate(void *appstate){*/
/* auto* app = (AppContext*)appstate;*/
/**/
/* SDL_SetRenderDrawColor(app->renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);*/
/* SDL_RenderClear(app->renderer); */
/**/
/* // ---------- cairo*/
/**/
/**/
/* cairo_set_source_rgba(cr, 0, 0, 0, 1.0);*/
/* cairo_rectangle(cr, 0, 0, app->width, app->height);*/
/* cairo_fill(cr);*/
/**/
/* for( auto& n : nodes){*/
/**/
/* if(mouse_clicked && n.hover_move){*/
/* n.clicked = true;*/
/* }*/
/* if(mouse_pressed && n.clicked){*/
/* n.position = mouse_pos;*/
/* }*/
/* if(!mouse_pressed) n.clicked = false;*/
/* n.update();*/
/* n.draw(cr, mouse_pos);*/
/* }*/
/**/
/* for( auto& n : signals){*/
/* n.update();*/
/* n.draw(cr);*/
/* }*/
/**/
/* SDL_Texture *texture = SDL_CreateTextureFromSurface(app->renderer, sdl_cairo_surface);*/
/**/
/* // ---------- ImGUI*/
/**/
/*ImGui_ImplSDLRenderer3_NewFrame();*/
/*ImGui_ImplSDL3_NewFrame();*/
/*ImGui::NewFrame();*/
/**/
/*ImGui::Begin("MIDI Config");*/
/*ImGui::SameLine();*/
/**/
/*for(auto port : midi_out_ports){*/
/* if(ImGui::Button(port.port_name.c_str())){*/
/* midi_out.open_port(port);*/
/* midi_out.send_message(144, 100, 40);*/
/* };*/
/*}*/
/**/
/*ImGui::Text("%f %f", mouse_pos.x, mouse_pos.y);*/
/**/
/*ImGui::End();*/
/*ImGui::Render();*/
/**/
/**/
/* // ---------- Render*/
/**/
/* SDL_RenderTexture(app->renderer, texture, NULL, NULL);*/
/*// ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), app->renderer); */
/**/
/* SDL_RenderPresent(app->renderer);*/
/**/
/*// auto time = SDL_GetTicks();*/
/* SDL_Delay(5);*/
/* return SDL_APP_CONTINUE;*/
/*}*/
/**/
/*SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event){*/
/* //auto* app = (AppContext*)appstate;*/
/* mouse_clicked = false;*/
/**/
/* const SDL_Event *ev = event;*/
/* ImGui_ImplSDL3_ProcessEvent(ev);*/
/**/
/* if (event->type == SDL_EVENT_QUIT) {*/
/* return SDL_APP_SUCCESS;*/
/* }*/
/**/
/* if(event->type == SDL_EVENT_MOUSE_MOTION){*/
/* mouse_pos = {event->motion.x, event->motion.y};*/
/* }*/
/**/
/* if(event->type == SDL_EVENT_MOUSE_BUTTON_DOWN){*/
/* if(event->button.button == SDL_BUTTON_LEFT) {*/
/* if(!mouse_pressed) {*/
/* drag_start = mouse_pos;*/
/* mouse_clicked = true;*/
/* }*/
/* mouse_pressed = true;*/
/* }*/
/* }*/
/**/
/* if(event->type == SDL_EVENT_MOUSE_BUTTON_UP){*/
/* if(event->button.button == SDL_BUTTON_LEFT) mouse_pressed = false;*/
/* }*/
/**/
/* return SDL_APP_CONTINUE;*/
/*}*/
/**/