Config nodes not working yet, but everything is prepared.

This commit is contained in:
Sebastian
2024-12-08 02:25:57 +01:00
parent d9c97be326
commit 558829f619
7 changed files with 177 additions and 159 deletions
+84 -24
View File
@@ -9,9 +9,15 @@
#define RADIUS 14.0f
namespace VISEQ::APP::UI{
class AppUI;
}
namespace VISEQ::GRAPH::NODES {
class MidiNode : public Node{
friend class APP::UI::AppUI;
private:
MIDI::MidiNote midiNote;
MIDI::MidiCC midiCC;
@@ -80,55 +86,56 @@ namespace VISEQ::GRAPH::NODES {
return midiNote.gate;
}
MIDI::MidiNote getNotes(){
MIDI::MidiNote getNotes() const {
MIDI::MidiNote cNote;
for(auto cn : getConnectedConfigNodes()){
cNote += cn.lock()->getNotes();
}
return cNote;
std::cout << cNote.note << std::endl;
return midiNote + cNote;
}
MIDI::MidiCC getCC(){
MIDI::MidiCC getCC() const {
MIDI::MidiCC cCC;
for(auto cn : getConnectedConfigNodes()){
cCC += cn.lock()->getCC();
}
return cCC;
return midiCC + cCC;
}
MIDI::MidiPC getPC(){
MIDI::MidiPC getPC() const {
MIDI::MidiPC cPC;
for(auto cn : getConnectedConfigNodes()){
cPC += cn.lock()->getPC();
}
return cPC;
return midiPC + cPC;
}
MIDI::MidiPitchBend getPitchBend(){
MIDI::MidiPitchBend getPitchBend() const {
MIDI::MidiPitchBend cPitchBend;
for(auto cn : getConnectedConfigNodes()){
cPitchBend += cn.lock()->getPitchBend();
}
return cPitchBend;
return midiPitchBend + cPitchBend;
}
MIDI::MidiAftertouch getAftertouch(){
MIDI::MidiAftertouch getAftertouch() const {
MIDI::MidiAftertouch cAftertouch;
for(auto cn : getConnectedConfigNodes()){
cAftertouch += cn.lock()->getAftertouch();
}
return cAftertouch;
return midiAftertouch + cAftertouch;
}
MIDI::MidiPolyPressure getPolyPressure(){
MIDI::MidiPolyPressure getPolyPressure() const {
MIDI::MidiPolyPressure cPolyPressure;
for(auto cn : getConnectedConfigNodes()){
cPolyPressure += cn.lock()->getPolyPressure();
}
return cPolyPressure;
return midiPolyPressure + cPolyPressure;
}
std::vector<std::weak_ptr<ConfigNode>> getConnectedConfigNodes(){
std::vector<std::weak_ptr<ConfigNode>> 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){
@@ -140,8 +147,7 @@ namespace VISEQ::GRAPH::NODES {
void update() override {
Node::update();
mode = state->node_mode;
mode = state->node_mode;
}
int getMidiNote(){
@@ -257,17 +263,17 @@ namespace VISEQ::GRAPH::NODES {
int offset_gate = 0;
switch(mode){
case 0:
value = (float)midiNote.gate/1000.0f;
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)midiCC.value;
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)midiPitchBend.value;
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;
@@ -275,16 +281,16 @@ namespace VISEQ::GRAPH::NODES {
} else {
switch(mode){
case 0:{
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 );
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("{}", midiCC.control).c_str(), 12);
DrawText(std::format("{}", midiCC.control).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
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("{}", midiPitchBend.value).c_str(), 12);
DrawText(std::format("{}", midiPitchBend.value).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE );
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;}
}
}
@@ -292,5 +298,59 @@ namespace VISEQ::GRAPH::NODES {
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;});
j = json{
{"id", N.id},
{"position", N.position},
{"distributionMode", N.distributionMode},
{"nodeType", N.nodeType},
{"midi_note_channel",N.midiNote.channel},
{"midi_note_note",N.midiNote.note},
{"midi_note_velocity",N.midiNote.velocity},
{"midi_note_gate",N.midiNote.gate},
{"midi_cc_channel",N.midiCC.channel},
{"midi_cc_control",N.midiCC.control},
{"midi_cc_value",N.midiCC.value},
{"midi_pc_channel",N.midiPC.channel},
{"midi_pc_program",N.midiPC.program},
{"midi_pc_value",N.midiPC.value},
{"midi_pitch_bend_channel",N.midiPitchBend.channel},
{"midi_pitch_bend_value",N.midiPitchBend.value},
{"midi_aftertouch_channel",N.midiAftertouch.channel},
{"midi_aftertouch_value",N.midiAftertouch.value},
{"midi_polypressure_channel",N.midiPolyPressure.channel},
{"midi_polypressure_value",N.midiPolyPressure.value},
{"connections",conns}};
}
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);
j.at("midi_note_channel").get_to(N.midiNote.channel);
j.at("midi_note_note").get_to(N.midiNote.note);
j.at("midi_note_velocity").get_to(N.midiNote.velocity);
j.at("midi_note_gate").get_to(N.midiNote.gate);
j.at("midi_cc_channel").get_to(N.midiCC.channel);
j.at("midi_cc_control").get_to(N.midiCC.control);
j.at("midi_cc_value").get_to(N.midiCC.value);
j.at("midi_pc_channel").get_to(N.midiPC.channel);
j.at("midi_pc_program").get_to(N.midiPC.program);
j.at("midi_pc_value").get_to(N.midiPC.value);
j.at("midi_pitch_bend_channel").get_to(N.midiPitchBend.channel);
j.at("midi_pitch_bend_value").get_to(N.midiPitchBend.value);
j.at("midi_aftertouch_channel").get_to(N.midiAftertouch.channel);
j.at("midi_aftertouch_value").get_to(N.midiAftertouch.value);
j.at("midi_polypressure_channel").get_to(N.midiPolyPressure.channel);
j.at("midi_polypressure_value").get_to(N.midiPolyPressure.value);
//j.at("connections").get_to(N.connections);
}
};
}