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-12-15 01:47:53 +01:00
|
|
|
#include "node-handle.h"
|
2024-10-31 01:43:00 +01:00
|
|
|
#include "node.h"
|
2024-12-09 01:40:13 +01:00
|
|
|
#include "raylib.h"
|
2024-10-31 01:43:00 +01:00
|
|
|
#include "raymath.h"
|
2024-12-09 01:40:13 +01:00
|
|
|
#include "state.h"
|
2024-10-31 01:43:00 +01:00
|
|
|
#include <map>
|
2024-12-13 01:15:55 +01:00
|
|
|
#include <memory>
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
namespace VISEQ::APP::UI{
|
|
|
|
|
class AppUI;
|
|
|
|
|
}
|
|
|
|
|
|
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-08 02:25:57 +01:00
|
|
|
friend class APP::UI::AppUI;
|
|
|
|
|
|
2024-12-07 15:28:33 +01:00
|
|
|
private:
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiNote midiNote;
|
|
|
|
|
MIDI::MidiCC midiCC;
|
2024-12-11 01:16:06 +01:00
|
|
|
MIDI::MidiPC midiPC;
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiPitchBend midiPitchBend;
|
|
|
|
|
MIDI::MidiAftertouch midiAftertouch;
|
|
|
|
|
MIDI::MidiPolyPressure midiPolyPressure;
|
2024-12-15 01:47:53 +01:00
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<NodeHandle<int>>> midiNoteHandles;
|
|
|
|
|
std::vector<std::shared_ptr<NodeHandle<int>>> midiCCHandles;
|
|
|
|
|
std::vector<std::shared_ptr<NodeHandle<int>>> midiPCHandles;
|
|
|
|
|
std::vector<std::shared_ptr<NodeHandle<int>>> midiPitchBendHandles;
|
|
|
|
|
std::vector<std::shared_ptr<NodeHandle<int>>> midiAftertouchHandles;
|
|
|
|
|
std::vector<std::shared_ptr<NodeHandle<int>>> midiPolyPressureHandles;
|
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-09 01:40:13 +01:00
|
|
|
MidiNode() {init();}
|
|
|
|
|
MidiNode(Vec2Df position) : Node(position) {init();}
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
NodeType nodeType = NodeType::MIDINODE;
|
2024-12-13 01:15:55 +01:00
|
|
|
|
|
|
|
|
//std::vector<std::shared_ptr<ControlNode>> controlNodes;
|
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;
|
|
|
|
|
|
|
|
|
|
float start = 0;
|
|
|
|
|
float fade = 0;
|
|
|
|
|
float time = 0;
|
|
|
|
|
float last = 0;
|
2024-12-09 01:40:13 +01:00
|
|
|
|
|
|
|
|
void init(){
|
2024-12-15 01:47:53 +01:00
|
|
|
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.note, position, VS_COLOR_GREEN, "NOTE"));
|
2024-12-16 02:10:58 +01:00
|
|
|
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
|
2024-12-15 03:17:10 +01:00
|
|
|
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.gate, position, VS_COLOR_RED, "GATE", 10, 30000, 40, 300));
|
2024-12-15 01:47:53 +01:00
|
|
|
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.velocity, position, VS_COLOR_PURPLE, "VELOCITY"));
|
|
|
|
|
|
|
|
|
|
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.control, position, VS_COLOR_SUN, "CONTROL"));
|
2024-12-16 02:10:58 +01:00
|
|
|
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
|
2024-12-15 01:47:53 +01:00
|
|
|
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.value, position, VS_COLOR_GREEN, "VALUE"));
|
|
|
|
|
|
|
|
|
|
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.program, position, VS_COLOR_SUN, "PROGRAM"));
|
2024-12-16 02:10:58 +01:00
|
|
|
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
|
2024-12-15 01:47:53 +01:00
|
|
|
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.value, position, VS_COLOR_GREEN, "VALUE"));
|
|
|
|
|
|
2024-12-16 02:10:58 +01:00
|
|
|
midiPitchBendHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
|
2024-12-15 01:47:53 +01:00
|
|
|
midiPitchBendHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.value, position, VS_COLOR_GREEN, "VALUE", -8192, 8192, 40, 300));
|
|
|
|
|
|
2024-12-16 02:10:58 +01:00
|
|
|
midiAftertouchHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
|
2024-12-15 01:47:53 +01:00
|
|
|
midiAftertouchHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.value, position, VS_COLOR_GREEN, "VALUE"));
|
|
|
|
|
|
2024-12-16 02:10:58 +01:00
|
|
|
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150));
|
2024-12-15 01:47:53 +01:00
|
|
|
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.value, position, VS_COLOR_GREEN, "VALUE"));
|
|
|
|
|
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.note, position, VS_COLOR_SUN, "NOTE"));
|
2024-12-09 01:40:13 +01:00
|
|
|
}
|
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-08 14:21:46 +01:00
|
|
|
fade = getNotes().gate;
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-12-08 14:21:46 +01:00
|
|
|
void setMode(int _mode) override {
|
2024-11-03 03:48:49 +01:00
|
|
|
mode = _mode;
|
|
|
|
|
}
|
2024-10-31 01:43:00 +01:00
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
MIDI::MidiNote getNotes() const {
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiNote cNote;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cNote += cn.lock()->getNotes();
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
return midiNote + cNote;
|
2024-12-07 22:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
MIDI::MidiCC getCC() const {
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiCC cCC;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cCC += cn.lock()->getCC();
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
return midiCC + cCC;
|
2024-12-07 22:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
MIDI::MidiPC getPC() const {
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiPC cPC;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cPC += cn.lock()->getPC();
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
return midiPC + cPC;
|
2024-12-07 22:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
MIDI::MidiPitchBend getPitchBend() const {
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiPitchBend cPitchBend;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cPitchBend += cn.lock()->getPitchBend();
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
return midiPitchBend + cPitchBend;
|
2024-12-07 22:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
MIDI::MidiAftertouch getAftertouch() const {
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiAftertouch cAftertouch;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cAftertouch += cn.lock()->getAftertouch();
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
return midiAftertouch + cAftertouch;
|
2024-12-07 22:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
MIDI::MidiPolyPressure getPolyPressure() const {
|
2024-12-07 22:09:06 +01:00
|
|
|
MIDI::MidiPolyPressure cPolyPressure;
|
|
|
|
|
for(auto cn : getConnectedConfigNodes()){
|
|
|
|
|
cPolyPressure += cn.lock()->getPolyPressure();
|
|
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
return midiPolyPressure + cPolyPressure;
|
2024-12-07 22:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
std::vector<std::weak_ptr<ConfigNode>> getConnectedConfigNodes() const {
|
2024-12-07 15:28:33 +01:00
|
|
|
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()));
|
|
|
|
|
}
|
2024-12-08 14:21:46 +01:00
|
|
|
/*std::cout << "id: " << id << " n cn: " << config_nodes.size() << std::endl;*/
|
2024-12-07 15:28:33 +01:00
|
|
|
return config_nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-30 02:54:40 +01:00
|
|
|
void update() override {
|
|
|
|
|
Node::update();
|
2024-12-08 02:25:57 +01:00
|
|
|
mode = state->node_mode;
|
2024-12-15 01:47:53 +01:00
|
|
|
for(auto mh : midiNoteHandles){
|
|
|
|
|
mh->update(position);
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiCCHandles){
|
|
|
|
|
mh->update(position);
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiPCHandles){
|
|
|
|
|
mh->update(position);
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiPitchBendHandles){
|
|
|
|
|
mh->update(position);
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiAftertouchHandles){
|
|
|
|
|
mh->update(position);
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiPolyPressureHandles){
|
|
|
|
|
mh->update(position);
|
|
|
|
|
}
|
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-11 01:16:06 +01:00
|
|
|
void modMidiPC(int incr){
|
|
|
|
|
midiPC.program += incr;
|
|
|
|
|
if(midiPC.program < 0 ) midiPC.program = 127;
|
|
|
|
|
if(midiPC.program > 127 ) midiPC.program = 0;
|
|
|
|
|
}
|
|
|
|
|
|
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-12-11 01:16:06 +01:00
|
|
|
|
|
|
|
|
void modMidiAftertouch(int incr){
|
|
|
|
|
midiAftertouch.value += incr;
|
|
|
|
|
if(midiAftertouch.value < 0 ) midiAftertouch.value = 0;
|
|
|
|
|
if(midiAftertouch.value > 127 ) midiAftertouch.value = 127;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void modMidiPolyPressure(int incr){
|
|
|
|
|
midiPolyPressure.value += incr;
|
|
|
|
|
if(midiPolyPressure.value < 0 ) midiPolyPressure.value = 0;
|
|
|
|
|
if(midiPolyPressure.value > 127 ) midiPolyPressure.value = 127;
|
|
|
|
|
}
|
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-11 01:16:06 +01:00
|
|
|
modMidiPC(wheel);
|
|
|
|
|
break;}
|
|
|
|
|
case 3:{
|
2024-12-07 15:28:33 +01:00
|
|
|
modMidiPitchBend(wheel);
|
2024-11-14 00:55:09 +01:00
|
|
|
break;}
|
2024-12-11 01:16:06 +01:00
|
|
|
case 4:{
|
|
|
|
|
modMidiAftertouch(wheel);
|
|
|
|
|
break;}
|
|
|
|
|
case 5:{
|
|
|
|
|
modMidiPolyPressure(wheel);
|
|
|
|
|
break;}
|
2024-11-14 00:55:09 +01:00
|
|
|
};
|
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-12-11 01:16:06 +01:00
|
|
|
midiPC.value += wheel;
|
|
|
|
|
if(midiPC.value < 0 ) midiPC.value = 0;
|
|
|
|
|
if(midiPC.value > 127 ) midiPC.value = 127;
|
|
|
|
|
break;}
|
|
|
|
|
case 3:{
|
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-12-11 01:16:06 +01:00
|
|
|
case 4:{
|
|
|
|
|
float incr = (float)wheel * (KEYS_DOWN.shift ? 100.0f : KEYS_DOWN.ctrl ? 1000.0f : 10.0f);
|
|
|
|
|
midiAftertouch.value += incr;
|
|
|
|
|
if(midiAftertouch.value < 0 ) midiAftertouch.value = 0;
|
|
|
|
|
if(midiAftertouch.value > 127 ) midiAftertouch.value = 127;
|
|
|
|
|
break;}
|
|
|
|
|
case 5:{
|
|
|
|
|
float incr = (float)wheel * (KEYS_DOWN.shift ? 100.0f : KEYS_DOWN.ctrl ? 1000.0f : 10.0f);
|
|
|
|
|
midiPolyPressure.value += incr;
|
|
|
|
|
if(midiPolyPressure.value < 0 ) midiPolyPressure.value = 0;
|
|
|
|
|
if(midiPolyPressure.value > 127 ) midiPolyPressure.value = 127;
|
|
|
|
|
break;}
|
2024-11-14 00:55:09 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
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-12-15 01:47:53 +01:00
|
|
|
for(auto mh : midiNoteHandles){
|
|
|
|
|
if(mode == 0) mh->unlock();
|
|
|
|
|
else mh->lock();
|
|
|
|
|
mh->draw();
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiCCHandles){
|
|
|
|
|
if(mode == 1) mh->unlock();
|
|
|
|
|
else mh->lock();
|
|
|
|
|
mh->draw();
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiPCHandles){
|
|
|
|
|
if(mode == 2) mh->unlock();
|
|
|
|
|
else mh->lock();
|
|
|
|
|
mh->draw();
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiPitchBendHandles){
|
|
|
|
|
if(mode == 3) mh->unlock();
|
|
|
|
|
else mh->lock();
|
|
|
|
|
mh->draw();
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiAftertouchHandles){
|
|
|
|
|
if(mode == 4) mh->unlock();
|
|
|
|
|
else mh->lock();
|
|
|
|
|
mh->draw();
|
|
|
|
|
}
|
|
|
|
|
for(auto mh : midiPolyPressureHandles){
|
|
|
|
|
if(mode == 5) mh->unlock();
|
|
|
|
|
else mh->lock();
|
|
|
|
|
mh->draw();
|
|
|
|
|
}
|
2024-12-09 01:40:13 +01:00
|
|
|
|
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-08 14:21:46 +01:00
|
|
|
if(time - start >= (float)getNotes().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
|
|
|
|
2024-12-09 01:40:13 +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) * getNotes().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-15 03:17:10 +01:00
|
|
|
float trigger_alpha = (1.f / getNotes().gate) * fade;
|
|
|
|
|
|
|
|
|
|
if(!picked_up && !selected && !in_selection_rect && !hovering()) DrawCircle(position.x, position.y, radius, ColorLerp(state->mode_color, VS_COLOR_RED, trigger_alpha));
|
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-12-09 01:40:13 +01:00
|
|
|
|
2024-12-15 03:17:10 +01:00
|
|
|
/*if(fade > 0) DrawCircle(position.x, position.y, radius, ColorAlpha(VS_COLOR_RED, trigger_alpha));*/
|
|
|
|
|
|
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-08 02:25:57 +01:00
|
|
|
value = (float)getNotes().gate/1000.0f;
|
2024-11-03 03:48:49 +01:00
|
|
|
offset_gate = MeasureText(std::format("{:.2f}", value).c_str(), 12);
|
2024-12-13 00:30:31 +01:00
|
|
|
DrawText(std::format("{:.2f}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE );
|
2024-11-03 03:48:49 +01:00
|
|
|
break;
|
|
|
|
|
case 1:
|
2024-12-08 02:25:57 +01:00
|
|
|
value = (float)getCC().value;
|
2024-11-03 03:48:49 +01:00
|
|
|
offset_gate = MeasureText(std::format("{}", value).c_str(), 12);
|
2024-12-13 00:30:31 +01:00
|
|
|
DrawText(std::format("{}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE );
|
2024-11-03 03:48:49 +01:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2024-12-08 02:25:57 +01:00
|
|
|
value = (float)getPitchBend().value;
|
2024-11-03 03:48:49 +01:00
|
|
|
offset_gate = MeasureText(std::format("{}", value).c_str(), 12);
|
2024-12-13 00:30:31 +01:00
|
|
|
DrawText(std::format("{}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE );
|
2024-11-03 03:48:49 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch(mode){
|
|
|
|
|
case 0:{
|
2024-12-08 02:25:57 +01:00
|
|
|
int offset = MeasureText(MIDI::Notes[(int)getNotes().note].c_str(), 12);
|
2024-12-13 00:30:31 +01:00
|
|
|
DrawText(MIDI::Notes[getNotes().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-08 02:25:57 +01:00
|
|
|
int offset = MeasureText(std::format("{}", getCC().control).c_str(), 12);
|
2024-12-13 00:30:31 +01:00
|
|
|
DrawText(std::format("{}", getCC().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-08 02:25:57 +01:00
|
|
|
int offset = MeasureText(std::format("{}", getPitchBend().value).c_str(), 12);
|
2024-12-13 00:30:31 +01:00
|
|
|
DrawText(std::format("{}", getPitchBend().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-12-09 01:40:13 +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
|
|
|
}
|
2024-12-08 02:25:57 +01:00
|
|
|
|
|
|
|
|
friend void to_json(json& j, const MidiNode& N){
|
|
|
|
|
std::vector<int> conns;
|
|
|
|
|
std::ranges::transform(N.connections.begin(), N.connections.end(), std::back_inserter(conns), [](VISEQ::GRAPH::EDGES::SPTR_Edge e){ return e->id;});
|
|
|
|
|
j = json{
|
|
|
|
|
{"id", N.id},
|
|
|
|
|
{"position", N.position},
|
|
|
|
|
{"distributionMode", N.distributionMode},
|
|
|
|
|
{"nodeType", N.nodeType},
|
2024-12-16 02:10:58 +01:00
|
|
|
{"midiNote", N.midiNote},
|
|
|
|
|
{"midiCC", N.midiCC},
|
|
|
|
|
{"midiPC", N.midiPC},
|
|
|
|
|
{"midiPitchBend", N.midiPitchBend},
|
|
|
|
|
{"midiAftertouch", N.midiAftertouch},
|
|
|
|
|
{"midiPolyPressure", N.midiPolyPressure},
|
|
|
|
|
//{"midiNoteHandle", N.midiNoteHandles},
|
|
|
|
|
/*{"midiCCHandle", N.midiCCHandles},*/
|
|
|
|
|
/*{"midiPCHandle", N.midiPCHandles},*/
|
|
|
|
|
/*{"midiPitchBendHandle", N.midiPitchBendHandles},*/
|
|
|
|
|
/*{"midiAftertouchHandle", N.midiAftertouchHandles},*/
|
|
|
|
|
/*{"midiPolyPressureHandle", N.midiPolyPressureHandles},*/
|
2024-12-08 02:25:57 +01:00
|
|
|
{"connections",conns}};
|
2024-12-16 02:10:58 +01:00
|
|
|
|
2024-12-08 02:25:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend void from_json(const json& j, MidiNode& N){
|
|
|
|
|
std::cout << "MidiNode" << std::endl;
|
|
|
|
|
|
|
|
|
|
j.at("id").get_to(N.id);
|
|
|
|
|
j.at("position").get_to<Vec2Df>(N.position);
|
|
|
|
|
j.at("distributionMode").get_to(N.distributionMode);
|
|
|
|
|
j.at("nodeType").get_to(N.nodeType);
|
2024-12-16 02:10:58 +01:00
|
|
|
j.at("midiNote").get_to(N.midiNote);
|
|
|
|
|
j.at("midiCC").get_to(N.midiCC);
|
|
|
|
|
j.at("midiPC").get_to(N.midiPC);
|
|
|
|
|
j.at("midiPitchBend").get_to(N.midiPitchBend);
|
|
|
|
|
j.at("midiAftertouch").get_to(N.midiAftertouch);
|
|
|
|
|
j.at("midiPolyPressure").get_to(N.midiPolyPressure);
|
|
|
|
|
/*j.at("midiNoteHandle").get_to(N.midiNoteHandles);*/
|
|
|
|
|
/*j.at("midiCCHandle").get_to(N.midiCCHandles);*/
|
|
|
|
|
/*j.at("midiPCHandle").get_to(N.midiPCHandles);*/
|
|
|
|
|
/*j.at("midiPitchBendHandle").get_to(N.midiPitchBendHandles);*/
|
|
|
|
|
/*j.at("midiAftertouchHandle").get_to(N.midiAftertouchHandles);*/
|
|
|
|
|
/*j.at("midiPolyPressureHandle").get_to(N.midiPolyPressureHandles);*/
|
2024-12-08 02:25:57 +01:00
|
|
|
|
|
|
|
|
//j.at("connections").get_to(N.connections);
|
|
|
|
|
}
|
2024-11-03 03:48:49 +01:00
|
|
|
};
|
|
|
|
|
}
|