- Edited
fennec the Write class isn't able doing this since it can only write whole files, overwrite them or append to i
it's meant for streaming data to disk while the audio process is running (e.g.: write sensor data), and it's pretty bad at it. It is not meant for reading/writing presets.
if you don't need the full flexibility of JSON, you can use these config file utilities http://docs.bela.io/namespaceConfigFileUtils.html . If you have your own format, you can just use the underlying I/O utilities to read/write files (http://docs.bela.io/namespaceIoUtils.html).
fennec So what about the JSON and JSON Value classes? Are they only for reading .json files? Does anybody have a good example showing this?
Not a "good" one. But see here https://forum.bela.io/d/2937-are-ioutils-still-available/3 (which eventually revers to nlohmann's json).
As usual, all disk I/O should not - at least in principle - take place in the audio thread. OTOH, one may be willing to tolerate audio dropouts while storing or loading a preset, so if it's easier and this is not a problem, you can also do that from the audio thread.
fennec The only trouble is, that it takes pretty long compiling (probably because all is one .hpp file?)
There are ways to work around that, for instance do not include the .hpp file directly from your render.cpp file, rather create a preset.cpp file where you perform all the JSON stuff and has a simpler API which is exposed to the file in render.cpp (such API should be exposed in something like preset.h, which should not include the json hpp file). This way, preset.cpp will require a long time to build, but render.cpp won't, so once you sorted out your preset stuff, you can keep building your code in render.cpp (and/or other files) without the building slow down due to the the json hpp file. Or you could set up distcc to offload some of the compilation tasks to the host computer: https://gist.github.com/jarmitage/2a5dffbcfdd5532371f097e9bb80e4b0