Config nodes do what they should do now. UX is still off, modifier keys do different things on MidiNodes and ConfigNodes.

This commit is contained in:
Sebastian
2024-12-08 14:21:46 +01:00
parent 558829f619
commit 3b08037f92
8 changed files with 106 additions and 131 deletions
+2 -5
View File
@@ -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<Node>();
if(mn.id > highest_id) {
highest_id = mn.id;
hid = mn;
if(n.at("id").get<int>() > highest_id) {
highest_id = n.at("id").get<int>();
}
}
}
+7 -16
View File
@@ -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<ConfigNode> 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<std::weak_ptr<MidiNode>> 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<std::shared_ptr<EDGES::Edge>>>();*/
/* std::vector<std::weak_ptr<MidiNode>> midi_nodes;*/
/* for(auto e : midi_conns){*/
/* if(e->start.lock()->getNodeType() == NodeType::MIDINODE) midi_nodes.push_back(std::dynamic_pointer_cast<MidiNode>(e->start.lock()));*/
/* if(e->end.lock()->getNodeType() == NodeType::MIDINODE) midi_nodes.push_back(std::dynamic_pointer_cast<MidiNode>(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){
+69 -77
View File
@@ -1,6 +1,5 @@
#pragma once
#include <filesystem>
#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<T> operator*(const Vec2D<T> left, T scalar){*/
/* return Vec2D<T>(left.x * scalar, left.y * scalar);*/
/*};*/
+9 -4
View File
@@ -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<Node>(*n));
/*if(n->getNodeType() == NodeType::MIDINODE) nodes.insert(nodes.end(), std::make_shared<MidiNode>(*n));*/
/*if(n->getNodeType() == NodeType::CONFIGNODE) nodes.insert(nodes.end(), std::make_shared<ConfigNode>(*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<MidiNode>(*n));
copied_nodes.insert(copied_nodes.end(), std::make_shared<Node>(*n));
/*if(n->getNodeType() == NodeType::MIDINODE) copied_nodes.insert(copied_nodes.end(), std::make_shared<MidiNode>(*n));*/
/*if(n->getNodeType() == NodeType::CONFIGNODE) copied_nodes.insert(copied_nodes.end(), std::make_shared<ConfigNode>(*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<Node>(*n));
/*if(n->getNodeType() == NodeType::MIDINODE) nodes.insert(nodes.end(), std::make_shared<MidiNode>(*n));*/
/*if(n->getNodeType() == NodeType::CONFIGNODE) nodes.insert(nodes.end(), std::make_shared<ConfigNode>(*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<MidiNode>(c->start.lock())->GGate(), 1.f, 4.f);
midi_gate_v1 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast<MidiNode>(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<MidiNode>(c->end.lock())->GGate(), 1.f, 4.f);
midi_gate_v2 = Clamp((4.f / 1000.f) * std::dynamic_pointer_cast<MidiNode>(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){
+7 -23
View File
@@ -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<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;
}
@@ -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;
+6 -4
View File
@@ -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<Node> 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;
}
-1
View File
@@ -1,7 +1,6 @@
#pragma once
#include <raylib.h>
#include <string>
#include "moveable.h"
#include "node.h"
+6 -1
View File
@@ -113,7 +113,12 @@ namespace VISEQ::GRAPH::NODES {
inline void from_json(const json& j, std::shared_ptr<Node>& N){
std::cout << "SPTR_Node" << std::endl;
N.reset(new Node(j.get<Node>()));
if(N->getNodeType() == NodeType::MIDINODE){
N.reset(new MidiNode(j.get<MidiNode>()));
}
if(N->getNodeType() == NodeType::CONFIGNODE){
N.reset(new ConfigNode(j.get<ConfigNode>()));
}
}
}