more refactoring and breaking things
This commit is contained in:
@@ -0,0 +1,391 @@
|
||||
#include "midi-node.h"
|
||||
|
||||
#include "config-node.h"
|
||||
#include "datatypes.h"
|
||||
#include "edge.h"
|
||||
#include "node-handle.h"
|
||||
#include "node.h"
|
||||
#include "raylib.h"
|
||||
#include "state.h"
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
namespace VISEQ::GRAPH::NODES {
|
||||
|
||||
void MidiNode::init(){
|
||||
float orbit_1 = radius + 25.0f;
|
||||
float orbit_2 = orbit_1 + 20.0f;
|
||||
float orbit_3 = orbit_2 + 20.0f;
|
||||
float orbit_4 = orbit_3 + 20.0f;
|
||||
float orbit_5 = orbit_4 + 30.0f;
|
||||
|
||||
midiHandles[NOTE].emplace_back(std::make_shared<NodeHandle<int>>(midiNote.note, position, VS_COLOR_GREEN, "NOTE", orbit_5, 12));
|
||||
midiHandles[NOTE].emplace_back(std::make_shared<NodeHandle<int>>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 16, 1, 16, 40, 150));
|
||||
midiHandles[NOTE].emplace_back(std::make_shared<NodeHandle<int>>(midiNote.gate, position, VS_COLOR_RED, "GATE", orbit_3, 30, 10, 30000, 40, 300));
|
||||
midiHandles[NOTE].back()->logScale = true;
|
||||
midiHandles[NOTE].emplace_back(std::make_shared<NodeHandle<int>>(midiNote.velocity, position, VS_COLOR_PURPLE, "VELOCITY", orbit_4, 32));
|
||||
|
||||
midiHandles[CC].emplace_back(std::make_shared<NodeHandle<int>>(midiCC.control, position, VS_COLOR_SUN, "CONTROL", orbit_3, 32));
|
||||
midiHandles[CC].emplace_back(std::make_shared<NodeHandle<int>>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
|
||||
midiHandles[CC].emplace_back(std::make_shared<NodeHandle<int>>(midiCC.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32));
|
||||
|
||||
midiHandles[PC].emplace_back(std::make_shared<NodeHandle<int>>(midiPC.program, position, VS_COLOR_SUN, "PROGRAM", orbit_3, 32));
|
||||
midiHandles[PC].emplace_back(std::make_shared<NodeHandle<int>>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
|
||||
midiHandles[PC].emplace_back(std::make_shared<NodeHandle<int>>(midiPC.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32));
|
||||
|
||||
midiHandles[PB].emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
|
||||
midiHandles[PB].emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.value, position, VS_COLOR_GREEN, "VALUE", orbit_3, 256, -8192, 8192, 40, 300));
|
||||
|
||||
midiHandles[AT].emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
|
||||
midiHandles[AT].emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.value, position, VS_COLOR_GREEN, "VALUE", orbit_3, 32));
|
||||
|
||||
midiHandles[PP].emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
|
||||
midiHandles[PP].emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32));
|
||||
midiHandles[PP].emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.note, position, VS_COLOR_SUN, "NOTE", orbit_5, 12));
|
||||
}
|
||||
|
||||
std::shared_ptr<MidiNode> MidiNode::getPtr(){
|
||||
return std::static_pointer_cast<MidiNode>(shared_from_this());
|
||||
}
|
||||
|
||||
NodeType MidiNode::getNodeType() const {
|
||||
return nodeType;
|
||||
}
|
||||
|
||||
void MidiNode::setMidiPort(int midi_port, bool _state){
|
||||
midi_outs[midi_port].enabled = _state;
|
||||
}
|
||||
|
||||
void MidiNode::trigger() {
|
||||
triggered = true;
|
||||
start = GetTime();
|
||||
fade = getNotes().gate;
|
||||
}
|
||||
|
||||
void MidiNode::setMode(int _mode) {
|
||||
mode = _mode;
|
||||
}
|
||||
|
||||
MIDI::MidiNote MidiNode::getNotes() const {
|
||||
MIDI::MidiNote cNote;
|
||||
for(auto cn : getConnectedConfigNodes()){
|
||||
cNote += cn.lock()->getNotes();
|
||||
}
|
||||
return midiNote + cNote;
|
||||
}
|
||||
|
||||
MIDI::MidiCC MidiNode::getCC() const {
|
||||
MIDI::MidiCC cCC;
|
||||
for(auto cn : getConnectedConfigNodes()){
|
||||
cCC += cn.lock()->getCC();
|
||||
}
|
||||
return midiCC + cCC;
|
||||
}
|
||||
|
||||
MIDI::MidiPC MidiNode::getPC() const {
|
||||
MIDI::MidiPC cPC;
|
||||
for(auto cn : getConnectedConfigNodes()){
|
||||
cPC += cn.lock()->getPC();
|
||||
}
|
||||
return midiPC + cPC;
|
||||
}
|
||||
|
||||
MIDI::MidiPitchBend MidiNode::getPitchBend() const {
|
||||
MIDI::MidiPitchBend cPitchBend;
|
||||
for(auto cn : getConnectedConfigNodes()){
|
||||
cPitchBend += cn.lock()->getPitchBend();
|
||||
}
|
||||
return midiPitchBend + cPitchBend;
|
||||
}
|
||||
|
||||
MIDI::MidiAftertouch MidiNode::getAftertouch() const {
|
||||
MIDI::MidiAftertouch cAftertouch;
|
||||
for(auto cn : getConnectedConfigNodes()){
|
||||
cAftertouch += cn.lock()->getAftertouch();
|
||||
}
|
||||
return midiAftertouch + cAftertouch;
|
||||
}
|
||||
|
||||
MIDI::MidiPolyPressure MidiNode::getPolyPressure() const {
|
||||
MIDI::MidiPolyPressure cPolyPressure;
|
||||
for(auto cn : getConnectedConfigNodes()){
|
||||
cPolyPressure += cn.lock()->getPolyPressure();
|
||||
}
|
||||
return midiPolyPressure + cPolyPressure;
|
||||
}
|
||||
|
||||
std::vector<std::weak_ptr<ConfigNode>> MidiNode::getConnectedConfigNodes() const {
|
||||
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()));
|
||||
}
|
||||
/*std::cout << "id: " << id << " n cn: " << config_nodes.size() << std::endl;*/
|
||||
return config_nodes;
|
||||
}
|
||||
|
||||
void MidiNode::update() {
|
||||
Node::update();
|
||||
mode = state->node_mode;
|
||||
for(auto mh : midiHandles[NOTE]){
|
||||
mh->update(position);
|
||||
}
|
||||
for(auto mh : midiHandles[CC]){
|
||||
mh->update(position);
|
||||
}
|
||||
for(auto mh : midiHandles[PC]){
|
||||
mh->update(position);
|
||||
}
|
||||
for(auto mh : midiHandles[PB]){
|
||||
mh->update(position);
|
||||
}
|
||||
for(auto mh : midiHandles[AT]){
|
||||
mh->update(position);
|
||||
}
|
||||
for(auto mh : midiHandles[PP]){
|
||||
mh->update(position);
|
||||
}
|
||||
}
|
||||
|
||||
void MidiNode::modMidiNote(int incr){
|
||||
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;
|
||||
}
|
||||
|
||||
void MidiNode::modMidiCC(int incr){
|
||||
midiCC.control += incr;
|
||||
if(midiCC.control < 0 ) midiCC.control = 127;
|
||||
if(midiCC.control > 127 ) midiCC.control = 0;
|
||||
}
|
||||
|
||||
void MidiNode::modMidiPC(int incr){
|
||||
midiPC.program += incr;
|
||||
if(midiPC.program < 0 ) midiPC.program = 127;
|
||||
if(midiPC.program > 127 ) midiPC.program = 0;
|
||||
}
|
||||
|
||||
void MidiNode::modMidiPitchBend(int incr){
|
||||
midiPitchBend.value += incr;
|
||||
if(midiPitchBend.value < 0 ) midiPitchBend.value = 0;
|
||||
if(midiPitchBend.value > 16383 ) midiPitchBend.value = 16383;
|
||||
}
|
||||
|
||||
void MidiNode::modMidiAftertouch(int incr){
|
||||
midiAftertouch.value += incr;
|
||||
if(midiAftertouch.value < 0 ) midiAftertouch.value = 0;
|
||||
if(midiAftertouch.value > 127 ) midiAftertouch.value = 127;
|
||||
}
|
||||
|
||||
void MidiNode::modMidiPolyPressure(int incr){
|
||||
midiPolyPressure.value += incr;
|
||||
if(midiPolyPressure.value < 0 ) midiPolyPressure.value = 0;
|
||||
if(midiPolyPressure.value > 127 ) midiPolyPressure.value = 127;
|
||||
}
|
||||
|
||||
void MidiNode::interact(){
|
||||
float wheel = GetMouseWheelMove();
|
||||
|
||||
if(KEYS_DOWN.ctrl && !KEYS_DOWN.alt){
|
||||
switch(state->node_mode){
|
||||
case 0:{
|
||||
modMidiNote(wheel);
|
||||
break;}
|
||||
case 1:{
|
||||
modMidiCC(wheel);
|
||||
break;}
|
||||
case 2:{
|
||||
modMidiPC(wheel);
|
||||
break;}
|
||||
case 3:{
|
||||
modMidiPitchBend(wheel);
|
||||
break;}
|
||||
case 4:{
|
||||
modMidiAftertouch(wheel);
|
||||
break;}
|
||||
case 5:{
|
||||
modMidiPolyPressure(wheel);
|
||||
break;}
|
||||
};
|
||||
} else if(KEYS_DOWN.shift && !KEYS_DOWN.alt) {
|
||||
midiNote.velocity += wheel;
|
||||
if(midiNote.velocity < 0 ) midiNote.velocity = 127;
|
||||
if(midiNote.velocity > 127 ) midiNote.velocity = 0;
|
||||
} else if(KEYS_DOWN.alt) {
|
||||
switch(state->node_mode){
|
||||
case 0:{
|
||||
float incr = (float)wheel * (KEYS_DOWN.shift ? 100.0f : KEYS_DOWN.ctrl ? 1000.0f : 10.0f);
|
||||
midiNote.gate += incr;
|
||||
if(midiNote.gate < 0 ) midiNote.gate = 0;
|
||||
break;}
|
||||
case 1:{
|
||||
midiCC.value += wheel;
|
||||
if(midiCC.value < 0 ) midiCC.value = 0;
|
||||
if(midiCC.value > 127 ) midiCC.value = 127;
|
||||
break;}
|
||||
case 2:{
|
||||
midiPC.value += wheel;
|
||||
if(midiPC.value < 0 ) midiPC.value = 0;
|
||||
if(midiPC.value > 127 ) midiPC.value = 127;
|
||||
break;}
|
||||
case 3:{
|
||||
float incr = (float)wheel * (KEYS_DOWN.shift ? 100.0f : KEYS_DOWN.ctrl ? 1000.0f : 10.0f);
|
||||
midiPitchBend.value += incr;
|
||||
if(midiPitchBend.value < 0 ) midiPitchBend.value = 0;
|
||||
if(midiPitchBend.value > 16383 ) midiPitchBend.value = 16383;
|
||||
break;}
|
||||
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;}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void MidiNode::draw(Vec2Df mouse, Camera2D cam) {
|
||||
Node::draw();
|
||||
|
||||
for(int i = 0; i < 6; ++i){
|
||||
for(auto mh : midiHandles[(Handles)i]){
|
||||
mh->lock();
|
||||
}
|
||||
}
|
||||
|
||||
if(hovering() || selected) interact();
|
||||
|
||||
last = time;
|
||||
time = GetTime();
|
||||
if(time - start >= (float)getNotes().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) * getNotes().velocity - 90.0f, 24, (Color){158, 134, 200, 255});
|
||||
DrawCircleLinesV(position, radius + 4, (Color){100, 100, 100, 255});
|
||||
|
||||
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));
|
||||
if(picked_up || in_selection_rect || hovering()) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255});
|
||||
if(selected) DrawCircle(position.x, position.y, radius, (Color){255, 153, 187, 255});
|
||||
|
||||
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});
|
||||
bool modified = false;
|
||||
if(mode >= 0 && mode < 6){
|
||||
for(auto mh : midiHandles[(Handles)mode]){
|
||||
mh->unlock();
|
||||
mh->draw();
|
||||
std::string text = "";
|
||||
if(mh->hovering() || mh->picked_up){
|
||||
text = std::format("{}", mh->assignedValueRef);
|
||||
if(mh->name == "NOTE") text = MIDI::Notes[mh->assignedValueRef];
|
||||
if(mh->name == "GATE") text = std::format("{:.2f}", mh->assignedValueRef / 1000.0f);
|
||||
if(mh->name == "VALUE" && (Handles)mode == PB) text = std::format("{}", round(((float)mh->assignedValueRef / 8192.0f) * 100));
|
||||
DrawCenteredText(text, position, 12, WHITE);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!modified){
|
||||
switch((Handles)mode){
|
||||
case NOTE:{
|
||||
DrawCenteredText(MIDI::Notes[getNotes().note], position, 12, WHITE);
|
||||
break;}
|
||||
case CC:{
|
||||
DrawCenteredText(std::format("{}", getCC().value), position, 12, WHITE);
|
||||
break;}
|
||||
case PC:{
|
||||
DrawCenteredText(std::format("{}", getPC().value), position, 12, WHITE);
|
||||
break;}
|
||||
case PB:{
|
||||
DrawCenteredText(std::format("{}", round(((float)getPitchBend().value / 8192.0f) * 100)), position, 12, WHITE);
|
||||
break;}
|
||||
case AT:{
|
||||
DrawCenteredText(std::format("{}", getAftertouch().value), position, 12, WHITE);
|
||||
break;}
|
||||
case PP:{
|
||||
DrawCenteredText(std::format("{}", getPolyPressure().value), position, 12, WHITE);
|
||||
break;}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(highlighted) DrawCircleLinesV(position, radius+2, (Color){255, 0, 0, 200});
|
||||
}
|
||||
|
||||
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;});
|
||||
|
||||
std::vector<std::vector<Vec2Df>> handles;
|
||||
|
||||
for(auto i : N.midiHandles){
|
||||
handles.emplace_back();
|
||||
for(auto n : i.second){
|
||||
handles.at(i.first).push_back(n->position);
|
||||
}
|
||||
}
|
||||
|
||||
j = json{
|
||||
{"id", N.id},
|
||||
{"position", N.position},
|
||||
{"distributionMode", N.distributionMode},
|
||||
{"nodeType", N.nodeType},
|
||||
{"midiNote", N.midiNote},
|
||||
{"midiCC", N.midiCC},
|
||||
{"midiPC", N.midiPC},
|
||||
{"midiPitchBend", N.midiPitchBend},
|
||||
{"midiAftertouch", N.midiAftertouch},
|
||||
{"midiPolyPressure", N.midiPolyPressure},
|
||||
{"handles", handles},
|
||||
{"connections",conns}};
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
std::vector<std::vector<Vec2Df>> handles;
|
||||
|
||||
j.at("handles").get_to(handles);
|
||||
|
||||
int i = 0;
|
||||
for(auto n : handles){
|
||||
int j = 0;
|
||||
for(auto nn : n){
|
||||
N.midiHandles[(Handles)i][j]->position = nn;
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user