GME Plugin: try loading m3u sidecar files

This commit is contained in:
John Regan 2017-09-22 16:51:36 +02:00
parent da9657aac4
commit e96513c8db

View File

@ -105,16 +105,39 @@ ParseContainerPath(Path path_fs)
return { path_fs.GetDirectoryName(), track - 1 }; return { path_fs.GetDirectoryName(), track - 1 };
} }
static Music_Emu*
LoadGmeAndM3u(GmeContainerPath container) {
const char *path = container.path.c_str();
const char *suffix = uri_get_suffix(path);
Music_Emu *emu;
const char *gme_err =
gme_open_file(path, &emu, GME_SAMPLE_RATE);
if (gme_err != nullptr) {
LogWarning(gme_domain, gme_err);
return nullptr;
}
if(suffix == nullptr) {
return emu;
}
std::string m3u_path(path,suffix);
m3u_path += "m3u";
gme_load_m3u(emu,m3u_path.c_str());
return emu;
}
static void static void
gme_file_decode(DecoderClient &client, Path path_fs) gme_file_decode(DecoderClient &client, Path path_fs)
{ {
const auto container = ParseContainerPath(path_fs); const auto container = ParseContainerPath(path_fs);
Music_Emu *emu; Music_Emu *emu = LoadGmeAndM3u(container);
const char *gme_err = if(emu == nullptr) {
gme_open_file(container.path.c_str(), &emu, GME_SAMPLE_RATE);
if (gme_err != nullptr) {
LogWarning(gme_domain, gme_err);
return; return;
} }
@ -129,7 +152,7 @@ gme_file_decode(DecoderClient &client, Path path_fs)
#endif #endif
gme_info_t *ti; gme_info_t *ti;
gme_err = gme_track_info(emu, &ti, container.track); const char *gme_err = gme_track_info(emu, &ti, container.track);
if (gme_err != nullptr) { if (gme_err != nullptr) {
LogWarning(gme_domain, gme_err); LogWarning(gme_domain, gme_err);
return; return;
@ -255,11 +278,8 @@ gme_scan_file(Path path_fs,
{ {
const auto container = ParseContainerPath(path_fs); const auto container = ParseContainerPath(path_fs);
Music_Emu *emu; Music_Emu *emu = LoadGmeAndM3u(container);
const char *gme_err = if(emu == nullptr) {
gme_open_file(container.path.c_str(), &emu, GME_SAMPLE_RATE);
if (gme_err != nullptr) {
LogWarning(gme_domain, gme_err);
return false; return false;
} }
@ -272,12 +292,10 @@ static std::forward_list<DetachedSong>
gme_container_scan(Path path_fs) gme_container_scan(Path path_fs)
{ {
std::forward_list<DetachedSong> list; std::forward_list<DetachedSong> list;
const auto container = ParseContainerPath(path_fs);
Music_Emu *emu; Music_Emu *emu = LoadGmeAndM3u(container);
const char *gme_err = gme_open_file(path_fs.c_str(), &emu, if(emu == nullptr) {
GME_SAMPLE_RATE);
if (gme_err != nullptr) {
LogWarning(gme_domain, gme_err);
return list; return list;
} }