2024-10-31 01:43:00 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-12-07 15:28:33 +01:00
|
|
|
#include "config-node.h"
|
2024-11-01 02:38:47 +01:00
|
|
|
#include "datatypes.h"
|
2024-12-07 22:09:06 +01:00
|
|
|
#include "edge.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{
|
2024-12-07 15:28:33 +01:00
|
|
|
private:
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiNote midiNote;
|
|
|
|
|
MIDI::MidiCC midiCC;
|
|
|
|
|
MIDI::MidiPitchBend midiPitchBend;
|
|
|
|
|
MIDI::MidiAftertouch midiAftertouch;
|
|
|
|
|
MIDI::MidiPolyPressure midiPolyPressure;
|
|
|
|
|
MIDI::MidiPC midiPC;
|
2024-12-07 15:28:33 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
public:
|
2024-11-14 01:37:16 +01:00
|
|
|
|
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-12-05 00:01:42 +01:00
|
|
|
MidiNode() : Node() {std::cout << "MidiNode Constructor std" << std::endl;}
|
2024-11-03 03:48:49 +01:00
|
|
|
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
|
|
|
float start = 0;
|
|
|
|
|
float fade = 0;
|
|
|
|
|
float time = 0;
|
|
|
|
|
float last = 0;
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-12-05 00:01:42 +01:00
|
|
|
std::shared_ptr<MidiNode> getPtr(){
|
|
|
|
|
return std::static_pointer_cast<MidiNode>(shared_from_this());
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
2024-12-07 22:09:06 +01:00
|
|
|
fade = midiNote.gate;
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
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-21 02:03:32 +01:00
|
|
|
int GGate(){
|
2024-12-07 22:09:06 +01:00
|
|
|
return midiNote.gate;
|
2024-10-31 01:43:00 +01:00
|
|
|
}
|
2024-12-07 03:44:03 +01:00
|
|
|
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiNote getNotes(){
|
|
|
|
|
MIDI::MidiNote cNote;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cNote += cn.lock()->getNotes();
|
|
|
|
|
}
|
|
|
|
|
return cNote;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MIDI::MidiCC getCC(){
|
|
|
|
|
MIDI::MidiCC cCC;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cCC += cn.lock()->getCC();
|
|
|
|
|
}
|
|
|
|
|
return cCC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MIDI::MidiPC getPC(){
|
|
|
|
|
MIDI::MidiPC cPC;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cPC += cn.lock()->getPC();
|
|
|
|
|
}
|
|
|
|
|
return cPC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MIDI::MidiPitchBend getPitchBend(){
|
|
|
|
|
MIDI::MidiPitchBend cPitchBend;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cPitchBend += cn.lock()->getPitchBend();
|
|
|
|
|
}
|
|
|
|
|
return cPitchBend;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MIDI::MidiAftertouch getAftertouch(){
|
|
|
|
|
MIDI::MidiAftertouch cAftertouch;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cAftertouch += cn.lock()->getAftertouch();
|
|
|
|
|
}
|
|
|
|
|
return cAftertouch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MIDI::MidiPolyPressure getPolyPressure(){
|
|
|
|
|
MIDI::MidiPolyPressure cPolyPressure;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cPolyPressure += cn.lock()->getPolyPressure();
|
|
|
|
|
}
|
|
|
|
|
return cPolyPressure;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 15:28:33 +01:00
|
|
|
std::vector<std::weak_ptr<ConfigNode>> getConnectedConfigNodes(){
|
|
|
|
|
auto config_conns = connections | RANGE_FILTER([](EDGES::SPTR_Edge c){ return c->start.lock()->getNodeType() == NodeType::CONFIGNODE || c->end.lock()->getNodeType() == NodeType::CONFIGNODE;}) | std::ranges::to<std::vector<std::shared_ptr<EDGES::Edge>>>();
|
|
|
|
|
std::vector<std::weak_ptr<ConfigNode>> config_nodes;
|
|
|
|
|
for(auto e : config_conns){
|
|
|
|
|
if(e->start.lock()->getNodeType() == NodeType::CONFIGNODE) config_nodes.push_back(std::dynamic_pointer_cast<ConfigNode>(e->start.lock()));
|
|
|
|
|
if(e->end.lock()->getNodeType() == NodeType::CONFIGNODE) config_nodes.push_back(std::dynamic_pointer_cast<ConfigNode>(e->end.lock()));
|
|
|
|
|
}
|
|
|
|
|
return config_nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-30 02:54:40 +01:00
|
|
|
void update() override {
|
|
|
|
|
Node::update();
|
|
|
|
|
mode = state->node_mode;
|
2024-12-07 15:28:33 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getMidiNote(){
|
|
|
|
|
int mod_notes = 0;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
mod_notes += cn.lock()->midiNote.note;
|
|
|
|
|
}
|
2024-12-07 22:09:06 +01:00
|
|
|
return midiNote.note + mod_notes;
|
2024-12-07 15:28:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void modMidiNote(int incr){
|
2024-12-07 22:09:06 +01:00
|
|
|
midiNote.note += incr;
|
|
|
|
|
if(midiNote.note < 0 ) midiNote.note = VISEQ::MIDI::Notes.size()-1;
|
|
|
|
|
if(midiNote.note >= (int)VISEQ::MIDI::Notes.size()) midiNote.note = 0;
|
2024-12-07 15:28:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void modMidiCC(int incr){
|
2024-12-07 22:09:06 +01:00
|
|
|
midiCC.control += incr;
|
|
|
|
|
if(midiCC.control < 0 ) midiCC.control = 127;
|
|
|
|
|
if(midiCC.control > 127 ) midiCC.control = 0;
|
2024-12-07 15:28:33 +01:00
|
|
|
}
|
2024-12-07 22:09:06 +01:00
|
|
|
|
2024-12-07 15:28:33 +01:00
|
|
|
void modMidiPitchBend(int incr){
|
2024-12-07 22:09:06 +01:00
|
|
|
midiPitchBend.value += incr;
|
|
|
|
|
if(midiPitchBend.value < 0 ) midiPitchBend.value = 0;
|
|
|
|
|
if(midiPitchBend.value > 16383 ) midiPitchBend.value = 16383;
|
2024-11-30 02:54:40 +01:00
|
|
|
}
|
2024-11-21 02:03:32 +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
|
|
|
|
2024-11-19 01:04:06 +01:00
|
|
|
if(KEYS_DOWN.ctrl && !KEYS_DOWN.alt){
|
2024-11-24 03:08:06 +01:00
|
|
|
switch(state->node_mode){
|
2024-11-14 00:55:09 +01:00
|
|
|
case 0:{
|
2024-12-07 15:28:33 +01:00
|
|
|
modMidiNote(wheel);
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
case 1:{
|
2024-12-07 15:28:33 +01:00
|
|
|
modMidiCC(wheel);
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
case 2:{
|
2024-12-07 15:28:33 +01:00
|
|
|
modMidiPitchBend(wheel);
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
};
|
2024-11-19 01:04:06 +01:00
|
|
|
} else if(KEYS_DOWN.shift && !KEYS_DOWN.alt) {
|
2024-12-07 22:09:06 +01:00
|
|
|
midiNote.velocity += wheel;
|
|
|
|
|
if(midiNote.velocity < 0 ) midiNote.velocity = 127;
|
|
|
|
|
if(midiNote.velocity > 127 ) midiNote.velocity = 0;
|
2024-11-19 01:04:06 +01:00
|
|
|
} else if(KEYS_DOWN.alt) {
|
2024-11-24 03:08:06 +01:00
|
|
|
switch(state->node_mode){
|
2024-11-14 00:55:09 +01:00
|
|
|
case 0:{
|
2024-11-19 01:04:06 +01:00
|
|
|
float incr = (float)wheel * (KEYS_DOWN.shift ? 100.0f : KEYS_DOWN.ctrl ? 1000.0f : 10.0f);
|
2024-12-07 22:09:06 +01:00
|
|
|
midiNote.gate += incr;
|
|
|
|
|
if(midiNote.gate < 0 ) midiNote.gate = 0;
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
case 1:{
|
2024-12-07 22:09:06 +01:00
|
|
|
midiCC.value += wheel;
|
|
|
|
|
if(midiCC.value < 0 ) midiCC.value = 0;
|
|
|
|
|
if(midiCC.value > 127 ) midiCC.value = 127;
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
|
|
|
|
case 2:{
|
2024-11-19 01:04:06 +01:00
|
|
|
float incr = (float)wheel * (KEYS_DOWN.shift ? 100.0f : KEYS_DOWN.ctrl ? 1000.0f : 10.0f);
|
2024-12-07 22:09:06 +01:00
|
|
|
midiPitchBend.value += incr;
|
|
|
|
|
if(midiPitchBend.value < 0 ) midiPitchBend.value = 0;
|
|
|
|
|
if(midiPitchBend.value > 16383 ) midiPitchBend.value = 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-17 02:40:31 +01:00
|
|
|
if(hovering() || selected) interact();
|
2024-11-14 01:37:16 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
last = time;
|
|
|
|
|
time = GetTime();
|
2024-12-07 22:09:06 +01:00
|
|
|
if(time - start >= (float)midiNote.gate / 1000.0f){
|
2024-11-03 03:48:49 +01:00
|
|
|
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});
|
2024-12-07 22:09:06 +01:00
|
|
|
DrawRing(position, radius, radius+4, 0.0f - 90.0f, (360.0f/127.0f) * midiNote.velocity - 90.0f, 24, (Color){158, 134, 200, 255});
|
2024-11-03 03:48:49 +01:00
|
|
|
DrawCircleLinesV(position, radius + 4, (Color){100, 100, 100, 255});
|
|
|
|
|
|
2024-12-07 22:09:06 +01:00
|
|
|
float midi_gate_map = round((255.f / midiNote.gate) * fade);
|
2024-11-03 03:48:49 +01:00
|
|
|
|
|
|
|
|
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);
|
2024-11-18 01:57:10 +01:00
|
|
|
if(picked_up || in_selection_rect || hovering()) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255});
|
2024-11-17 02:40:31 +01:00
|
|
|
if(selected) DrawCircle(position.x, position.y, radius, (Color){255, 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});
|
|
|
|
|
|
2024-11-19 01:04:06 +01:00
|
|
|
if(KEYS_DOWN.alt){
|
2024-11-03 03:48:49 +01:00
|
|
|
float value = 0;
|
|
|
|
|
int offset_gate = 0;
|
|
|
|
|
switch(mode){
|
|
|
|
|
case 0:
|
2024-12-07 22:09:06 +01:00
|
|
|
value = (float)midiNote.gate/1000.0f;
|
2024-11-03 03:48:49 +01:00
|
|
|
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:
|
2024-12-07 22:09:06 +01:00
|
|
|
value = (float)midiCC.value;
|
2024-11-03 03:48:49 +01:00
|
|
|
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:
|
2024-12-07 22:09:06 +01:00
|
|
|
value = (float)midiPitchBend.value;
|
2024-11-03 03:48:49 +01:00
|
|
|
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:{
|
2024-12-07 22:09:06 +01:00
|
|
|
int offset = MeasureText(MIDI::Notes[(int)midiNote.note].c_str(), 12);
|
|
|
|
|
DrawText(MIDI::Notes[midiNote.note].c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
|
2024-11-03 03:48:49 +01:00
|
|
|
break;}
|
|
|
|
|
case 1:{
|
2024-12-07 22:09:06 +01:00
|
|
|
int offset = MeasureText(std::format("{}", midiCC.control).c_str(), 12);
|
|
|
|
|
DrawText(std::format("{}", midiCC.control).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
|
2024-11-03 03:48:49 +01:00
|
|
|
break;}
|
|
|
|
|
case 2:{
|
2024-12-07 22:09:06 +01:00
|
|
|
int offset = MeasureText(std::format("{}", midiPitchBend.value).c_str(), 12);
|
|
|
|
|
DrawText(std::format("{}", midiPitchBend.value).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
|
2024-11-03 03:48:49 +01:00
|
|
|
break;}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-02 15:52:16 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|