global mouse moved to state and removed some GetMousePosition()s.
This commit is contained in:
+1
-5
@@ -19,12 +19,10 @@ namespace VISEQ::BASE {
|
||||
}
|
||||
|
||||
virtual bool hovering() override {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
return CheckCollisionPointCircle(mp, position, 5);
|
||||
return CheckCollisionPointCircle(state->screen_mouse, position, 5);
|
||||
}
|
||||
|
||||
virtual void drag() override {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
DrawLineV(position, state->mod_mouse, (Color){229, 181, 103, 255});
|
||||
}
|
||||
|
||||
@@ -39,8 +37,6 @@ namespace VISEQ::BASE {
|
||||
}
|
||||
|
||||
virtual void connect() {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
|
||||
if(picked_up){
|
||||
for(auto c : connectables){
|
||||
if(c.get() != this && c->hovering()) {
|
||||
|
||||
+4
-5
@@ -8,6 +8,8 @@
|
||||
namespace VISEQ::GRAPH {
|
||||
class Connector : public BASE::Connectable, public GraphItem{
|
||||
public:
|
||||
using GraphItem::state;
|
||||
|
||||
Connector() {}
|
||||
Connector(Vec2Df center_position, float orbit) : orbit(orbit) {setPosition(center_position);}
|
||||
|
||||
@@ -16,16 +18,13 @@ namespace VISEQ::GRAPH {
|
||||
Vec2Df center_position;
|
||||
|
||||
void setPosition(Vec2Df pos) override {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
center_position = pos;
|
||||
if(!partner) position = center_position - ((center_position - mp)).norm() * (radius + orbit);
|
||||
if(!partner) position = center_position - ((center_position - state->screen_mouse)).norm() * (radius + orbit);
|
||||
if(partner) position = center_position - ((center_position - partner->position)).norm() * (radius + orbit);
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
|
||||
float opacity = 150.0f - Clamp(position.dist(mp), 0.0f, 150.0f);
|
||||
float opacity = 150.0f - Clamp(position.dist(state->screen_mouse), 0.0f, 150.0f);
|
||||
|
||||
if(partner){
|
||||
DrawLineV(position, partner->position, VS_COLOR_RED);
|
||||
|
||||
+1
-2
@@ -17,10 +17,9 @@ namespace VISEQ::BASE {
|
||||
bool picked_up = false;
|
||||
|
||||
virtual bool pickedUp() {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
if(clicked() && held()) {
|
||||
picked_up = true;
|
||||
drag_offset = position - mp;
|
||||
drag_offset = position - state->raw_mouse;
|
||||
}
|
||||
return picked_up;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "globals.h"
|
||||
#include "state.h"
|
||||
#include "raylib.h"
|
||||
#include "datatypes.h"
|
||||
#include <memory>
|
||||
|
||||
+8
-14
@@ -5,7 +5,7 @@
|
||||
* 2024 Sebastian Kujas
|
||||
*
|
||||
*/
|
||||
#include "globals.h"
|
||||
#include "state.h"
|
||||
#include "datatypes.h"
|
||||
#include "graph-manager.h"
|
||||
#include "node.h"
|
||||
@@ -83,7 +83,7 @@ int main(){
|
||||
std::ifstream f("state.json");
|
||||
json graph = json::parse(f);
|
||||
|
||||
state->settings = graph.at("settings");
|
||||
// state->settings = graph.at("settings");
|
||||
|
||||
int highest_id = 0;
|
||||
std::shared_ptr<Node> hid;
|
||||
@@ -197,7 +197,8 @@ int main(){
|
||||
Vec2Df mouse_delta = {GetMouseDelta().x, GetMouseDelta().y};
|
||||
Vec2Df delta = mouse_delta * (-1.0f/camera.zoom);
|
||||
|
||||
state->raw_mouse = mouse_pos;
|
||||
state->screen_mouse = mouse_pos;
|
||||
state->raw_mouse = {GetMousePosition().x, GetMousePosition().y};
|
||||
state->mod_mouse = mouse_pos;
|
||||
|
||||
if(IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||
@@ -513,22 +514,15 @@ int main(){
|
||||
/* break;*/
|
||||
/* }*/
|
||||
/*};*/
|
||||
if(mouse_right_down) {
|
||||
camera.target = Vector2Add(camera.target, delta);
|
||||
}
|
||||
|
||||
float wheel = GetMouseWheelMove();
|
||||
if(wheel != 0){
|
||||
if(!hovering_nodes.empty() && hovering_nodes.front()->getNodeType() == NodeType::MIDINODE) {
|
||||
VEC_SPTR_Node modify_nodes;
|
||||
std::copy_if(selected_nodes.begin(), selected_nodes.end(), std::back_inserter(modify_nodes), [](SPTR_Node n){ return n->getNodeType() == NodeType::MIDINODE;});
|
||||
if(selected_nodes.empty()) std::copy_if(hovering_nodes.begin(), hovering_nodes.end(), std::back_inserter(modify_nodes), [modify_nodes](SPTR_Node n){ return n->getNodeType() == NodeType::MIDINODE && !std::ranges::contains(modify_nodes, n);});
|
||||
|
||||
for(auto n : modify_nodes){
|
||||
std::shared_ptr<MidiNode> midiNode = std::dynamic_pointer_cast<MidiNode>(n);
|
||||
}
|
||||
}
|
||||
if(!IsKeyDown(KEY_LEFT_SHIFT) && !IsKeyDown(KEY_LEFT_CONTROL) && !IsKeyDown(KEY_LEFT_ALT)){
|
||||
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
|
||||
camera.offset = GetMousePosition();
|
||||
camera.target = mouseWorldPos;
|
||||
camera.target = mouse_pos;
|
||||
float scaleFactor = 1.0f + (0.25f*fabsf(wheel));
|
||||
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
|
||||
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
|
||||
|
||||
+29
-24
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "graph-item.h"
|
||||
#include "node.h"
|
||||
#include "raymath.h"
|
||||
#include <map>
|
||||
@@ -12,6 +13,7 @@ namespace VISEQ::GRAPH::NODES {
|
||||
class MidiNode : public Node{
|
||||
|
||||
public:
|
||||
using GraphItem::state;
|
||||
|
||||
struct NodeMidiOut{
|
||||
int i;
|
||||
@@ -65,8 +67,8 @@ namespace VISEQ::GRAPH::NODES {
|
||||
|
||||
virtual NodeType getNodeType() const override {return nodeType;}
|
||||
|
||||
void setMidiPort(int midi_port, bool state){
|
||||
midi_outs[midi_port].enabled = state;
|
||||
void setMidiPort(int midi_port, bool _state){
|
||||
midi_outs[midi_port].enabled = _state;
|
||||
}
|
||||
|
||||
void trigger() override {
|
||||
@@ -83,49 +85,50 @@ namespace VISEQ::GRAPH::NODES {
|
||||
return midi_gate;
|
||||
}
|
||||
void interact(){
|
||||
float wheel = GetMouseWheelMove();
|
||||
|
||||
if(IsKeyDown(KEY_LEFT_CONTROL) && !IsKeyDown(KEY_LEFT_ALT)){
|
||||
switch(state->settings.mode){
|
||||
switch(GraphItem::state->node_mode){
|
||||
case 0:{
|
||||
midiNode->midi_note += wheel;
|
||||
midi_note += wheel;
|
||||
break;}
|
||||
case 1:{
|
||||
midiNode->midi_cc += wheel;
|
||||
midi_cc += wheel;
|
||||
break;}
|
||||
case 2:{
|
||||
midiNode->midi_pitch_bend += wheel;
|
||||
midi_pitch_bend += wheel;
|
||||
break;}
|
||||
};
|
||||
if(midiNode->midi_note < 0 ) midiNode->midi_note = VISEQ::MIDI::Notes.size()-1;
|
||||
if(midiNode->midi_note >= VISEQ::MIDI::Notes.size() ) midiNode->midi_note = 0;
|
||||
if(midi_note < 0 ) midi_note = VISEQ::MIDI::Notes.size()-1;
|
||||
if(midi_note >= VISEQ::MIDI::Notes.size() ) midi_note = 0;
|
||||
|
||||
if(midiNode->midi_cc < 0 ) midiNode->midi_cc = 127;
|
||||
if(midiNode->midi_cc > 127 ) midiNode->midi_cc = 0;
|
||||
if(midi_cc < 0 ) midi_cc = 127;
|
||||
if(midi_cc > 127 ) midi_cc = 0;
|
||||
|
||||
if(midiNode->midi_pitch_bend < 0 ) midiNode->midi_pitch_bend = 0;
|
||||
if(midiNode->midi_pitch_bend > 16383 ) midiNode->midi_pitch_bend = 16383;
|
||||
if(midi_pitch_bend < 0 ) midi_pitch_bend = 0;
|
||||
if(midi_pitch_bend > 16383 ) midi_pitch_bend = 16383;
|
||||
|
||||
} else if(IsKeyDown(KEY_LEFT_SHIFT) && !IsKeyDown(KEY_LEFT_ALT)) {
|
||||
midiNode->midi_velocity += wheel;
|
||||
if(midiNode->midi_velocity < 0 ) midiNode->midi_velocity = 127;
|
||||
if(midiNode->midi_velocity > 127 ) midiNode->midi_velocity = 0;
|
||||
midi_velocity += wheel;
|
||||
if(midi_velocity < 0 ) midi_velocity = 127;
|
||||
if(midi_velocity > 127 ) midi_velocity = 0;
|
||||
} else if(IsKeyDown(KEY_LEFT_ALT)) {
|
||||
switch(state->settings.mode){
|
||||
switch(GraphItem::state->node_mode){
|
||||
case 0:{
|
||||
float incr = (float)wheel * (IsKeyDown(KEY_LEFT_SHIFT) ? 100.0f : IsKeyDown(KEY_LEFT_CONTROL) ? 1000.0f : 10.0f);
|
||||
midiNode->midi_gate += incr;
|
||||
if(midiNode->midi_gate < 0 ) midiNode->midi_gate = 0;
|
||||
midi_gate += incr;
|
||||
if(midi_gate < 0 ) midi_gate = 0;
|
||||
break;}
|
||||
case 1:{
|
||||
midiNode->midi_cc_value += wheel;
|
||||
if(midiNode->midi_cc_value < 0 ) midiNode->midi_cc_value = 0;
|
||||
if(midiNode->midi_cc_value > 127 ) midiNode->midi_cc_value = 127;
|
||||
midi_cc_value += wheel;
|
||||
if(midi_cc_value < 0 ) midi_cc_value = 0;
|
||||
if(midi_cc_value > 127 ) midi_cc_value = 127;
|
||||
break;}
|
||||
case 2:{
|
||||
float incr = (float)wheel * (IsKeyDown(KEY_LEFT_SHIFT) ? 100.0f : IsKeyDown(KEY_LEFT_CONTROL) ? 1000.0f : 10.0f);
|
||||
midiNode->midi_pitch_bend += incr;
|
||||
if(midiNode->midi_pitch_bend < 0 ) midiNode->midi_pitch_bend = 0;
|
||||
if(midiNode->midi_pitch_bend > 16383 ) midiNode->midi_pitch_bend = 16383;
|
||||
midi_pitch_bend += incr;
|
||||
if(midi_pitch_bend < 0 ) midi_pitch_bend = 0;
|
||||
if(midi_pitch_bend > 16383 ) midi_pitch_bend = 16383;
|
||||
break;}
|
||||
};
|
||||
}
|
||||
@@ -133,6 +136,8 @@ namespace VISEQ::GRAPH::NODES {
|
||||
|
||||
void draw(Vec2Df mouse, Camera2D cam) override {
|
||||
Node::draw();
|
||||
interact();
|
||||
|
||||
last = time;
|
||||
time = GetTime();
|
||||
if(time - start >= (float)midi_gate / 1000.0f){
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "globals.h"
|
||||
#include "state.h"
|
||||
#include "vmath.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
+4
-2
@@ -18,6 +18,8 @@ namespace VISEQ::GRAPH::NODES {
|
||||
class Node : public BASE::Draggable, public GraphItem{
|
||||
|
||||
public:
|
||||
using GraphItem::state;
|
||||
|
||||
Node() {}
|
||||
Node(float x, float y) : Draggable(Vec2Df(x, y)) {}
|
||||
Node(Vec2Df p) : Draggable(p) {}
|
||||
@@ -52,11 +54,11 @@ namespace VISEQ::GRAPH::NODES {
|
||||
virtual void trigger() {};
|
||||
|
||||
virtual bool hovering() override {
|
||||
Vec2Df mp = {GetMousePosition().x, GetMousePosition().y};
|
||||
return CheckCollisionPointCircle(mp, position, radius);
|
||||
return CheckCollisionPointCircle(state->raw_mouse, position, radius);
|
||||
}
|
||||
|
||||
void update() override{
|
||||
|
||||
if(pickedUp()) drag();
|
||||
if(released()) putDown();
|
||||
int free_connectors = 0;
|
||||
|
||||
+5
-2
@@ -6,7 +6,6 @@
|
||||
namespace VISEQ::APP{
|
||||
|
||||
struct AppSettings{
|
||||
int mode = 0;
|
||||
int width;
|
||||
int height;
|
||||
float grid;
|
||||
@@ -15,7 +14,7 @@ namespace VISEQ::APP{
|
||||
float speed = 16.0f;
|
||||
int gui_selected_midi_out;
|
||||
};
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(AppSettings, mode, width, height, grid, bpm, fps, speed, gui_selected_midi_out)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(AppSettings, width, height, grid, bpm, fps, speed, gui_selected_midi_out)
|
||||
|
||||
class State{
|
||||
public:
|
||||
@@ -24,9 +23,13 @@ namespace VISEQ::APP{
|
||||
void operator=(const State &) = delete;
|
||||
|
||||
AppSettings settings;
|
||||
|
||||
Vec2Df raw_mouse;
|
||||
Vec2Df screen_mouse;
|
||||
Vec2Df mod_mouse;
|
||||
|
||||
int node_mode = 0;
|
||||
|
||||
inline static std::shared_ptr<State> instance;
|
||||
static std::shared_ptr<State> get() {
|
||||
if(!instance){
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "globals.h"
|
||||
#include "state.h"
|
||||
#include "midi-node.h"
|
||||
#include "raylib.h"
|
||||
#include "raygui/raygui.h"
|
||||
@@ -137,7 +137,7 @@ namespace VISEQ::APP::UI{
|
||||
GuiCheckBox((Rectangle){np.x + 160, np.y + y_channel, 20, 20}, "PITCH", &mn->send_pitch_bend);
|
||||
|
||||
int y_cc_note = y_channel + 120;
|
||||
switch(state->settings.mode){
|
||||
switch(state->node_mode){
|
||||
case 0:{
|
||||
GuiLabel((Rectangle){np.x + 20, np.y + y_cc_note - 75, 220, 20}, "NOTE CHANNEL");
|
||||
GuiToggleGroup((Rectangle){np.x + 20, np.y + y_cc_note - 50, 25, 20}, "1;2;3;4;5;6;7;8\n9;10;11;12;13;14;15;16", &mn->midi_note_channel);
|
||||
|
||||
Reference in New Issue
Block a user