More UI tweaks and some refactoring. Nice!

This commit is contained in:
Sebastian
2024-12-29 01:17:44 +01:00
parent 011552c020
commit e5f614ce06
2 changed files with 97 additions and 173 deletions
+89 -166
View File
@@ -1,5 +1,6 @@
#pragma once
#include "button.h"
#include "config-node.h"
#include "datatypes.h"
#include "edge.h"
@@ -31,13 +32,6 @@ namespace VISEQ::GRAPH::NODES {
std::map<Handles, std::vector<std::shared_ptr<NodeHandle<int>>>> midiHandles;
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;
public:
struct NodeMidiOut{
@@ -79,31 +73,29 @@ namespace VISEQ::GRAPH::NODES {
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.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));
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.note, position, VS_COLOR_GREEN, "NOTE", orbit_5, 12));
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 16, 1, 16, 40, 150));
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.gate, position, VS_COLOR_RED, "GATE", orbit_3, 30, 10, 30000, 40, 300));
midiNoteHandles.back()->logScale = true;
midiNoteHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiNote.velocity, position, VS_COLOR_PURPLE, "VELOCITY", 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));
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.control, position, VS_COLOR_SUN, "CONTROL", orbit_3, 32));
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
midiCCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiCC.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32));
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));
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.program, position, VS_COLOR_SUN, "PROGRAM", orbit_3, 32));
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
midiPCHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPC.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32));
midiPitchBendHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
midiPitchBendHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPitchBend.value, position, VS_COLOR_GREEN, "VALUE", orbit_3, 256, -8192, 8192, 40, 300));
midiAftertouchHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
midiAftertouchHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiAftertouch.value, position, VS_COLOR_GREEN, "VALUE", orbit_3, 32));
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150));
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32));
midiPolyPressureHandles.emplace_back(std::make_shared<NodeHandle<int>>(midiPolyPressure.note, position, VS_COLOR_SUN, "NOTE", orbit_5, 12));
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> getPtr(){
@@ -188,22 +180,22 @@ namespace VISEQ::GRAPH::NODES {
void update() override {
Node::update();
mode = state->node_mode;
for(auto mh : midiNoteHandles){
for(auto mh : midiHandles[NOTE]){
mh->update(position);
}
for(auto mh : midiCCHandles){
for(auto mh : midiHandles[CC]){
mh->update(position);
}
for(auto mh : midiPCHandles){
for(auto mh : midiHandles[PC]){
mh->update(position);
}
for(auto mh : midiPitchBendHandles){
for(auto mh : midiHandles[PB]){
mh->update(position);
}
for(auto mh : midiAftertouchHandles){
for(auto mh : midiHandles[AT]){
mh->update(position);
}
for(auto mh : midiPolyPressureHandles){
for(auto mh : midiHandles[PP]){
mh->update(position);
}
}
@@ -313,35 +305,11 @@ namespace VISEQ::GRAPH::NODES {
void draw(Vec2Df mouse, Camera2D cam) override {
Node::draw();
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();
for(int i = 0; i < 6; ++i){
for(auto mh : midiHandles[(Handles)i]){
mh->lock();
}
}
if(hovering() || selected) interact();
@@ -369,77 +337,61 @@ namespace VISEQ::GRAPH::NODES {
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(fade > 0) DrawCircle(position.x, position.y, radius, ColorAlpha(VS_COLOR_RED, trigger_alpha));*/
if(KEYS_DOWN.alt){
float value = 0;
int offset_gate = 0;
switch(mode){
case 0:
value = (float)getNotes().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)getCC().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)getPitchBend().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;
}
} else {
switch(mode){
case 0:{
int offset = MeasureText(MIDI::Notes[(int)getNotes().note].c_str(), 12);
DrawText(MIDI::Notes[getNotes().note].c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
break;}
case 1:{
int offset = MeasureText(std::format("{}", getCC().control).c_str(), 12);
DrawText(std::format("{}", getCC().control).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
break;}
case 2:{
int offset = MeasureText(std::format("{}", getPitchBend().value).c_str(), 12);
DrawText(std::format("{}", getPitchBend().value).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
break;}
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});
//DrawText(std::format("{}", id).c_str(), position.x + 20.0f, position.y + 20.0f, 10, WHITE);
}
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;});
std::map<std::string, Vec2Df> noteHandles;
std::map<std::string, Vec2Df> CCHandles;
std::map<std::string, Vec2Df> PCHandles;
std::map<std::string, Vec2Df> pitchBendHandles;
std::map<std::string, Vec2Df> aftertouchHandles;
std::map<std::string, Vec2Df> polyPressureHandles;
std::vector<std::vector<Vec2Df>> handles;
for(auto i : N.midiNoteHandles){
noteHandles.insert(std::make_pair(i->name, i->position));
}
for(auto i : N.midiCCHandles){
CCHandles.insert(std::make_pair(i->name, i->position));
}
for(auto i : N.midiPCHandles){
PCHandles.insert(std::make_pair(i->name, i->position));
}
for(auto i : N.midiPitchBendHandles){
pitchBendHandles.insert(std::make_pair(i->name, i->position));
}
for(auto i : N.midiAftertouchHandles){
pitchBendHandles.insert(std::make_pair(i->name, i->position));
}
for(auto i : N.midiPolyPressureHandles){
polyPressureHandles.insert(std::make_pair(i->name, i->position));
for(auto i : N.midiHandles){
handles.emplace_back();
for(auto n : i.second){
handles.at(i.first).push_back(n->position);
}
}
j = json{
@@ -453,12 +405,7 @@ namespace VISEQ::GRAPH::NODES {
{"midiPitchBend", N.midiPitchBend},
{"midiAftertouch", N.midiAftertouch},
{"midiPolyPressure", N.midiPolyPressure},
{"midiNoteHandle", noteHandles},
{"midiCCHandle", CCHandles},
{"midiPCHandle", PCHandles},
{"midiPitchBendHandle", pitchBendHandles},
{"midiAftertouchHandle", aftertouchHandles},
{"midiPolyPressureHandle", polyPressureHandles},
{"handles", handles},
{"connections",conns}};
}
@@ -477,43 +424,19 @@ namespace VISEQ::GRAPH::NODES {
j.at("midiAftertouch").get_to(N.midiAftertouch);
j.at("midiPolyPressure").get_to(N.midiPolyPressure);
std::map<std::string, Vec2Df> noteHandles;
std::map<std::string, Vec2Df> CCHandles;
std::map<std::string, Vec2Df> PCHandles;
std::map<std::string, Vec2Df> pitchBendHandles;
std::map<std::string, Vec2Df> aftertouchHandles;
std::map<std::string, Vec2Df> polyPressureHandles;
std::vector<std::vector<Vec2Df>> handles;
j.at("midiNoteHandle").get_to(noteHandles);
j.at("midiCCHandle").get_to(CCHandles);
j.at("midiPCHandle").get_to(PCHandles);
j.at("midiPitchBendHandle").get_to(pitchBendHandles);
j.at("midiAftertouchHandle").get_to(aftertouchHandles);
j.at("midiPolyPressureHandle").get_to(polyPressureHandles);
N.midiNoteHandles[0]->position = noteHandles["NOTE"];
N.midiNoteHandles[1]->position = noteHandles["CHANNEL"];
N.midiNoteHandles[2]->position = noteHandles["GATE"];
N.midiNoteHandles[3]->position = noteHandles["VELOCITY"];
N.midiCCHandles[0]->position = CCHandles["CONTROL"];
N.midiCCHandles[1]->position = CCHandles["CHANNEL"];
N.midiCCHandles[2]->position = CCHandles["VALUE"];
j.at("handles").get_to(handles);
N.midiPCHandles[0]->position = PCHandles["PROGRAM"];
N.midiPCHandles[1]->position = PCHandles["CHANNEL"];
N.midiPCHandles[2]->position = PCHandles["VALUE"];
N.midiPitchBendHandles[0]->position = pitchBendHandles["CHANNEL"];
N.midiPitchBendHandles[1]->position = pitchBendHandles["VALUE"];
N.midiAftertouchHandles[0]->position = aftertouchHandles["CHANNEL"];
N.midiAftertouchHandles[1]->position = aftertouchHandles["VALUE"];
N.midiPolyPressureHandles[0]->position = polyPressureHandles["CHANNEL"];
N.midiPolyPressureHandles[1]->position = polyPressureHandles["VALUE"];
N.midiPolyPressureHandles[2]->position = polyPressureHandles["NOTE"];
//j.at("connections").get_to(N.connections);
int i = 0;
for(auto n : handles){
int j = 0;
for(auto nn : n){
N.midiHandles[(Handles)i][j]->position = nn;
j++;
}
i++;
}
}
};
}
+8 -7
View File
@@ -1,5 +1,6 @@
#pragma once
#include "button.h"
#include "datatypes.h"
#include "draggable.h"
#include "graph-item.h"
@@ -141,14 +142,17 @@ namespace VISEQ::GRAPH::NODES{
DrawLineV(pos, pos1, dynGrey);
}
}
//DrawCircleLinesV(parentPosition, (parentPosition + position).dist(parentPosition), dynGrey);
float r = (parentPosition + position).dist(parentPosition);
DrawRing(parentPosition, r - 5, r + 5, 0, 360, 90, ColorAlpha(dyncol, 0.1));
DrawRing(parentPosition, r - 5, r + 5, -90, angle_g - 90, 90, ColorAlpha(dyncol, 0.3));
DrawCircleV(position + parentPosition, radius, dyncol);
VISEQ::HELPER::DrawSuperText(std::format("{}", assignedValueRef), position + parentPosition, position + parentPosition + Vec2Df(50,0), 1, 0, 8, dyncol);
//if(show) VISEQ::HELPER::DrawSuperText(name, minP, maxP, 0.5f, 8.0f, 10.0f, dyncol);
//VISEQ::HELPER::DrawSuperText(std::format("{}", assignedValueRef), position + parentPosition, position + parentPosition + Vec2Df(50,0), 1, 0, 8, dyncol);
/*if(show) {*/
/* std::string text = std::format("{}", assignedValueRef);*/
/* DrawCenteredText(text, parentPosition, 12, ColorBrightness(dyncol, 0.75f));*/
/*}*/
}
}
@@ -156,9 +160,6 @@ namespace VISEQ::GRAPH::NODES{
return false;
}
/*friend void to_json(json& j, const NodeHandle<T>& N){*/
/* j = json{{"position",N.position}};*/
/*}*/
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(NodeHandle, position, name);
};
}