Skip to content

Commit eaac343

Browse files
ramonsmitsradioactiveman
authored andcommitted
console: Load companion .m3u/.m3u8 for subsong metadata
The bundled GME library includes a full M3u_Playlist parser that understands the NEZplug extended m3u format (with ::TYPE and $track syntax), but the code to auto-load a companion .m3u was disabled. Re-enable it using the Audacious StringBuf API. When a game music file is loaded, look for a matching .m3u8 (preferred) or .m3u file in the same directory and feed it to the emulator. This provides track names, durations, and correct subsong mapping for KSS, NSF, GBS, HES, and other multi-track formats.
1 parent 95a3dbf commit eaac343

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/console/Audacious_Driver.cc

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* http://www.slack.net/~ant/libs/
77
*/
88

9+
#include <cstring>
910
#include <math.h>
1011

1112
#include <libaudcore/audstrings.h>
@@ -120,24 +121,22 @@ int ConsoleFileHandler::load(int sample_rate)
120121

121122
log_warning(m_emu);
122123

123-
#if 0
124-
// load .m3u from same directory( replace/add extension with ".m3u")
125-
char *m3u_path = g_strdup(m_path);
126-
char *ext = strrchr(m3u_path, '.');
127-
if (ext == nullptr)
128-
{
129-
ext = g_strdup_printf("%s.m3u", m3u_path);
130-
g_free(m3u_path);
131-
m3u_path = ext;
132-
}
124+
// load companion .m3u or .m3u8 from same directory
125+
StringBuf base_path = str_copy(m_path);
126+
const char *dot = strrchr(base_path, '.');
127+
if (dot)
128+
base_path.resize(dot - base_path);
133129

134130
Vfs_File_Reader m3u;
131+
StringBuf m3u_path = str_concat({base_path, ".m3u8"});
132+
if (m3u.open(m3u_path))
133+
m3u_path = str_concat({base_path, ".m3u"});
134+
135135
if (!m3u.open(m3u_path))
136136
{
137-
if (log_err(m_emu->load_m3u(m3u))) // TODO: fail if m3u can't be loaded?
138-
log_warning(m_emu); // this will log line number of first problem in m3u
137+
if (log_err(m_emu->load_m3u(m3u)))
138+
log_warning(m_emu);
139139
}
140-
#endif
141140

142141
return 0;
143142
}

0 commit comments

Comments
 (0)