json is loading, but does nothing yet

This commit is contained in:
Sebastian
2024-11-03 03:48:49 +01:00
parent a4ea20b2b3
commit 7bdd68bdcc
16 changed files with 1174 additions and 1104 deletions
+32 -16
View File
@@ -6,6 +6,10 @@
*
*/
#include "graph-manager.h"
#include "vmath.h"
#include <filesystem>
#include <fstream>
#define RAYGUI_IMPLEMENTATION
#include <raylib.h>
#include <raymath.h>
@@ -24,9 +28,11 @@
#include <iterator>
#include <memory>
#include "state-io.h"
using json = nlohmann::json;
AppState app;
VISEQ::APP::AppState app;
Vec2Df mouse_pos;
Vec2Df drag_start;
@@ -72,19 +78,26 @@ int main(){
camera.rotation = 0.0f;
camera.zoom = 1.0f;
for(int i = 0; i < 4; ++i){
app.gm.addMidiNode(Vec2Df{(float)i * app.settings.grid*4 + 7 * app.settings.grid, 2 * app.settings.grid*4});
}
for(int i = 3; i >= 0; --i){
app.gm.addMidiNode(Vec2Df{(float)i * app.settings.grid*4 + 7 * app.settings.grid, 3 * app.settings.grid*4});
if(std::filesystem::exists("state.json")){
std::ifstream f("state.json");
json graph = json::parse(f);
app.gm = graph["graphmanager"].template get<VISEQ::GRAPH::GraphManager>();
} else {
for(int i = 0; i < 4; ++i){
app.gm.addMidiNode(Vec2Df{(float)i * app.settings.grid*4 + 7 * app.settings.grid, 2 * app.settings.grid*4});
}
for(int i = 3; i >= 0; --i){
app.gm.addMidiNode(Vec2Df{(float)i * app.settings.grid*4 + 7 * app.settings.grid, 3 * app.settings.grid*4});
}
for(int i = 0; i < 8; ++i){
app.gm.addConnection(app.gm.nodes[i], app.gm.nodes[(i+1) % 8]);
}
app.sm.addSignalAtNode(app.gm.nodes.front());
}
for(int i = 0; i < 8; ++i){
app.gm.addConnection(app.gm.nodes[i], app.gm.nodes[(i+1) % 8]);
}
app.sm.addSignalAtNode(app.gm.nodes.front());
app.sm.startSignalThread();
enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, DRAG_NODE, CONNECT_NODE, DRAW_SELECTION, DELETE_SELECTED_NODES, COPY_SELECTED_NODES, PASTE_SELECTED_NODES};
@@ -223,7 +236,7 @@ int main(){
float pol_r = steps;
float pol_theta = Vector2Angle(Vec2Df{1,0},(mouse_pos - dragNode->neighbor->position));
Vec2Df polar = VMath::polarToCartesian(pol_r, pol_theta);
Vec2Df polar = VISEQ::VMATH::polarToCartesian(pol_r, pol_theta);
dragNode->position = dragNode->neighbor->position + polar;
} else {
dragNode->position = mouse_pos + dragNode->drag_offset;
@@ -330,8 +343,8 @@ int main(){
midiNode->midi_pitch_bend += wheel;
break;}
};
if(midiNode->midi_note < 0 ) midiNode->midi_note = app.sm.midi.midiNotes.size()-1;
if(midiNode->midi_note >= app.sm.midi.midiNotes.size() ) midiNode->midi_note = 0;
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(midiNode->midi_cc < 0 ) midiNode->midi_cc = 127;
if(midiNode->midi_cc > 127 ) midiNode->midi_cc = 0;
@@ -390,7 +403,10 @@ int main(){
EndDrawing();
}
std::cout << std::setw(4) << json(app.gm) << std::endl;
std::ofstream file("state.json");
file << json(app);
std::cout << std::setw(4) << json(app) << std::endl;
CloseWindow();