In https://github.com/giuliomoro/rnbo.example.bela/blob/dev/render.cpp the first preset is loaded in setup() at these lines:
if(presetList->size())
{
unsigned int idx = 0;
RNBO::UniquePresetPtr preset = presetList->presetAtIndex(idx);
printf("Loading preset %d: %s\n", idx, presetList->presetNameAtIndex(idx).c_str());
rnbo->setPreset(std::move(preset));
}
what you would need is something in render.cpp that from within render() does the following:
- checks for a button press
- increments a counter of the current preset
- loads the next preset
E.g. something like this might work:
void render(BelaContext *context, void *userData)
{
...
const int kPresetBtn = 10; // digital in 10
static bool pastPresetBtnRead = false; // button reads low when not pressed and high when pressed
bool presetRead = digitalRead(context, 0, kPresetBtn);
// checks for a button press
if(presetRead && presetRead != pastPresetBtnRead)
{
// button press just started: load next preset
if(presetList->size())
{
static unsigned int currentPreset = 0;
currentPreset++;
if(currentPreset >= presetList->size())
currentPreset = 0;
RNBO::UniquePresetPtr preset = presetList->presetAtIndex(currentPreset);
printf("Loading preset %d: %s\n", currentPreset, presetList->presetNameAtIndex(currentPreset).c_str());
rnbo->setPreset(std::move(preset));
}
}
...
}