theallelectricsmartgrid

State Saver

The state saver (private/src/StateSaver.hpp) handles persistence of non-encoder runtime control state to/from JSON. It is not the general persistence layer for the whole synth.

Scope and separation from encoder state

StateSaver is a fixed-width per-scene registry for non-encoder state only. Encoder state never touches StateSaver: encoders serialize separately via EncoderBankBank::ToJSON() / FromJSON() (private/src/EncoderBankBank.hpp), which iterate the encoder array and write each named parameter.

In TheNonagonSquiggleBoyInternal, the two persistence paths sit side by side in the patch JSON:

Role

StateSaver bridges live in-memory non-encoder values and serialized patch/project state:

It is saved and loaded alongside Nonagon and SquiggleBoy state.

SquiggleBoyConfigGrid also persists sample-source directory choices. It writes a sampleDirectoryRelative array with one relative path per voice; on restore, each non-empty path is resolved under the configured sample root and loaded asynchronously through IoTaskThread::PushLoadAudioBufferBankFromDirectory(...).

Internal model

StateSaverTemp<NumScenes> stores compact per-scene snapshots for registered values:

This design keeps serialization generic while preserving exact typed values.

Scene-aware persistence

StateSaver works with scene logic so scene-specific values are retained: