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