diff --git a/src/midi-node.h b/src/midi-node.h index e28e6af7..7a6c40b 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -69,28 +69,34 @@ namespace VISEQ::GRAPH::NODES { float last = 0; void init(){ - midiNoteHandles.emplace_back(std::make_shared>(midiNote.note, position, VS_COLOR_GREEN, "NOTE")); - midiNoteHandles.emplace_back(std::make_shared>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); - midiNoteHandles.emplace_back(std::make_shared>(midiNote.gate, position, VS_COLOR_RED, "GATE", 10, 30000, 40, 300)); - midiNoteHandles.emplace_back(std::make_shared>(midiNote.velocity, position, VS_COLOR_PURPLE, "VELOCITY")); - - midiCCHandles.emplace_back(std::make_shared>(midiCC.control, position, VS_COLOR_SUN, "CONTROL")); - midiCCHandles.emplace_back(std::make_shared>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); - midiCCHandles.emplace_back(std::make_shared>(midiCC.value, position, VS_COLOR_GREEN, "VALUE")); - - midiPCHandles.emplace_back(std::make_shared>(midiPC.program, position, VS_COLOR_SUN, "PROGRAM")); - midiPCHandles.emplace_back(std::make_shared>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); - midiPCHandles.emplace_back(std::make_shared>(midiPC.value, position, VS_COLOR_GREEN, "VALUE")); + float orbit_1 = radius + 25.0f; + float orbit_2 = orbit_1 + 20.0f; + float orbit_3 = orbit_2 + 20.0f; + float orbit_4 = orbit_3 + 20.0f; + float orbit_5 = orbit_4 + 30.0f; - midiPitchBendHandles.emplace_back(std::make_shared>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); - midiPitchBendHandles.emplace_back(std::make_shared>(midiPitchBend.value, position, VS_COLOR_GREEN, "VALUE", -8192, 8192, 40, 300)); + midiNoteHandles.emplace_back(std::make_shared>(midiNote.note, position, VS_COLOR_GREEN, "NOTE", orbit_5, 12)); + midiNoteHandles.emplace_back(std::make_shared>(midiNote.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150)); + midiNoteHandles.emplace_back(std::make_shared>(midiNote.gate, position, VS_COLOR_RED, "GATE", orbit_3, 30, 10, 30000, 40, 300)); + midiNoteHandles.emplace_back(std::make_shared>(midiNote.velocity, position, VS_COLOR_PURPLE, "VELOCITY", orbit_4, 32)); - midiAftertouchHandles.emplace_back(std::make_shared>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); - midiAftertouchHandles.emplace_back(std::make_shared>(midiAftertouch.value, position, VS_COLOR_GREEN, "VALUE")); + midiCCHandles.emplace_back(std::make_shared>(midiCC.control, position, VS_COLOR_SUN, "CONTROL", orbit_3, 32)); + midiCCHandles.emplace_back(std::make_shared>(midiCC.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150)); + midiCCHandles.emplace_back(std::make_shared>(midiCC.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32)); - midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", 1, 16, 40, 150)); - midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.value, position, VS_COLOR_GREEN, "VALUE")); - midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.note, position, VS_COLOR_SUN, "NOTE")); + midiPCHandles.emplace_back(std::make_shared>(midiPC.program, position, VS_COLOR_SUN, "PROGRAM", orbit_3, 32)); + midiPCHandles.emplace_back(std::make_shared>(midiPC.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150)); + midiPCHandles.emplace_back(std::make_shared>(midiPC.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32)); + + midiPitchBendHandles.emplace_back(std::make_shared>(midiPitchBend.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150)); + midiPitchBendHandles.emplace_back(std::make_shared>(midiPitchBend.value, position, VS_COLOR_GREEN, "VALUE", orbit_3, 256, -8192, 8192, 40, 300)); + + midiAftertouchHandles.emplace_back(std::make_shared>(midiAftertouch.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150)); + midiAftertouchHandles.emplace_back(std::make_shared>(midiAftertouch.value, position, VS_COLOR_GREEN, "VALUE", orbit_3, 32)); + + midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.channel, position, VS_COLOR_PINK, "CHANNEL", orbit_1, 1, 1, 16, 40, 150)); + midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.value, position, VS_COLOR_GREEN, "VALUE", orbit_4, 32)); + midiPolyPressureHandles.emplace_back(std::make_shared>(midiPolyPressure.note, position, VS_COLOR_SUN, "NOTE", orbit_5, 12)); } std::shared_ptr getPtr(){ diff --git a/src/node-handle.h b/src/node-handle.h index 0d076cc..102287d 100644 --- a/src/node-handle.h +++ b/src/node-handle.h @@ -16,8 +16,8 @@ namespace VISEQ::GRAPH::NODES{ class NodeHandle : public BASE::Draggable, public GraphItem, public std::enable_shared_from_this>{ public: NodeHandle() {} - NodeHandle(T &_assignedValue, Vec2Df parentPos, Color _col, std::string name) : assignedValueRef(_assignedValue), parentPosition(parentPos), col(_col), name(name) {init();} - NodeHandle(T &_assignedValue, Vec2Df parentPos, Color _col, std::string name, float min, float max, float minDist, float maxDist) : assignedValueRef(_assignedValue), parentPosition(parentPos), col(_col), name(name), minValue(min), maxValue(max), minDistance(minDist), maxDistance(maxDist) {init();} + NodeHandle(T &_assignedValue, Vec2Df parentPos, Color _col, std::string name, float orbit, int steps) : assignedValueRef(_assignedValue), parentPosition(parentPos), col(_col), name(name), orbit(orbit), steps(steps) {init();} + NodeHandle(T &_assignedValue, Vec2Df parentPos, Color _col, std::string name, float orbit, int steps, float min, float max, float minDist, float maxDist) : assignedValueRef(_assignedValue), parentPosition(parentPos), col(_col), name(name), minValue(min), maxValue(max), minDistance(minDist), maxDistance(maxDist), orbit(orbit), steps(steps) {init();} virtual GRAPH::GraphItemType getType() override { return GraphItemType::HANDLE; @@ -40,6 +40,8 @@ namespace VISEQ::GRAPH::NODES{ float radius = 10.0f; float orbit = 0.0f; + int steps = 1; + float angle_g = 0; Vec2Df minP; Vec2Df maxP; @@ -48,7 +50,7 @@ namespace VISEQ::GRAPH::NODES{ bool visible = false; void init(){ - position = parentPosition.orbitAtAngle(minDistance, DEG2RAD * GetRandomValue(0, 360)) - parentPosition; + position = parentPosition.orbitAtAngle(orbit, 0) - parentPosition; } void assignValue(T &value){ @@ -60,16 +62,13 @@ namespace VISEQ::GRAPH::NODES{ } virtual void drag(Vec2Df mouse_pos) override { - if(KEYS_DOWN.shift) { - orbit = (parentPosition + position).dist(parentPosition); - position = parentPosition.orbitAlongVector(SCREEN_MOUSE, orbit) - parentPosition; - } else { - float step = (maxDistance - minDistance) / (maxValue - minValue); - orbit = round(parentPosition.dist(SCREEN_MOUSE) / step) * step; - position = parentPosition.orbitAlongVector(maxP, orbit) - parentPosition; - } - if(distance() >= maxDistance) position = parentPosition.orbitAlongVector(maxP, maxDistance) - parentPosition; - if(distance() <= minDistance) position = parentPosition.orbitAlongVector(maxP, minDistance) - parentPosition; + float range = maxValue - minValue; + float stepping = 360 / range; + if(KEYS_DOWN.shift) stepping = steps; + float angle = Vector2Angle((SCREEN_MOUSE - parentPosition), Vector2(0,1)) * RAD2DEG; + float stepped_angle = (round(angle / stepping) * stepping) * DEG2RAD; + //position = parentPosition.orbitAlongVector(SCREEN_MOUSE, orbit) - parentPosition; + position = parentPosition.orbitAtAngle(orbit, stepped_angle) - parentPosition; } void lock(){ @@ -87,7 +86,11 @@ namespace VISEQ::GRAPH::NODES{ } void updateAssignedValue(){ - assignedValueRef = (T)Remap((float)(parentPosition + position).dist(parentPosition), minDistance, maxDistance, minValue, maxValue); + //T value = (T)Remap((float)(parentPosition + position).dist(parentPosition), minDistance, maxDistance, minValue, maxValue); + float angle = 360 - (Vector2Angle(position, Vector2(0,1)) * RAD2DEG + 180); + angle_g = angle; + T value = (T)Remap(angle, 0, 360, minValue, maxValue); + assignedValueRef = value; } virtual bool hovering() override { @@ -115,12 +118,23 @@ namespace VISEQ::GRAPH::NODES{ Color dcol = ColorBrightness(col, -0.5f); Color dyncol = show ? col : dcol; - DrawLineV(minP, maxP, dcol); + //DrawLineV(minP, maxP, dcol); //DrawLineV(parentPosition, minP, VS_COLOR_LIGHTGREY); - DrawCircleV(minP, 3.0f, dyncol); - DrawCircleV(maxP, 3.0f, dyncol); + //DrawCircleV(minP, 3.0f, dyncol); + //DrawCircleV(maxP, 3.0f, dyncol); + if(steps > 0){ + for(int i = 0; i < 360; i += steps){ + Vec2Df pos = parentPosition.orbitAtAngle(orbit, DEG2RAD * i); + Vec2Df pos1 = parentPosition.orbitAtAngle(orbit - 4.0f, DEG2RAD * i); + //DrawCircleV(pos, 1.0f, dyncol); + DrawLineV(pos, pos1, dyncol); + } + } DrawCircleV(position + parentPosition, radius, dyncol); - if(show) VISEQ::HELPER::DrawSuperText(name, minP, maxP, 0.5f, 8.0f, 10.0f, dyncol); + DrawCircleLinesV(parentPosition, (parentPosition + position).dist(parentPosition), 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); } }