diff --git a/src/app-manager.h b/src/app-manager.h index c22d441..61b9d8c 100644 --- a/src/app-manager.h +++ b/src/app-manager.h @@ -70,14 +70,11 @@ namespace VISEQ::APP { } int highest_id = 0; - Node hid; for(auto n : graph.at("gm").at("nodes")){ 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; + if(n.at("id").get() > highest_id) { + highest_id = n.at("id").get(); } } } diff --git a/src/config-node.h b/src/config-node.h index a3960b6..d7a9f0d 100644 --- a/src/config-node.h +++ b/src/config-node.h @@ -12,7 +12,7 @@ namespace VISEQ::GRAPH::NODES { class ConfigNode : public Node{ public: - ConfigNode() : Node() {std::cout << "ConfigNode Constructor std" << std::endl;} + ConfigNode() {std::cout << "ConfigNode Constructor std" << std::endl;} ConfigNode(Vec2Df position) : Node(position) {} std::shared_ptr getPtr(){ @@ -32,11 +32,13 @@ namespace VISEQ::GRAPH::NODES { float radius = 20.0f; virtual NodeType getNodeType() const override {return nodeType;} - - int GGate(){ - return 0; + + virtual void trigger() override {} + + virtual void setMode(int _mode) override { + mode = _mode; } - + MIDI::MidiNote getNotes(){ return midiNote; } @@ -66,19 +68,8 @@ namespace VISEQ::GRAPH::NODES { mode = state->node_mode; } - /*std::vector> getConnectedMidiNodes(){*/ - /* auto midi_conns = connections | RANGE_FILTER([](EDGES::SPTR_Edge c){ return c->start.lock()->getNodeType() == NodeType::MIDINODE || c->end.lock()->getNodeType() == NodeType::MIDINODE;}) | std::ranges::to>>();*/ - /* std::vector> midi_nodes;*/ - /* for(auto e : midi_conns){*/ - /* if(e->start.lock()->getNodeType() == NodeType::MIDINODE) midi_nodes.push_back(std::dynamic_pointer_cast(e->start.lock()));*/ - /* if(e->end.lock()->getNodeType() == NodeType::MIDINODE) midi_nodes.push_back(std::dynamic_pointer_cast(e->end.lock()));*/ - /* }*/ - /* return midi_nodes;*/ - /*}*/ - void interact(){ float wheel = GetMouseWheelMove(); - /*auto midi_nodes = getConnectedMidiNodes();*/ if(KEYS_DOWN.ctrl && !KEYS_DOWN.alt){ switch(state->node_mode){ diff --git a/src/datatypes.h b/src/datatypes.h index 83599b9..9e0ab7c 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -1,6 +1,5 @@ #pragma once -#include #ifdef _WIN32 #define _USE_MATH_DEFINES #endif @@ -42,10 +41,10 @@ namespace VISEQ::GRAPH{ namespace VISEQ::MIDI{ struct MidiNote{ - int channel = 1; - int note = 48; - int velocity = 60; - int gate = 10; // gate time in milliseconds + int channel = 0; + int note = 0; + int velocity = 0; + int gate = 0; // gate time in milliseconds }; struct MidiCC{ @@ -87,6 +86,11 @@ namespace VISEQ::MIDI{ int number; }; + inline std::ostream& operator<<(std::ostream& os, const MidiNote note){ + os << "note: " << note.note << " channel: " << note.channel << " velocity: " << note.velocity << " gate: " << note.gate; + return os; + } + inline MidiNote operator+(const MidiNote left, const MidiNote right){ MidiNote added; added.note = left.note + right.note; @@ -181,102 +185,90 @@ namespace VISEQ::MIDI{ return added; } - // UNARY + // COMPOUND - inline MidiNote operator+=(const MidiNote left, const MidiNote right){ - MidiNote added; - added.note = left.note + right.note; - added.channel = left.channel + right.channel; - added.gate = left.gate + right.gate; - added.velocity = left.velocity + right.velocity; - return added; + inline MidiNote& operator+=(MidiNote& left, const MidiNote& right){ + left.note += right.note; + left.channel += right.channel; + left.gate += right.gate; + left.velocity += right.velocity; + return left; } - inline MidiCC operator+=(const MidiCC left, const MidiCC right){ - MidiCC added; - added.channel = left.channel + right.channel; - added.control = left.control + right.control; - added.value = left.value+ right.value; - return added; + inline MidiCC& operator+=(MidiCC& left, const MidiCC right){ + left.channel += right.channel; + left.control += right.control; + left.value += right.value; + return left; } - inline MidiPC operator+=(const MidiPC left, const MidiPC right){ - MidiPC added; - added.channel = left.channel + right.channel; - added.program = left.program + right.program; - added.value = left.value+ right.value; - return added; + inline MidiPC& operator+=(MidiPC& left, const MidiPC right){ + left.channel += right.channel; + left.program += right.program; + left.value += right.value; + return left; } - inline MidiPitchBend operator+=(const MidiPitchBend left, const MidiPitchBend right){ - MidiPitchBend added; - added.channel = left.channel + right.channel; - added.value = left.value+ right.value; - return added; + inline MidiPitchBend& operator+=(MidiPitchBend& left, const MidiPitchBend right){ + left.channel += right.channel; + left.value += right.value; + return left; } - inline MidiAftertouch operator+=(const MidiAftertouch left, const MidiAftertouch right){ - MidiAftertouch added; - added.channel = left.channel + right.channel; - added.value = left.value+ right.value; - return added; + inline MidiAftertouch& operator+=(MidiAftertouch& left, const MidiAftertouch right){ + left.channel += right.channel; + left.value += right.value; + return left; } - inline MidiPolyPressure operator+=(const MidiPolyPressure left, const MidiPolyPressure right){ - MidiPolyPressure added; - added.channel = left.channel + right.channel; - added.note = left.note + right.note; - added.value = left.value+ right.value; - return added; + inline MidiPolyPressure& operator+=(MidiPolyPressure& left, const MidiPolyPressure right){ + left.channel += right.channel; + left.note += right.note; + left.value += right.value; + return left; } - inline MidiNote operator-=(const MidiNote left, const MidiNote right){ - MidiNote added; - added.note = left.note - right.note; - added.channel = left.channel - right.channel; - added.gate = left.gate - right.gate; - added.velocity = left.velocity - right.velocity; - return added; + + inline MidiNote& operator-=(MidiNote& left, const MidiNote& right){ + left.note -= right.note; + left.channel -= right.channel; + left.gate -= right.gate; + left.velocity -= right.velocity; + return left; } - inline MidiCC operator-=(const MidiCC left, const MidiCC right){ - MidiCC added; - added.channel = left.channel - right.channel; - added.control = left.control - right.control; - added.value = left.value- right.value; - return added; + inline MidiCC& operator-=(MidiCC& left, const MidiCC right){ + left.channel -= right.channel; + left.control -= right.control; + left.value -= right.value; + return left; } - inline MidiPC operator-=(const MidiPC left, const MidiPC right){ - MidiPC added; - added.channel = left.channel - right.channel; - added.program = left.program - right.program; - added.value = left.value- right.value; - return added; + inline MidiPC& operator-=(MidiPC& left, const MidiPC right){ + left.channel -= right.channel; + left.program -= right.program; + left.value -= right.value; + return left; } - inline MidiPitchBend operator-=(const MidiPitchBend left, const MidiPitchBend right){ - MidiPitchBend added; - added.channel = left.channel - right.channel; - added.value = left.value- right.value; - return added; + inline MidiPitchBend& operator-=(MidiPitchBend& left, const MidiPitchBend right){ + left.channel -= right.channel; + left.value -= right.value; + return left; } - inline MidiAftertouch operator-=(const MidiAftertouch left, const MidiAftertouch right){ - MidiAftertouch added; - added.channel = left.channel - right.channel; - added.value = left.value- right.value; - return added; + inline MidiAftertouch& operator-=(MidiAftertouch& left, const MidiAftertouch right){ + left.channel -= right.channel; + left.value -= right.value; + return left; } - inline MidiPolyPressure operator-=(const MidiPolyPressure left, const MidiPolyPressure right){ - MidiPolyPressure added; - added.channel = left.channel - right.channel; - added.note = left.note - right.note; - added.value = left.value- right.value; - return added; + inline MidiPolyPressure& operator-=(MidiPolyPressure& left, const MidiPolyPressure right){ + left.channel -= right.channel; + left.note -= right.note; + left.value -= right.value; + return left; } - /*Vec2D operator*(const Vec2D left, T scalar){*/ /* return Vec2D(left.x * scalar, left.y * scalar);*/ /*};*/ diff --git a/src/graph-manager.h b/src/graph-manager.h index dc85268..b03751a 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -125,6 +125,8 @@ namespace VISEQ::GRAPH { void copyNodes(VEC_SPTR_Node _nodes, Vec2Df position){ for(auto n: _nodes){ nodes.insert(nodes.end(), std::make_shared(*n)); + /*if(n->getNodeType() == NodeType::MIDINODE) nodes.insert(nodes.end(), std::make_shared(*n));*/ + /*if(n->getNodeType() == NodeType::CONFIGNODE) nodes.insert(nodes.end(), std::make_shared(*n));*/ nodes.back()->setPosition(position + nodes.back()->drag_offset); nodes.back()->selected = false; } @@ -141,8 +143,9 @@ namespace VISEQ::GRAPH { VEC_SPTR_Node getCopiesOfSelectedNodes(){ VEC_SPTR_Node copied_nodes; for(auto n : selected_nodes){ -// if(n->getNodeType() == NodeType::MIDINODE) copied_nodes.insert(copied_nodes.end(), std::make_shared(*n)); copied_nodes.insert(copied_nodes.end(), std::make_shared(*n)); + /*if(n->getNodeType() == NodeType::MIDINODE) copied_nodes.insert(copied_nodes.end(), std::make_shared(*n));*/ + /*if(n->getNodeType() == NodeType::CONFIGNODE) copied_nodes.insert(copied_nodes.end(), std::make_shared(*n));*/ copied_nodes.back()->deselect(); } return copied_nodes; @@ -151,6 +154,8 @@ namespace VISEQ::GRAPH { SPTR_Node copyNode(SPTR_Node n, Vec2Df position){ std::cout << "copy basenode" << std::endl; nodes.insert(nodes.end(), std::make_shared(*n)); + /*if(n->getNodeType() == NodeType::MIDINODE) nodes.insert(nodes.end(), std::make_shared(*n));*/ + /*if(n->getNodeType() == NodeType::CONFIGNODE) nodes.insert(nodes.end(), std::make_shared(*n));*/ nodes.back()->setPosition(position); return nodes.back(); } @@ -165,7 +170,7 @@ namespace VISEQ::GRAPH { void setNodeMode(int mode){ for(auto n: nodes){ - n->SMode(mode); + n->setMode(mode); } } @@ -378,10 +383,10 @@ namespace VISEQ::GRAPH { 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); + midi_gate_v1 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast(c->start.lock())->getNotes().gate, 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); + midi_gate_v2 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast(c->end.lock())->getNotes().gate, 1.f, 4.f); } // Line with small connector circles if(c->end.lock()->getNodeType() == NodeType::MIDINODE && c->start.lock()->getNodeType() == NodeType::MIDINODE){ diff --git a/src/midi-node.h b/src/midi-node.h index 022aff1..eb46cc0 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -34,7 +34,7 @@ namespace VISEQ::GRAPH::NODES { bool enabled; }; - MidiNode() : Node() {std::cout << "MidiNode Constructor std" << std::endl;} + MidiNode() {std::cout << "MidiNode Constructor std" << std::endl;} MidiNode(Vec2Df position) : Node(position) {} NodeType nodeType = NodeType::MIDINODE; @@ -53,10 +53,6 @@ namespace VISEQ::GRAPH::NODES { bool gui_midi_velocity_edit = false; bool gui_midi_gate_edit = false; - bool triggered = false; - - int mode = 0; - float start = 0; float fade = 0; float time = 0; @@ -75,23 +71,18 @@ namespace VISEQ::GRAPH::NODES { void trigger() override { triggered = true; start = GetTime(); - fade = midiNote.gate; + fade = getNotes().gate; } - void SMode(int _mode) override{ + void setMode(int _mode) override { mode = _mode; } - int GGate(){ - return midiNote.gate; - } - MIDI::MidiNote getNotes() const { MIDI::MidiNote cNote; for(auto cn : getConnectedConfigNodes()){ cNote += cn.lock()->getNotes(); } - std::cout << cNote.note << std::endl; return midiNote + cNote; } @@ -142,6 +133,7 @@ namespace VISEQ::GRAPH::NODES { if(e->start.lock()->getNodeType() == NodeType::CONFIGNODE) config_nodes.push_back(std::dynamic_pointer_cast(e->start.lock())); if(e->end.lock()->getNodeType() == NodeType::CONFIGNODE) config_nodes.push_back(std::dynamic_pointer_cast(e->end.lock())); } + /*std::cout << "id: " << id << " n cn: " << config_nodes.size() << std::endl;*/ return config_nodes; } @@ -150,14 +142,6 @@ namespace VISEQ::GRAPH::NODES { mode = state->node_mode; } - int getMidiNote(){ - int mod_notes = 0; - for(auto cn : getConnectedConfigNodes()){ - mod_notes += cn.lock()->midiNote.note; - } - return midiNote.note + mod_notes; - } - void modMidiNote(int incr){ midiNote.note += incr; if(midiNote.note < 0 ) midiNote.note = VISEQ::MIDI::Notes.size()-1; @@ -223,7 +207,7 @@ namespace VISEQ::GRAPH::NODES { last = time; time = GetTime(); - if(time - start >= (float)midiNote.gate / 1000.0f){ + if(time - start >= (float)getNotes().gate / 1000.0f){ triggered = false; fade = 0; } else { @@ -231,10 +215,10 @@ namespace VISEQ::GRAPH::NODES { } 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}); + 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 midi_gate_map = round((255.f / midiNote.gate) * fade); + float midi_gate_map = round((255.f / getNotes().gate) * fade); Color gate_color = VS_COLOR_GREEN; diff --git a/src/node.h b/src/node.h index ea0952f..83c3b0f 100644 --- a/src/node.h +++ b/src/node.h @@ -37,6 +37,12 @@ namespace VISEQ::GRAPH::NODES { float radius = 15.0f; bool config = false; + bool triggered = false; + int mode = 0; + + virtual void trigger() {} + virtual void setMode(int _mode) {mode = _mode;} + std::shared_ptr getPtr(){ return shared_from_this(); } @@ -54,11 +60,7 @@ namespace VISEQ::GRAPH::NODES { } virtual NodeType getNodeType() const {return nodeType;} - - virtual void SMode(int mode) {}; - virtual void trigger() {}; - void deselect() override { selected = false; } diff --git a/src/signal.h b/src/signal.h index 5582a97..35ed1f6 100644 --- a/src/signal.h +++ b/src/signal.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include "moveable.h" #include "node.h" diff --git a/src/state-io.h b/src/state-io.h index 4106134..c4dbaeb 100644 --- a/src/state-io.h +++ b/src/state-io.h @@ -113,7 +113,12 @@ namespace VISEQ::GRAPH::NODES { inline void from_json(const json& j, std::shared_ptr& N){ std::cout << "SPTR_Node" << std::endl; - N.reset(new Node(j.get())); + if(N->getNodeType() == NodeType::MIDINODE){ + N.reset(new MidiNode(j.get())); + } + if(N->getNodeType() == NodeType::CONFIGNODE){ + N.reset(new ConfigNode(j.get())); + } } }