Remember last cassette on startup, always pause on cassette switch

Persist the current cassette filename to last_cassette.txt so the player
resumes the same cassette after restart. Switching cassettes now always
lands in a paused state to avoid jarring mid-playback jumps.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michael Smith 2026-02-13 21:55:48 +01:00
parent 3fcae8ea5e
commit 8123b9a99f
2 changed files with 41 additions and 2 deletions

View File

@ -43,6 +43,11 @@ This document specifies the functional requirements for an SDL2 based media play
## 6. Changelog ## 6. Changelog
### 2026-02-13 — Remember last cassette and pause on switch
- **Remember last cassette**: The current cassette filename is saved to `last_cassette.txt` in the audio directory on every file switch. On startup, the player resumes the last-loaded cassette instead of always starting with the first file. Falls back to the first file if the saved file is missing or not found.
- **Pause on cassette switch**: Switching cassettes (prev/next) now always lands in a paused state, even if the player was playing. This avoids the jarring effect of immediately resuming from a saved position in a different cassette.
### 2026-02-13 — Fix power button shutdown regression ### 2026-02-13 — Fix power button shutdown regression
- **Consolidated input handling**: Power button long-press shutdown is now handled by `rg35xx-screen-monitor.py` instead of a separate `evtest`-based monitor in the wrapper. Both monitors were reading `/dev/input/event0` simultaneously, causing the `evtest` parser to miss power button events on the device's Linux 4.9 kernel. - **Consolidated input handling**: Power button long-press shutdown is now handled by `rg35xx-screen-monitor.py` instead of a separate `evtest`-based monitor in the wrapper. Both monitors were reading `/dev/input/event0` simultaneously, causing the `evtest` parser to miss power button events on the device's Linux 4.9 kernel.

View File

@ -197,6 +197,37 @@ static void adjust_volume(float delta) {
save_volume(); save_volume();
} }
/* --- Last cassette persistence --- */
static void save_last_cassette(const char* filename) {
char path[1024];
snprintf(path, sizeof(path), "%s/last_cassette.txt", audio_dir);
FILE* f = fopen(path, "w");
if (f) {
fprintf(f, "%s\n", filename);
fclose(f);
}
}
static int load_last_cassette(void) {
char path[1024];
snprintf(path, sizeof(path), "%s/last_cassette.txt", audio_dir);
FILE* f = fopen(path, "r");
if (!f) return 0;
char name[256];
if (!fgets(name, sizeof(name), f)) {
fclose(f);
return 0;
}
fclose(f);
char* nl = strchr(name, '\n');
if (nl) *nl = '\0';
for (int i = 0; i < num_audio_files; i++) {
if (strcmp(audio_files[i], name) == 0) return i;
}
return 0;
}
/* --- File scanning --- */ /* --- File scanning --- */
static int has_audio_extension(const char* name) { static int has_audio_extension(const char* name) {
@ -484,11 +515,14 @@ static void switch_file(int index) {
decoder_seek(pos); decoder_seek(pos);
} }
save_last_cassette(current_file);
char title[768]; char title[768];
snprintf(title, sizeof(title), "SDLamp2 - %s", current_file); snprintf(title, sizeof(title), "SDLamp2 - %s", current_file);
SDL_SetWindowTitle(window, title); SDL_SetWindowTitle(window, title);
SDL_PauseAudioDevice(audio_device, paused); paused = SDL_TRUE;
SDL_PauseAudioDevice(audio_device, 1);
return; return;
} }
@ -674,7 +708,7 @@ int main(int argc, char** argv) {
scan_audio_files(audio_dir); scan_audio_files(audio_dir);
volume = load_volume(); volume = load_volume();
if (num_audio_files > 0) { if (num_audio_files > 0) {
switch_file(0); switch_file(load_last_cassette());
} else { } else {
SDL_SetWindowTitle(window, "SDLamp2 - No audio files found"); SDL_SetWindowTitle(window, "SDLamp2 - No audio files found");
} }