giuliomoro
we don't have an API for that. I have written text files with WriteFile
and read them with std::ifstream
(see, e.g.: here for the reading part). This was done in a non-realtime context. The only difference when doing it in a real-time context is that you need to run this function in an AuxiliaryTask
, e.g.:
AuxiliaryTask readFileTask;
std::string path;
float parameter1;
float parameter2;
float parameter3;
void readFileFunc(void*)
{
std::ifstream inputFile;
try
{
inputFile.open(path);
if(inputFile.fail())
{
fprintf(stderr, "Unable to open file\n");
}
while(!inputFile.eof())
{
unsigned int key;
inputFile >> parameter1;
inputFile >> parameter2;
inputFile >> parameter3;
}
}
catch(...)
{
fprintf(stderr, "Exception while reading file\n");
}
}
bool setup(BelaContext* context, void*)
{
readFileTask = Bela_createAuxiliaryTask(readFileFunc, 1, "readFileTask", NULL);
}
void render(BelaContext* context, void*)
{
if(shouldLoadPreset)
{
path = "pathForPresetToLoad";
Bela_scheduleAuxiliaryTask(readFileTask);
}
}
In the example above, you are loading the parameter..
variables one at a time, which - depending on your application - may or may not be a problem. If it is a problem (e.g.: if there is something non thread-safe, or if you wish the parameters to all be loaded at the same time), just load them all in a separate variable, then when done notify render()
of the update, and let render()
apply all the new parameters at the same time.