2024-10-25 16:41:37 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-19 01:04:06 +01:00
|
|
|
#include "clipboard.h"
|
2024-10-25 16:41:37 +02:00
|
|
|
#include "datatypes.h"
|
2024-10-30 14:55:24 +01:00
|
|
|
#include "graph-manager.h"
|
2024-11-01 02:38:47 +01:00
|
|
|
#include "midi-node.h"
|
2024-11-21 23:58:35 +01:00
|
|
|
#include "mouse.h"
|
2024-11-21 02:03:32 +01:00
|
|
|
#include "node.h"
|
|
|
|
|
#include "raylib.h"
|
2024-10-25 16:41:37 +02:00
|
|
|
#include "signal-manager.h"
|
2024-11-21 02:03:32 +01:00
|
|
|
#include "state.h"
|
2024-10-25 16:41:37 +02:00
|
|
|
#include "ui.h"
|
2024-10-27 00:40:57 +02:00
|
|
|
|
2024-11-01 02:38:47 +01:00
|
|
|
#include <memory>
|
2024-10-26 02:14:41 +02:00
|
|
|
#include <ranges>
|
2024-10-25 16:41:37 +02:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
namespace VISEQ::APP {
|
2024-10-25 16:41:37 +02:00
|
|
|
|
2024-11-14 00:55:09 +01:00
|
|
|
class AppManager{
|
2024-11-03 03:48:49 +01:00
|
|
|
public:
|
|
|
|
|
|
2024-11-22 00:24:31 +01:00
|
|
|
AppManager() : sm(&gm, &mutex), mouse(&gm), ui(&sm, &gm) {}
|
2024-10-25 16:41:37 +02:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
std::mutex mutex;
|
2024-10-25 16:41:37 +02:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
VISEQ::GRAPH::GraphManager gm;
|
|
|
|
|
VISEQ::SIGNAL::SignalManager sm;
|
2024-11-19 01:04:06 +01:00
|
|
|
VISEQ::APP::Clipboard cb;
|
2024-11-21 23:58:35 +01:00
|
|
|
VISEQ::APP::Mouse mouse;
|
2024-10-25 16:41:37 +02:00
|
|
|
|
2024-11-21 02:03:32 +01:00
|
|
|
std::shared_ptr<APP::State> state = APP::State::get();
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
UI::AppUI ui;
|
2024-10-25 16:41:37 +02:00
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
void updateMidiPorts(){
|
|
|
|
|
for(auto&n : gm.nodes | RANGE_FILTER([](VISEQ::GRAPH::NODES::SPTR_Node n){return n->getNodeType() == NodeType::MIDINODE;})){
|
|
|
|
|
auto nc = std::dynamic_pointer_cast<MidiNode>(n);
|
|
|
|
|
for(auto& mo : sm.midi.midi_out_ports){
|
|
|
|
|
if(!nc->midi_outs.contains(mo.number) && mo.enabled){
|
|
|
|
|
nc->midi_outs[mo.number] = {mo.number, mo.port.port_name, false};
|
|
|
|
|
}
|
|
|
|
|
if(nc->midi_outs.contains(mo.number) && !mo.enabled){
|
|
|
|
|
nc->midi_outs.erase(mo.number);
|
|
|
|
|
}
|
2024-10-25 16:41:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-03 03:48:49 +01:00
|
|
|
void removeNodes(VEC_SPTR_Node nodes){
|
2024-10-26 02:14:41 +02:00
|
|
|
|
2024-11-21 02:03:32 +01:00
|
|
|
VEC_SPTR_Node adjacent_nodes = gm.getAdjacentNodes(nodes);
|
2024-10-26 02:14:41 +02:00
|
|
|
|
2024-11-21 02:03:32 +01:00
|
|
|
sm.rerouteSignal(nodes, adjacent_nodes);
|
|
|
|
|
sm.rebaseSignal(nodes);
|
2024-10-26 02:14:41 +02:00
|
|
|
|
2024-11-21 02:03:32 +01:00
|
|
|
gm.removeNodesAndEdges(nodes);
|
2024-10-26 02:14:41 +02:00
|
|
|
}
|
2024-11-17 02:40:31 +01:00
|
|
|
|
2024-11-24 03:08:06 +01:00
|
|
|
void doInteraction(){
|
|
|
|
|
while(event_queue.size() > 0){
|
|
|
|
|
auto e = event_queue.front();
|
|
|
|
|
std::cout << e.action << " " << e.item->z_index << std::endl;
|
|
|
|
|
|
|
|
|
|
if(e.item->getType() == GraphItemType::NODE || e.item->getType() == GraphItemType::CONNECTOR) {
|
|
|
|
|
switch(e.action){
|
|
|
|
|
case VISEQ::APP::Interaction::PICKUP:
|
|
|
|
|
{
|
|
|
|
|
e.item->pickUp();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case VISEQ::APP::Interaction::DRAG:
|
|
|
|
|
{
|
|
|
|
|
e.item->drag();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case VISEQ::APP::Interaction::PUTDOWN:
|
|
|
|
|
{
|
|
|
|
|
e.item->putDown();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event_queue.pop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-17 02:40:31 +01:00
|
|
|
void update(){
|
2024-11-03 03:48:49 +01:00
|
|
|
mutex.lock();
|
|
|
|
|
updateMidiPorts();
|
|
|
|
|
mutex.unlock();
|
2024-11-24 03:08:06 +01:00
|
|
|
doInteraction();
|
2024-11-22 00:24:31 +01:00
|
|
|
mouse.update();
|
2024-11-21 02:03:32 +01:00
|
|
|
|
|
|
|
|
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_C)){
|
|
|
|
|
VEC_SPTR_Node selected_nodes = gm.getSelection();
|
|
|
|
|
if(!selected_nodes.empty()) cb.pushNodes(selected_nodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(KEYS_DOWN.ctrl && IsKeyPressed(KEY_V)){
|
|
|
|
|
VEC_SPTR_Node paste_nodes = cb.pullNodes();
|
|
|
|
|
if(!paste_nodes.empty()) gm.pasteNodesAndEdges(paste_nodes, MOD_MOUSE);
|
|
|
|
|
}
|
2024-11-17 02:40:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void draw(Vec2Df mouse_pos, Camera2D camera){
|
2024-11-03 03:48:49 +01:00
|
|
|
gm.drawNodes(mouse_pos, camera);
|
|
|
|
|
gm.drawEdges(mouse_pos, camera);
|
|
|
|
|
sm.drawSignals(mouse_pos, camera);
|
2024-10-26 02:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-15 01:49:10 +01:00
|
|
|
void drawUI(Vec2Df mouse_pos, Camera2D camera){
|
2024-11-03 03:48:49 +01:00
|
|
|
mutex.lock();
|
|
|
|
|
ui.draw(mouse_pos, camera);
|
|
|
|
|
mutex.unlock();
|
2024-10-26 02:14:41 +02:00
|
|
|
}
|
2024-11-03 03:48:49 +01:00
|
|
|
};
|
|
|
|
|
|
2024-11-14 00:55:09 +01:00
|
|
|
inline void to_json(json& j, const AppManager& A){
|
|
|
|
|
j = json{{"graphmanager", A.gm}, {"signalmanager", A.sm}};
|
2024-11-03 03:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 00:55:09 +01:00
|
|
|
inline void from_json(const json& j, AppManager& A){
|
2024-11-03 03:48:49 +01:00
|
|
|
j.at("graphmanager").get_to(A.gm); // = json{{"graphmanager", A.gm}, {"signalmanager", A.sm}};
|
|
|
|
|
}
|
|
|
|
|
}
|