I devised a simple method of saving the currently selected track for the current preset each time the user presses a button to advance to the next track in the list. However, when I added this to the code, it causes a noticeable split-second pause in all audio playback. Here is the relevant code:
void NextTrack() {
if (num_tracks_ > 0) {
if (track_player_->isPlaying()) track_player_->Stop();
if (track_player_) track_player_.Free();
char next_track[128];
next_track[0] = 0;
if (!RunCommandAndFindNextSortedLine<128>("list_current_tracks", nullptr, current_track_, next_track, false)) {
RunCommandAndFindNextSortedLine<128>("list_current_tracks", nullptr, nullptr, next_track, false);
}
strcpy(current_track_, next_track);
PlayTrack();
} else {
StartOrStopTrack();
StartOrStopTrack();
}
}
bool Event2(enum BUTTON button, EVENT event, uint32_t modifiers) override {
switch (EVENTID(button, event, modifiers)) {
// Next Preset/Track
case EVENTID(BUTTON_AUX, EVENT_FIRST_HELD_MEDIUM, MODE_OFF):
if (SFX_mselect) {
hybrid_font.PlayPolyphonic(&SFX_mselect);
}
NextTrack();
#ifdef CAIWYN_SAVE_TRACKS
current_preset_.track = mkstr(current_track_);
current_preset_.Save();
#endif
return true;
If CAIWYN_SAVE_TRACKS is not defined then the audio plays as expected. If it’s defined, however, there’s an audible dropout in the audio. Is there something I’m missing that needs to be added to make this work more smoothly?