2024-10-09 02:01:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-10-20 01:17:18 +02:00
|
|
|
#include <map>
|
2024-10-13 04:22:09 +02:00
|
|
|
#include <raylib.h>
|
2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
#include "datatypes.h"
|
|
|
|
|
#include "moveable.h"
|
2024-10-20 23:42:38 +02:00
|
|
|
#include "raymath.h"
|
2024-10-09 02:01:23 +02:00
|
|
|
|
2024-10-18 01:27:14 +02:00
|
|
|
#define R 14.0f
|
2024-10-13 04:22:09 +02:00
|
|
|
|
2024-10-20 01:17:18 +02:00
|
|
|
struct NodeMidiOut{
|
|
|
|
|
int i;
|
|
|
|
|
std::string name;
|
|
|
|
|
bool enabled;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
class Node : public Movable{
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Node() {}
|
2024-10-26 02:14:41 +02:00
|
|
|
Node(int id, float x, float y, float r) : Movable(Vec2D<float>(x, y), 0.0f), radius(r), id(id) {}
|
|
|
|
|
Node(int id, Vec2D<float> p, float r) : Movable(p, 0.0f), radius(r), id(id) {}
|
2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
float radius;
|
|
|
|
|
|
2024-10-26 02:14:41 +02:00
|
|
|
int id;
|
|
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
bool picked_up = false;
|
2024-10-23 03:25:57 +02:00
|
|
|
bool dragging = false;
|
|
|
|
|
bool in_rect = false;
|
2024-10-09 02:01:23 +02:00
|
|
|
bool hover_connect = false;
|
2024-10-23 03:25:57 +02:00
|
|
|
bool hovering = false;
|
2024-10-13 04:22:09 +02:00
|
|
|
bool connecting = false;
|
2024-10-16 02:26:02 +02:00
|
|
|
bool config = false;
|
2024-10-23 00:23:24 +02:00
|
|
|
bool selected = false;
|
2024-10-25 17:13:30 +02:00
|
|
|
bool erase = false;
|
2024-10-26 02:14:41 +02:00
|
|
|
bool highlighted = false;
|
2024-10-26 16:31:23 +02:00
|
|
|
bool copied = false;
|
2024-10-27 00:40:57 +02:00
|
|
|
bool triggered = false;
|
2024-10-13 15:07:19 +02:00
|
|
|
|
2024-10-19 17:41:31 +02:00
|
|
|
int midi_out = -1;
|
|
|
|
|
|
2024-10-23 00:23:24 +02:00
|
|
|
Vec2D<float> drag_offset;
|
|
|
|
|
|
2024-10-20 01:17:18 +02:00
|
|
|
std::map<int, NodeMidiOut> midi_outs;
|
|
|
|
|
|
|
|
|
|
bool gui_midi_channel_edit = false;
|
|
|
|
|
bool gui_midi_note_edit = false;
|
|
|
|
|
bool gui_midi_velocity_edit = false;
|
|
|
|
|
bool gui_midi_gate_edit = false;
|
2024-10-13 15:07:19 +02:00
|
|
|
|
2024-10-27 00:40:57 +02:00
|
|
|
int midi_channel = 1;
|
|
|
|
|
int midi_note = 48;
|
|
|
|
|
int midi_velocity = 60;
|
|
|
|
|
int midi_gate = 100;
|
2024-10-13 15:07:19 +02:00
|
|
|
|
2024-10-20 01:17:18 +02:00
|
|
|
int midi_cc = 0;
|
2024-10-27 00:40:57 +02:00
|
|
|
float start = 0;
|
|
|
|
|
float fade = 0;
|
|
|
|
|
float time = 0;
|
|
|
|
|
float last = 0;
|
|
|
|
|
|
2024-10-20 01:17:18 +02:00
|
|
|
Distribution mode = Distribution::ROUNDROBIN;
|
2024-10-19 04:08:46 +02:00
|
|
|
|
2024-10-25 16:41:37 +02:00
|
|
|
void setMidiPort(int midi_port, bool state){
|
|
|
|
|
midi_outs[midi_port].enabled = state;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-27 00:40:57 +02:00
|
|
|
void trigger(){
|
|
|
|
|
triggered = true;
|
|
|
|
|
start = GetTime();
|
|
|
|
|
fade = midi_gate;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-20 23:42:38 +02:00
|
|
|
void draw(Vec2D<float> *mouse, Camera2D *cam) {
|
2024-10-27 00:40:57 +02:00
|
|
|
last = time;
|
|
|
|
|
time = GetTime();
|
|
|
|
|
if(time - start >= (float)midi_gate / 1000.0f){
|
|
|
|
|
triggered = false;
|
|
|
|
|
fade = 0;
|
|
|
|
|
} else {
|
|
|
|
|
fade -= (time - last)*1000.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawRing(position, radius, radius+4, 0, 360, 24, (Color){60, 60, 60, 255});
|
|
|
|
|
DrawRing(position, radius, radius+4, 0.0f - 90.0f, (360.0f/127.0f) * midi_velocity - 90.0f, 24, (Color){158, 134, 200, 255});
|
|
|
|
|
DrawCircleLinesV(position, radius + 4, (Color){100, 100, 100, 255});
|
|
|
|
|
|
|
|
|
|
float midi_gate_map = round((255.f / midi_gate) * fade);
|
|
|
|
|
Color gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){180, 210, 115, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE);
|
|
|
|
|
|
|
|
|
|
if(!dragging && !selected && !in_rect && !hovering) DrawCircle(position.x, position.y, radius, gate_color);
|
2024-10-26 02:14:41 +02:00
|
|
|
if(selected || dragging || in_rect || hovering) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255});
|
2024-10-27 00:40:57 +02:00
|
|
|
|
|
|
|
|
if(selected) DrawCircleLinesV(position, radius+8, (Color){158, 255, 210, 255});
|
2024-10-27 00:48:13 +02:00
|
|
|
|
|
|
|
|
if(IsKeyDown(KEY_LEFT_ALT)){
|
|
|
|
|
int offset_gate = MeasureText(std::format("{:.2f}", (float)midi_gate/1000.0f).c_str(), 12);
|
|
|
|
|
DrawText(std::format("{:.2f}",(float)midi_gate/1000.0f).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE );
|
|
|
|
|
} else {
|
|
|
|
|
int offset = MeasureText(MIDI::Notes[midi_note].c_str(), 12);
|
|
|
|
|
DrawText(MIDI::Notes[midi_note].c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
|
|
|
|
|
}
|
2024-10-18 01:27:14 +02:00
|
|
|
if(mode == Distribution::RANDOM) DrawCircle(position.x, position.y, radius/2.0f, (Color){229, 181, 103, 255});
|
|
|
|
|
|
2024-10-13 04:22:09 +02:00
|
|
|
Vec2D<float> connector = position - ((position - *mouse)).norm() * (radius + R);
|
2024-10-20 23:42:38 +02:00
|
|
|
float opacity = 150.0f - Clamp(position.dist(mouse), 0.0f, 150.0f);
|
2024-10-13 04:22:09 +02:00
|
|
|
|
|
|
|
|
if(hover_connect){
|
2024-10-18 01:27:14 +02:00
|
|
|
DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255});
|
2024-10-13 04:22:09 +02:00
|
|
|
} else {
|
2024-10-20 23:42:38 +02:00
|
|
|
DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity});
|
2024-10-13 04:22:09 +02:00
|
|
|
}
|
2024-10-26 02:14:41 +02:00
|
|
|
if(highlighted) DrawCircleLinesV(position, radius+2, (Color){255, 0, 0, 200});
|
2024-10-09 02:01:23 +02:00
|
|
|
}
|
|
|
|
|
};
|