// native_bridge/include/StateStore.h // G2: persist bridge instrument state to a JSON file so a bridge respawn // (crash, kill, restart) can reload instruments and continue playing. #ifndef STATE_STORE_H #define STATE_STORE_H #include #include #include // One instrument slot persisted to disk. struct InstrumentStateEntry { uint32_t channel = 0; int type = 0; // InstrumentType as int (0=VST3, 1=VST2, 2=SF2/SF3, 3=SFZ) std::string path; // absolute plugin/soundfont path std::string presetBase64; // VST3 serialized preset (empty for non-VST) uint32_t bank = 0; // last bank select (SF2/SF3) uint32_t program = 0; // last program change }; // Whole-bridge snapshot written to disk. struct BridgeStateSnapshot { std::vector instruments; bool playing = false; double playhead = 0.0; }; // Hand-rolled JSON persistence (no external JSON dependency). // File format: {"version":1,"playing":bool,"playhead":num,"instruments":[...]} // Writes are atomic: temp file + rename (crash mid-write never corrupts state). class StateStore { public: // %APPDATA%/SonicForgeDAW/state/bridge_state.json (UTF-8). static std::string defaultPath(); // Serialize snapshot to `path` (atomic). Returns false on IO error. static bool save(const BridgeStateSnapshot& snap, const std::string& path); // Read `path` into `out`; returns false if missing or unparsable. static bool load(BridgeStateSnapshot& out, const std::string& path); // Remove the state file (and any stale .tmp). Returns false if missing. static bool clear(const std::string& path); }; #endif // STATE_STORE_H