Files
viseq/src/node.h
T

121 lines
3.3 KiB
C++
Raw Normal View History

2024-10-09 02:01:23 +02:00
#pragma once
2024-10-20 01:17:18 +02:00
#include <map>
#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-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() {}
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
2024-10-29 00:50:39 +01:00
Node *neighbor = nullptr;
2024-10-09 02:01:23 +02:00
float radius;
int id;
bool picked_up = false;
bool dragging = false;
bool in_rect = false;
2024-10-09 02:01:23 +02:00
bool hover_connect = false;
bool hovering = false;
bool connecting = false;
2024-10-16 02:26:02 +02:00
bool config = false;
bool selected = false;
bool erase = false;
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
int midi_out = -1;
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-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});
2024-10-29 00:50:39 +01:00
if(mode == Distribution::RANDOM) DrawCircle(position.x, position.y, radius/2.0f, VS_COLOR_PINK);
2024-10-27 00:40:57 +02:00
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);
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
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);
if(hover_connect){
2024-10-18 01:27:14 +02:00
DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255});
} else {
2024-10-20 23:42:38 +02:00
DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity});
}
if(highlighted) DrawCircleLinesV(position, radius+2, (Color){255, 0, 0, 200});
2024-10-09 02:01:23 +02:00
}
};