diff --git a/src/app-manager.h b/src/app-manager.h index 052c5e1..99ab48c 100644 --- a/src/app-manager.h +++ b/src/app-manager.h @@ -63,16 +63,25 @@ namespace VISEQ::APP { json graph = json::parse(f); for(auto n : graph.at("gm").at("nodes")){ - gm->addNode(n.template get>()); + std::cout << "object? " << n.is_object() << std::endl; + if(n.is_object()){ + std::cout << "nodeType = " << n.at("nodeType").get() << std::endl; + + if(n.at("nodeType").get() == NodeType::MIDINODE) gm->addNode(n.template get>()); + if(n.at("nodeType").get() == NodeType::CONFIGNODE) gm->addNode(n.template get>()); + } } int highest_id = 0; Node hid; for(auto n : graph.at("gm").at("nodes")){ - MidiNode mn = n.template get(); - if(mn.id > highest_id) { - highest_id = mn.id; - hid = mn; + std::cout << n << std::endl; + if(n.is_object()){ + Node mn = n.template get(); + if(mn.id > highest_id) { + highest_id = mn.id; + hid = mn; + } } } @@ -89,14 +98,10 @@ namespace VISEQ::APP { VEC_WPTR_Node start = gm->getNodesByID(start_id); VEC_WPTR_Node end = gm->getNodesByID(end_id); -// VEC_SPTR_Node start = gm->nodes | RANGE_FILTER([start_id](SPTR_Node n){return n->id == start_id;}) | std::ranges::to(); -// VEC_SPTR_Node end = gm->nodes | RANGE_FILTER([end_id](SPTR_Node n){return n->id == end_id;}) | std::ranges::to(); - if(!start.empty() && !end.empty()) { std::cout << std::format("connection {} to {}", start_id, end_id) << std::endl; gm->addConnection(start.front(), end.front()); } - } gm->lastEdge().lock()->newId(highest_id); diff --git a/src/config-node.h b/src/config-node.h index f6b5617..f312a77 100644 --- a/src/config-node.h +++ b/src/config-node.h @@ -9,6 +9,13 @@ namespace VISEQ::GRAPH::NODES { class ConfigNode : public Node{ public: + ConfigNode() : Node() {std::cout << "ConfigNode Constructor std" << std::endl;} + ConfigNode(Vec2Df position) : Node(position) {} + + std::shared_ptr getPtr(){ + return std::static_pointer_cast(shared_from_this()); + } + NodeType nodeType = NodeType::CONFIGNODE; MIDI::MidiNote midiNote; @@ -18,55 +25,110 @@ namespace VISEQ::GRAPH::NODES { MIDI::MidiPC midiPC; int mode = 0; + float radius = 20.0f; virtual NodeType getNodeType() const override {return nodeType;} + + int GGate(){ + return 0; + } + void update() override { + Node::update(); + mode = state->node_mode; + } + + void interact(){ + float wheel = GetMouseWheelMove(); + + if(KEYS_DOWN.ctrl && !KEYS_DOWN.alt){ + switch(state->node_mode){ + case 0:{ + midiNote.note += wheel; + break;} + case 1:{ + midiCC.value += wheel; + break;} + case 2:{ + midiPitchBend.value += wheel; + break;} + }; + if(midiNote.note < 0 ) midiNote.note = VISEQ::MIDI::Notes.size()-1; + if(midiNote.note >= (int)VISEQ::MIDI::Notes.size()) midiNote.note = 0; + + if(midiCC.value < 0 ) midiCC.value = 127; + if(midiCC.value > 127 ) midiCC.value = 0; + + if(midiPitchBend.value < 0 ) midiPitchBend.value = 0; + if(midiPitchBend.value > 16383 ) midiPitchBend.value = 16383; + + } else if(KEYS_DOWN.shift && !KEYS_DOWN.alt) { + } else if(KEYS_DOWN.alt) { + switch(state->node_mode){ + case 0:{ + midiNote.channel += wheel; + if(midiNote.channel < 0 ) midiNote.channel = 0; + if(midiNote.channel > 15) midiNote.channel = 15; + break;} + case 1:{ + midiCC.channel += wheel; + if(midiCC.channel < 0 ) midiCC.channel = 0; + if(midiCC.channel > 15 ) midiCC.channel = 15; + break;} + case 2:{ + midiPitchBend.channel += wheel; + if(midiPitchBend.channel < 0 ) midiPitchBend.channel = 0; + if(midiPitchBend.channel > 15 ) midiPitchBend.channel = 15; + break;} + }; + } + } + void draw(Vec2Df mouse, Camera2D cam) override { - 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) * midiNote.velocity - 90.0f, 24, (Color){158, 134, 200, 255}); - DrawCircleLinesV(position, radius + 4, (Color){100, 100, 100, 255}); - - float fade = 0; + Node::draw(); + if(hovering() || selected) interact(); - float midi_gate_map = round((255.f / midiNote.gate) * fade); + DrawRing(position, radius, radius+4, 0, 360, 24, (Color){60, 60, 60, 255}); + DrawCircleLinesV(position, radius + 4, (Color){100, 100, 100, 255}); Color gate_color = VS_COLOR_GREEN; switch(mode){ case 0:{ - gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){180, 210, 115, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE); - break;} + gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){180, 210, 115 + 70, (unsigned char)Clamp(255, 0, 255)}, WHITE); + break;} case 1:{ - gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){229, 181, 103, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE); - break;} + gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){229, 181, 103 + 70, (unsigned char)Clamp(255, 0, 255)}, WHITE); + break;} case 2:{ - gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){232, 125, 62, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE); - break;} + gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){232, 125, 62 + 70, (unsigned char)Clamp(255, 0, 255)}, WHITE); + break;} } - if(!picked_up && !selected && !in_rect && !hovering()) DrawCircle(position.x, position.y, radius, gate_color); - if(selected || picked_up || in_rect || hovering()) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255}); + if(!picked_up && !selected && !in_selection_rect && !hovering()) DrawCircle(position.x, position.y, radius, gate_color); + 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}); - - if(IsKeyDown(KEY_LEFT_ALT)){ + + if(KEYS_DOWN.alt){ float value = 0; int offset_gate = 0; switch(mode){ case 0: - value = (float)midiNote.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 ); + value = (float)midiNote.channel; + 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 1: - value = (float)midiCC.value; + value = (float)midiCC.channel; 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)midiPitchBend.channel; 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; @@ -74,28 +136,20 @@ 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 ); - break;} + 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 ); + break;} case 1:{ - int offset = MeasureText(std::format("{}", midiCC.value).c_str(), 12); - DrawText(std::format("{}", midiCC.value).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE ); - break;} + int offset = MeasureText(std::format("{}", midiCC.value).c_str(), 12); + DrawText(std::format("{}", midiCC.value).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 ); - break;} + 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 ); + break;} } } - Vec2Df connector = position - ((position - mouse)).norm() * (radius + 30); - float opacity = 150.0f - Clamp(position.dist(mouse), 0.0f, 150.0f); - - if(hover_connect){ - DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255}); - } else { - DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity}); - } 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); } diff --git a/src/connector.h b/src/connector.h index 44dda45..f9673b7 100644 --- a/src/connector.h +++ b/src/connector.h @@ -69,11 +69,7 @@ namespace VISEQ::GRAPH { void draw() override { BASE::Connectable::draw(); float opacity = 150.0f - Clamp(position.dist(SCREEN_MOUSE), 0.0f, 150.0f); - - if(!partner.expired()){ - DrawLineV(position, partner.lock()->position, VS_COLOR_RED); - } - + if(hovering()){ DrawCircle(position.x, position.y, 8.0f, (Color){108, 203, 237, 255}); } else { diff --git a/src/graph-manager.h b/src/graph-manager.h index 0ec83f7..c088abb 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -1,6 +1,7 @@ #pragma once +#include "config-node.h" #include "datatypes.h" #include "state.h" #include "vmath.h" @@ -20,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +66,11 @@ namespace VISEQ::GRAPH { nodes.back()->update(); } + void createConfigNode(Vec2Df position){ + nodes.emplace_back(std::make_shared(position)); + nodes.back()->update(); + } + void setMidiPortForAll(int number, bool _state){ for(auto n : nodes){ if(n->getNodeType() == NodeType::MIDINODE) std::dynamic_pointer_cast(n)->setMidiPort(number, _state); @@ -71,6 +78,7 @@ namespace VISEQ::GRAPH { } void addNode(SPTR_Node node){ + std::cout << "added node " << node->id << std::endl; nodes.insert(nodes.end(), node); node->update(); } @@ -169,6 +177,10 @@ namespace VISEQ::GRAPH { return nodes.front(); } + WPTR_Node getLastNode(){ + return nodes.back(); + } + VEC_WPTR_Node getMidiNodes(){ return nodes | RANGE_FILTER([](VISEQ::GRAPH::NODES::SPTR_Node n){return n->getNodeType() == NodeType::MIDINODE;}) | std::ranges::to(); } @@ -345,35 +357,6 @@ namespace VISEQ::GRAPH { Vec2Df v1_position = c->start.lock()->position - ((c->start.lock()->position - c->end.lock()->position)).norm() * (c->start.lock()->radius + c->connector_offset); Vec2Df v2_position = c->end.lock()->position - ((c->end.lock()->position - c->start.lock()->position)).norm() * (c->end.lock()->radius + c->connector_offset); float v1_v2_distance = v1_position.dist(&v2_position); - - float midi_gate_v1 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast(c->start.lock())->GGate(), 1.f, 4.f); - float midi_gate_v2 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast(c->end.lock())->GGate(), 1.f, 4.f); - // Line with small connector circles - - Color col = {229, 181, 103, 255}; - if(c->GActive()) col = {108, 153, 187, 255}; - DrawLine(v1_position.x, v1_position.y, v2_position.x, v2_position.y, col); - { - float d = c->start.lock()->position.dist(c->end.lock()->position); - std::string frac = MIDI::Fractions.at(std::clamp(round(d/60) - 1, 0, 31)); - Vector2 text_length = MeasureTextEx(GetFontDefault(), std::format("{:.1f}",d).c_str(), 10.0f, 2.0f); - Vector2 text_length_frac = MeasureTextEx(GetFontDefault(), frac.c_str(), 10.0f, 2.0f); - - Vec2Df middle_handle = c->start.lock()->position + (c->end.lock()->position - c->start.lock()->position) * ((d - text_length.x)*0.5f)/d; - Vec2Df middle_handle_frac = c->start.lock()->position + (c->end.lock()->position - c->start.lock()->position) * ((d - text_length_frac.x)*0.5f)/d; - Vec2Df text_position = middle_handle + (c->start.lock()->position - c->end.lock()->position).norm().orth() * 12.0f; - Vec2Df text_position_frac = middle_handle_frac - (c->start.lock()->position - c->end.lock()->position).norm().orth() * 4.0f; - - float rotation = Vector2Angle((Vector2){1,0}, (c->end.lock()->position - c->start.lock()->position)) * RAD2DEG; - DrawTextPro(GetFontDefault(), std::format("{:.1f}",d).c_str(), text_position, (Vector2){0,0}, rotation, 10.0f, 2.0f, VS_COLOR_PINK); - if( (int)d % 60 == 0) DrawTextPro(GetFontDefault(), frac.c_str(), text_position_frac, (Vector2){0,0}, rotation, 10.0f, 2.0f, VS_COLOR_PINK); - } - if(midi_gate_v1 == 4.0f) col = VS_COLOR_RED; - DrawCircle(v1_position.x, v1_position.y, midi_gate_v1, col); - - col = {229, 181, 103, 255}; - if(midi_gate_v2 == 4.0f) col = VS_COLOR_RED; - DrawCircle(v2_position.x, v2_position.y, midi_gate_v2, col); if(v1_v2_distance < 100) c->switches_offset = v1_v2_distance/2.3f; Vec2Df from_to_handle = c->start.lock()->position - ((c->start.lock()->position - c->end.lock()->position)).norm() * (c->start.lock()->radius + c->switches_offset); @@ -382,32 +365,74 @@ namespace VISEQ::GRAPH { Vec2Df middle_handle_2 = c->end.lock()->position - ((c->end.lock()->position - c->start.lock()->position))*0.6f; Vec2Df flip_handle = middle_handle + (v1_position - v2_position).norm().orth() * (v1_v2_distance < 120.0f ? Clamp((120.0f - v1_v2_distance)*0.2, 0.f, 20.f) : 1.0f); Vec2Df flip_handle_2 = middle_handle_2 + (v1_position - v2_position).norm().orth() * (v1_v2_distance < 120.0f ? Clamp((120.0f - v1_v2_distance)*-0.2, -20.f, 0.f) : 1.0f); - + // Dynamic opacity by distance to mouse unsigned char opacity = 150.0f - Clamp(middle_handle.dist(mouse_pos), 0.0f, 150.0f); unsigned char opacity_from = 250.0f - Clamp(from_to_handle.dist(mouse_pos), 0.0f, 220.0f); unsigned char opacity_to = 250.0f - Clamp(to_from_handle.dist(mouse_pos), 0.0f, 220.0f); - - if(!c->start.lock()->picked_up && !c->end.lock()->picked_up){ - // On/Off switches on both sides - if(ViButton(mouse_pos, from_to_handle.x, from_to_handle.y, 8.0f, c->pass_forward ? (Color){120, 210, 115, opacity_from} : (Color){232, 50, 32, opacity_from} )) c->pass_forward = !c->pass_forward; - if(ViButton(mouse_pos, to_from_handle.x, to_from_handle.y, 8.0f, c->pass_backward ? (Color){120, 210, 115, opacity_to} : (Color){232, 50, 32, opacity_to} )) c->pass_backward = !c->pass_backward; - if(!c->pass_forward){ - Vec2Df block_point1 = (v1_position - v2_position).norm().orth()*4.0f + from_to_handle; - Vec2Df block_point2 = (v1_position - v2_position).norm().orth()*-4.0f + from_to_handle; - DrawLineEx(block_point1, block_point2, 2.0f, (Color){232,232,232,opacity_from}); - } - - if(!c->pass_backward){ - Vec2Df block_point1 = (v1_position - v2_position).norm().orth()*4.0f + to_from_handle; - Vec2Df block_point2 = (v1_position - v2_position).norm().orth()*-4.0f + to_from_handle; - DrawLineEx(block_point1, block_point2, 2.0f, (Color){232,232,232,opacity_to}); - } - - if(ViButton(mouse_pos, flip_handle.x, flip_handle.y, 8.0f, (Color){232, 50, 32, opacity} )) removeEdge(c); - if(ViButton(mouse_pos, flip_handle_2.x, flip_handle_2.y, 8.0f, (Color){232, 125, 62, opacity} )) splitEdge(c); + float midi_gate_v1 = 0.0f; + float midi_gate_v2 = 0.0f; + + if(c->start.lock()->getNodeType() == NodeType::MIDINODE){ + midi_gate_v1 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast(c->start.lock())->GGate(), 1.f, 4.f); } + if(c->end.lock()->getNodeType() == NodeType::MIDINODE){ + midi_gate_v2 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast(c->end.lock())->GGate(), 1.f, 4.f); + } + // Line with small connector circles + if(c->end.lock()->getNodeType() == NodeType::MIDINODE && c->start.lock()->getNodeType() == NodeType::MIDINODE){ + + Color col = {229, 181, 103, 255}; + if(c->GActive()) col = {108, 153, 187, 255}; + DrawLine(v1_position.x, v1_position.y, v2_position.x, v2_position.y, col); + { + float d = c->start.lock()->position.dist(c->end.lock()->position); + std::string frac = MIDI::Fractions.at(std::clamp(round(d/60) - 1, 0, 31)); + Vector2 text_length = MeasureTextEx(GetFontDefault(), std::format("{:.1f}",d).c_str(), 10.0f, 2.0f); + Vector2 text_length_frac = MeasureTextEx(GetFontDefault(), frac.c_str(), 10.0f, 2.0f); + + Vec2Df middle_handle = c->start.lock()->position + (c->end.lock()->position - c->start.lock()->position) * ((d - text_length.x)*0.5f)/d; + Vec2Df middle_handle_frac = c->start.lock()->position + (c->end.lock()->position - c->start.lock()->position) * ((d - text_length_frac.x)*0.5f)/d; + Vec2Df text_position = middle_handle + (c->start.lock()->position - c->end.lock()->position).norm().orth() * 12.0f; + Vec2Df text_position_frac = middle_handle_frac - (c->start.lock()->position - c->end.lock()->position).norm().orth() * 4.0f; + + float rotation = Vector2Angle((Vector2){1,0}, (c->end.lock()->position - c->start.lock()->position)) * RAD2DEG; + DrawTextPro(GetFontDefault(), std::format("{:.1f}",d).c_str(), text_position, (Vector2){0,0}, rotation, 10.0f, 2.0f, VS_COLOR_PINK); + if( (int)d % 60 == 0) DrawTextPro(GetFontDefault(), frac.c_str(), text_position_frac, (Vector2){0,0}, rotation, 10.0f, 2.0f, VS_COLOR_PINK); + } + if(midi_gate_v1 == 4.0f) col = VS_COLOR_RED; + DrawCircle(v1_position.x, v1_position.y, midi_gate_v1, col); + + col = {229, 181, 103, 255}; + if(midi_gate_v2 == 4.0f) col = VS_COLOR_RED; + DrawCircle(v2_position.x, v2_position.y, midi_gate_v2, col); + + if(!c->start.lock()->picked_up && !c->end.lock()->picked_up){ + // On/Off switches on both sides + if(ViButton(mouse_pos, from_to_handle.x, from_to_handle.y, 8.0f, c->pass_forward ? (Color){120, 210, 115, opacity_from} : (Color){232, 50, 32, opacity_from} )) c->pass_forward = !c->pass_forward; + if(ViButton(mouse_pos, to_from_handle.x, to_from_handle.y, 8.0f, c->pass_backward ? (Color){120, 210, 115, opacity_to} : (Color){232, 50, 32, opacity_to} )) c->pass_backward = !c->pass_backward; + + if(!c->pass_forward){ + Vec2Df block_point1 = (v1_position - v2_position).norm().orth()*4.0f + from_to_handle; + Vec2Df block_point2 = (v1_position - v2_position).norm().orth()*-4.0f + from_to_handle; + DrawLineEx(block_point1, block_point2, 2.0f, (Color){232,232,232,opacity_from}); + } + + if(!c->pass_backward){ + Vec2Df block_point1 = (v1_position - v2_position).norm().orth()*4.0f + to_from_handle; + Vec2Df block_point2 = (v1_position - v2_position).norm().orth()*-4.0f + to_from_handle; + DrawLineEx(block_point1, block_point2, 2.0f, (Color){232,232,232,opacity_to}); + } + + if(ViButton(mouse_pos, flip_handle_2.x, flip_handle_2.y, 8.0f, (Color){232, 125, 62, opacity} )) splitEdge(c); + } + } + if(c->start.lock()->getNodeType() == NodeType::CONFIGNODE || c->end.lock()->getNodeType() == NodeType::CONFIGNODE){ + DrawLine(v1_position.x, v1_position.y, v2_position.x, v2_position.y, VS_COLOR_BLUE); + } + + if(ViButton(mouse_pos, flip_handle.x, flip_handle.y, 8.0f, (Color){232, 50, 32, opacity} )) removeEdge(c); } } diff --git a/src/interaction-manager.h b/src/interaction-manager.h index 8632a55..57a5062 100644 --- a/src/interaction-manager.h +++ b/src/interaction-manager.h @@ -197,14 +197,23 @@ namespace VISEQ::INTERACTION{ break; } } + + auto connector = std::dynamic_pointer_cast(e.item); if(found && partner != e){ - auto connector = std::dynamic_pointer_cast(e.item); auto connector_to = std::dynamic_pointer_cast(partner.item); connector->partner = connector_to; connector_to->partner = connector; gm->addConnection(std::dynamic_pointer_cast(connector->parent.lock()), std::dynamic_pointer_cast(connector_to->parent.lock())); - connect_once = true; + } else if (partner != e){ + if(KEYS_DOWN.alt){ + gm->createConfigNode(SCREEN_MOUSE); + } else { + gm->createMidiNode(SCREEN_MOUSE); + } + gm->addConnection(std::dynamic_pointer_cast(connector->parent.lock()), gm->getLastNode()); } + connect_once = true; + break; } } diff --git a/src/midi-node.h b/src/midi-node.h index 3d78ca2..d238039 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -86,6 +86,7 @@ namespace VISEQ::GRAPH::NODES { int GGate(){ return midi_gate; } + void update() override { Node::update(); mode = state->node_mode; diff --git a/src/state-io.h b/src/state-io.h index dc4a46b..017b297 100644 --- a/src/state-io.h +++ b/src/state-io.h @@ -1,5 +1,6 @@ #pragma once +#include "config-node.h" #include "midi-node.h" #include "graph-item.h" #include "node.h" @@ -124,7 +125,51 @@ namespace VISEQ::GRAPH::NODES { j = json{{"port_id", MO.i}, {"enabled", MO.enabled}, {"name", MO.name}}; } + /* ----------------- CONFIG NODE -----------------*/ + inline void to_json(json& j, const ConfigNode& N){ + std::vector 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",N.midiNote.note}, + {"midi_cc_channel",N.midiCC.channel}, + {"midi_cc",N.midiCC.value}, + {"midi_pitch_bend_channel",N.midiPitchBend.channel}, + {"midi_pitch_bend",N.midiPitchBend.value}, + {"connections",conns}}; + } + + inline void from_json(const json& j, ConfigNode& N){ + std::cout << "ConfigNode" << std::endl; + + j.at("id").get_to(N.id); + j.at("position").get_to(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").get_to(N.midiNote.note); + j.at("midi_cc_channel").get_to(N.midiCC.channel); + j.at("midi_cc").get_to(N.midiCC.value); + j.at("midi_pitch_bend_channel").get_to(N.midiPitchBend.channel); + j.at("midi_pitch_bend").get_to(N.midiPitchBend.value); + + //j.at("connections").get_to(N.connections); + } + + inline void to_json(json& j, const std::shared_ptr& N){ + j = *N; + } + + inline void from_json(const json& j, std::shared_ptr& N){ + N.reset(new ConfigNode(j.get())); + } + /* ------------------- NODE ---------------------- */ @@ -132,6 +177,9 @@ namespace VISEQ::GRAPH::NODES { if(N.getNodeType() == NodeType::MIDINODE){ j = dynamic_cast(N); } + if(N.getNodeType() == NodeType::CONFIGNODE){ + j = dynamic_cast(N); + } } inline void from_json(const json& j, Node& N){ @@ -140,6 +188,10 @@ namespace VISEQ::GRAPH::NODES { std::cout << j.at("nodeType") << std::endl; N = j.template get(); } + if(j.at("nodeType") == NodeType::CONFIGNODE){ + std::cout << j.at("nodeType") << std::endl; + N = j.template get(); + } } inline void to_json(json& j, const SPTR_Node& N){ diff --git a/src/ui.h b/src/ui.h index 992e0ba..7fec535 100644 --- a/src/ui.h +++ b/src/ui.h @@ -32,7 +32,7 @@ namespace VISEQ::APP::UI{ void drawSideBar(){ - GuiPanel((Rectangle){-1,-30,280,(float)state->settings.height + 31}, ""); + GuiPanel((Rectangle){-1,-30,380,(float)state->settings.height + 31}, ""); const int s_controls = 25; //GuiSetStyle(BUTTON, STATE_FOCUSED, 0xFF0000FF); if(GuiButton((Rectangle){20, (float)s_controls, 80, 30}, "PLAY")) sm->play ? sm->pause() : sm->start();