From 53332db3e65f867ff13d33e659b034891d222ac8 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Thu, 16 Jan 2025 09:08:20 -0800 Subject: [PATCH] Change how getting the current title works, and fix ZSM backend not setting itself as opened. --- backends/playback/sdl_mixer_x/sdl_mixer_x.cpp | 9 +++------ backends/playback/zsm/zsm_backend.cpp | 4 +++- playback_backend.hpp | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/backends/playback/sdl_mixer_x/sdl_mixer_x.cpp b/backends/playback/sdl_mixer_x/sdl_mixer_x.cpp index e74af9d..85210d9 100644 --- a/backends/playback/sdl_mixer_x/sdl_mixer_x.cpp +++ b/backends/playback/sdl_mixer_x/sdl_mixer_x.cpp @@ -62,10 +62,7 @@ void SDLMixerXBackend::load(const char *filename) { current_file = std::string(filename); const char *title_tag = Mix_GetMusicTitleTag(output); // Check for an empty string, which indicates there's no title tag. - if (title_tag[0] == '\0') { - std::filesystem::path path(current_file); - current_title = path.stem().string(); - } else { + if (title_tag[0] != '\0') { current_title = std::string(title_tag); } this->music = output; @@ -73,9 +70,9 @@ void SDLMixerXBackend::load(const char *filename) { PlaybackStream stream; stream.id = 0; stream.length = Mix_MusicDuration(output); - stream.name = current_title; - streams.push_back(stream); open = true; + stream.name = get_title().value(); + streams.push_back(stream); initial = true; } void SDLMixerXBackend::switch_stream(int idx) { diff --git a/backends/playback/zsm/zsm_backend.cpp b/backends/playback/zsm/zsm_backend.cpp index 780ebeb..f05531d 100644 --- a/backends/playback/zsm/zsm_backend.cpp +++ b/backends/playback/zsm/zsm_backend.cpp @@ -40,7 +40,7 @@ std::vector ZsmBackend::get_property_list() { return properties; } void ZsmBackend::load(const char *filename) { - memset(&spec, 0, sizeof(spec)); + memset(&spec, 0, sizeof(spec)); current_file = filename; spec.format = AUDIO_S16SYS; spec.samples = 100; @@ -157,6 +157,7 @@ void ZsmBackend::load(const char *filename) { property_defaults[#name] = value; \ } #include "properties.inc" + PlaybackStream stream; } extern SDL_AudioSpec obtained; void ZsmBackend::switch_stream(int idx) { @@ -172,6 +173,7 @@ void ZsmBackend::switch_stream(int idx) { this->cpuClocks = 0.0; this->delayTicks = 0.0; this->ticks = 0.0; + open = true; } void ZsmBackend::cleanup() { delete file; diff --git a/playback_backend.hpp b/playback_backend.hpp index 994ff83..df82364 100644 --- a/playback_backend.hpp +++ b/playback_backend.hpp @@ -24,7 +24,7 @@ class PlaybackBackend { uint64_t length; std::vector streams; std::string current_file; - std::string current_title; + std::optional current_title; bool open; SDL_AudioSpec spec; uint64_t position; @@ -134,7 +134,21 @@ class PlaybackBackend { return open ? current_file : std::optional(); } inline virtual std::optional get_title() { - return open ? current_title : std::optional(); + if (open) { + if (current_title.has_value()) { + return current_title; + } else { + auto file = get_current_file(); + if (file.has_value()) { + std::filesystem::path path(file.value()); + return path.stem().string(); + } else { + return {}; + } + } + } else { + return {}; + } } inline virtual int get_stream_idx() {return 0;} inline virtual ~PlaybackBackend() { }