shithub: choc

Download patch

ref: f01ac84ab3e2d38f977b0309f16da3644150e5aa
parent: d113f4436909b86630af10022e2a18c8872bc159
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Oct 27 13:58:40 EDT 2018

music: Find .cfg files by globbing, not by name.

This allows additional music packs with other filenames beyond the
"well-known" ones. This opens the door for eg. music packs for PWADs
if that's something people want.

This fixes #1051.

--- a/src/i_musicpack.c
+++ b/src/i_musicpack.c
@@ -25,6 +25,7 @@
 #include "SDL.h"
 #include "SDL_mixer.h"
 
+#include "i_glob.h"
 #include "i_midipipe.h"
 
 #include "config.h"
@@ -92,16 +93,6 @@
 static subst_music_t *subst_music = NULL;
 static unsigned int subst_music_len = 0;
 
-static const char *subst_config_filenames[] =
-{
-    "doom1-music.cfg",
-    "doom2-music.cfg",
-    "tnt-music.cfg",
-    "heretic-music.cfg",
-    "hexen-music.cfg",
-    "strife-music.cfg",
-};
-
 static boolean music_initialized = false;
 
 // If this is true, this module initialized SDL sound and has the 
@@ -878,7 +869,7 @@
 
 // Read a substitute music configuration file.
 
-static boolean ReadSubstituteConfig(char *musicdir, char *filename)
+static boolean ReadSubstituteConfig(char *musicdir, const char *filename)
 {
     char *buffer;
     char *line;
@@ -933,8 +924,9 @@
 
 static void LoadSubstituteConfigs(void)
 {
+    glob_t *glob;
     char *musicdir;
-    char *path;
+    const char *path;
     unsigned int old_music_len;
     unsigned int i;
 
@@ -954,16 +946,18 @@
         musicdir = M_StringJoin(configdir, "music", DIR_SEPARATOR_S, NULL);
     }
 
-    // Load all music packs. We always load all music substitution packs for
-    // all games. Why? Suppose we have a Doom PWAD that reuses some music from
-    // Heretic. If we have the Heretic music pack loaded, then we get an
-    // automatic substitution.
-    for (i = 0; i < arrlen(subst_config_filenames); ++i)
+    // Load all music packs, by searching for .cfg files.
+    glob = I_StartGlob(musicdir, "*.cfg");
+    for (;;)
     {
-        path = M_StringJoin(musicdir, subst_config_filenames[i], NULL);
+        path = I_NextGlob(glob);
+        if (path == NULL)
+        {
+            break;
+        }
         ReadSubstituteConfig(musicdir, path);
-        free(path);
     }
+    I_EndGlob(glob);
 
     if (subst_music_len > 0)
     {