2024-10-31 01:43:00 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-01 02:38:47 +01:00
|
|
|
#include "datatypes.h"
|
2024-11-14 01:37:16 +01:00
|
|
|
#include "graph-item.h"
|
2024-10-31 01:43:00 +01:00
|
|
|
#include "node.h"
|
|
|
|
|
#include "raymath.h"
|
|
|
|
|
#include <map>
|
|
|
|
|
|
2024-11-02 15:52:16 +01:00
|
|
|
#define RADIUS 14.0f
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
namespace VISEQ::GRAPH::NODES {
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
class MidiNode : public Node{
|
|
|
|
|
|
|
|
|
|
public:
|
2024-11-14 01:37:16 +01:00
|
|
|
using GraphItem::state;
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
struct NodeMidiOut{
|
|
|
|
|
int i;
|
|
|
|
|
std::string name;
|
|
|
|
|
bool enabled;
|
|
|
|
|
};
|
2024-11-02 15:52:16 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
MidiNode() {}
|
|
|
|
|
MidiNode(Vec2Df position) : Node(position) {}
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
NodeType nodeType = NodeType::MIDINODE;
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
bool send_note = true;
|
|
|
|
|
bool send_cc = false;
|
|
|
|
|
bool send_pc = false;
|
|
|
|
|
bool send_pitch_bend = false;
|
2024-11-01 02:38:47 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
int midi_out = -1;
|
|
|
|
|
|
|
|
|
|
std::map<int, NodeMidiOut> midi_outs;
|
2024-11-01 02:38:47 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
bool gui_midi_channel_edit = false;
|
|
|
|
|
bool gui_midi_note_edit = false;
|
|
|
|
|
bool gui_midi_velocity_edit = false;
|
|
|
|
|
bool gui_midi_gate_edit = false;
|
|
|
|
|
|
|
|
|
|
bool triggered = false;
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
int mode = 0;
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
int midi_note_channel = 1;
|
|
|
|
|
int midi_note = 48;
|
|
|
|
|
int midi_velocity = 60;
|
2024-11-07 00:01:54 +01:00
|
|
|
int midi_gate = 10; // gate time in milliseconds
|
2024-11-03 03:48:49 +01:00
|
|
|
|
|
|
|
|
int midi_cc_channel = 0;
|
|
|
|
|
int midi_cc = 0;
|
|
|
|
|
int midi_cc_value = 0;
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
int midi_pc_channel = 0;
|
|
|
|
|
int midi_pc = 0;
|
|
|
|
|
int midi_pc_value = 0;
|
|
|
|
|
|
|
|
|
|
int midi_pitch_bend_channel = 0;
|
|
|
|
|
int midi_pitch_bend = 8192;
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
float start = 0;
|
|
|
|
|
float fade = 0;
|
|
|
|
|
float time = 0;
|
|
|
|
|
float last = 0;
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
virtual NodeType getNodeType() const override {return nodeType;}
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-14 01:37:16 +01:00
|
|
|
void setMidiPort(int midi_port, bool _state){
|
|
|
|
|
midi_outs[midi_port].enabled = _state;
|
2024-10-31 01:43:00 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
void trigger() override {
|
|
|
|
|
triggered = true;
|
|
|
|
|
start = GetTime();
|
|
|
|
|
fade = midi_gate;
|
|
|
|
|
}
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
void SMode(int _mode) override{
|
|
|
|
|
mode = _mode;
|
|
|
|
|
}
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
int Ggate(){
|
|
|
|
|
return midi_gate;
|
2024-10-31 01:43:00 +01:00
|
|
|
}
|
2024-11-14 00:55:09 +01:00
|
|
|
void interact(){
|
2024-11-14 01:37:16 +01:00
|
|
|
float wheel = GetMouseWheelMove();
|
2024-11-14 00:55:09 +01:00
|
|
|
|
|
|
|
|
if(IsKeyDown(KEY_LEFT_CONTROL) && !IsKeyDown(KEY_LEFT_ALT)){
|
2024-11-14 01:37:16 +01:00
|
|
|
switch(GraphItem::state->node_mode){
|
2024-11-14 00:55:09 +01:00
|
|
|
case 0:{
|
2024-11-14 01:37:16 +01:00
|
|
|
midi_note += wheel;
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
case 1:{
|
2024-11-14 01:37:16 +01:00
|
|
|
midi_cc += wheel;
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
case 2:{
|
2024-11-14 01:37:16 +01:00
|
|
|
midi_pitch_bend += wheel;
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
};
|
2024-11-14 01:37:16 +01:00
|
|
|
if(midi_note < 0 ) midi_note = VISEQ::MIDI::Notes.size()-1;
|
|
|
|
|
if(midi_note >= VISEQ::MIDI::Notes.size() ) midi_note = 0;
|
2024-11-14 00:55:09 +01:00
|
|
|
|
2024-11-14 01:37:16 +01:00
|
|
|
if(midi_cc < 0 ) midi_cc = 127;
|
|
|
|
|
if(midi_cc > 127 ) midi_cc = 0;
|
2024-11-14 00:55:09 +01:00
|
|
|
|
2024-11-14 01:37:16 +01:00
|
|
|
if(midi_pitch_bend < 0 ) midi_pitch_bend = 0;
|
|
|
|
|
if(midi_pitch_bend > 16383 ) midi_pitch_bend = 16383;
|
2024-11-14 00:55:09 +01:00
|
|
|
|
|
|
|
|
} else if(IsKeyDown(KEY_LEFT_SHIFT) && !IsKeyDown(KEY_LEFT_ALT)) {
|
2024-11-14 01:37:16 +01:00
|
|
|
midi_velocity += wheel;
|
|
|
|
|
if(midi_velocity < 0 ) midi_velocity = 127;
|
|
|
|
|
if(midi_velocity > 127 ) midi_velocity = 0;
|
2024-11-14 00:55:09 +01:00
|
|
|
} else if(IsKeyDown(KEY_LEFT_ALT)) {
|
2024-11-14 01:37:16 +01:00
|
|
|
switch(GraphItem::state->node_mode){
|
2024-11-14 00:55:09 +01:00
|
|
|
case 0:{
|
|
|
|
|
float incr = (float)wheel * (IsKeyDown(KEY_LEFT_SHIFT) ? 100.0f : IsKeyDown(KEY_LEFT_CONTROL) ? 1000.0f : 10.0f);
|
2024-11-14 01:37:16 +01:00
|
|
|
midi_gate += incr;
|
|
|
|
|
if(midi_gate < 0 ) midi_gate = 0;
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
case 1:{
|
2024-11-14 01:37:16 +01:00
|
|
|
midi_cc_value += wheel;
|
|
|
|
|
if(midi_cc_value < 0 ) midi_cc_value = 0;
|
|
|
|
|
if(midi_cc_value > 127 ) midi_cc_value = 127;
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
case 2:{
|
|
|
|
|
float incr = (float)wheel * (IsKeyDown(KEY_LEFT_SHIFT) ? 100.0f : IsKeyDown(KEY_LEFT_CONTROL) ? 1000.0f : 10.0f);
|
2024-11-14 01:37:16 +01:00
|
|
|
midi_pitch_bend += incr;
|
|
|
|
|
if(midi_pitch_bend < 0 ) midi_pitch_bend = 0;
|
|
|
|
|
if(midi_pitch_bend > 16383 ) midi_pitch_bend = 16383;
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
void draw(Vec2Df mouse, Camera2D cam) override {
|
2024-11-12 01:42:05 +01:00
|
|
|
Node::draw();
|
2024-11-14 23:21:04 +01:00
|
|
|
if(hovering()) interact();
|
2024-11-14 01:37:16 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
last = time;
|
|
|
|
|
time = GetTime();
|
|
|
|
|
if(time - start >= (float)midi_gate / 1000.0f){
|
|
|
|
|
triggered = false;
|
|
|
|
|
fade = 0;
|
|
|
|
|
} else {
|
|
|
|
|
fade -= (time - last)*1000.0f;
|
2024-10-31 01:43:00 +01:00
|
|
|
}
|
2024-11-03 03:48:49 +01:00
|
|
|
|
|
|
|
|
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 = VS_COLOR_GREEN;
|
|
|
|
|
|
2024-10-31 01:43:00 +01:00
|
|
|
switch(mode){
|
|
|
|
|
case 0:{
|
2024-11-03 03:48:49 +01:00
|
|
|
gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){180, 210, 115, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE);
|
2024-10-31 01:43:00 +01:00
|
|
|
break;}
|
|
|
|
|
case 1:{
|
2024-11-03 03:48:49 +01:00
|
|
|
gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){229, 181, 103, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE);
|
2024-10-31 01:43:00 +01:00
|
|
|
break;}
|
|
|
|
|
case 2:{
|
2024-11-03 03:48:49 +01:00
|
|
|
gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){232, 125, 62, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE);
|
2024-10-31 01:43:00 +01:00
|
|
|
break;}
|
|
|
|
|
}
|
2024-11-16 00:29:01 +01:00
|
|
|
if(!picked_up && !selected && !in_selection_rect && !hovering()) DrawCircle(position.x, position.y, radius, gate_color);
|
|
|
|
|
if(selected || picked_up || in_selection_rect || hovering()) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255});
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
if(distributionMode == Distribution::RANDOM) DrawCircle(position.x, position.y, radius/2.0f, VS_COLOR_PINK);
|
|
|
|
|
if(distributionMode == Distribution::ROUNDROBIN) DrawCircle(position.x, position.y, radius/2.0f, VS_COLOR_YELLOW);
|
|
|
|
|
|
|
|
|
|
if(selected) DrawCircleLinesV(position, radius+8, (Color){158, 255, 210, 255});
|
|
|
|
|
|
|
|
|
|
if(IsKeyDown(KEY_LEFT_ALT)){
|
|
|
|
|
float value = 0;
|
|
|
|
|
int offset_gate = 0;
|
|
|
|
|
switch(mode){
|
|
|
|
|
case 0:
|
|
|
|
|
value = (float)midi_gate/1000.0f;
|
|
|
|
|
offset_gate = MeasureText(std::format("{:.2f}", value).c_str(), 12);
|
|
|
|
|
DrawText(std::format("{:.2f}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE );
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
value = (float)midi_cc_value;
|
|
|
|
|
offset_gate = MeasureText(std::format("{}", value).c_str(), 12);
|
|
|
|
|
DrawText(std::format("{}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE );
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
value = (float)midi_pitch_bend;
|
|
|
|
|
offset_gate = MeasureText(std::format("{}", value).c_str(), 12);
|
|
|
|
|
DrawText(std::format("{}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch(mode){
|
|
|
|
|
case 0:{
|
|
|
|
|
int offset = MeasureText(MIDI::Notes[(int)midi_note].c_str(), 12);
|
|
|
|
|
DrawText(MIDI::Notes[midi_note].c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
|
|
|
|
|
break;}
|
|
|
|
|
case 1:{
|
|
|
|
|
int offset = MeasureText(std::format("{}", midi_cc).c_str(), 12);
|
|
|
|
|
DrawText(std::format("{}", midi_cc).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
|
|
|
|
|
break;}
|
|
|
|
|
case 2:{
|
|
|
|
|
int offset = MeasureText(std::format("{}", midi_pitch_bend).c_str(), 12);
|
|
|
|
|
DrawText(std::format("{}", midi_pitch_bend).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
|
|
|
|
|
break;}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-02 15:52:16 +01:00
|
|
|
|
2024-11-12 01:42:05 +01:00
|
|
|
/*Vec2Df connector = position - ((position - mouse)).norm() * (radius + RADIUS);*/
|
|
|
|
|
/*float opacity = 150.0f - Clamp(position.dist(mouse), 0.0f, 150.0f);*/
|
|
|
|
|
/**/
|
|
|
|
|
/*if(hover_connect){*/
|
|
|
|
|
/* DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255});*/
|
|
|
|
|
/*} else {*/
|
|
|
|
|
/* DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity});*/
|
|
|
|
|
/*}*/
|
2024-11-03 03:48:49 +01:00
|
|
|
if(highlighted) DrawCircleLinesV(position, radius+2, (Color){255, 0, 0, 200});
|
2024-11-04 01:00:59 +01:00
|
|
|
DrawText(std::format("{}", id).c_str(), position.x + 20.0f, position.y + 20.0f, 10, WHITE);
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|