foxygit / doom Log in
commit 77ad7dc5f88eafb2d0c502957ae879fab073200d
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Wed Jan 25 20:53:30 2017 +0000
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Wed Jan 25 20:55:23 2017 +0000

    music: Add config variable for music packs path.

    The current setup where you have to extract the music packs in your
    config directory is rather awkward and inflexible. Instead, add a
    config variable 'music_pack_path' to specify where to find extracted
    music packs.

    First part of #843.
---
 src/i_sdlmusic.c | 10 +++++++++-
 src/i_sound.c    |  2 ++
 src/m_config.c   |  9 +++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index b52175b7..2eb082f4 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -111,6 +111,7 @@ static boolean sdl_was_initialized = false;
 static boolean musicpaused = false;
 static int current_music_volume;

+char *music_pack_path = "";
 char *timidity_cfg_path = "";

 static char *temp_timidity_cfg = NULL;
@@ -672,7 +673,14 @@ static void LoadSubstituteConfigs(void)
     char *path;
     unsigned int i;

-    if (!strcmp(configdir, ""))
+    // We can configure the path to music packs using the music_pack_path
+    // configuration variable. Otherwise we use the current directory, or
+    // $configdir/music to look for .cfg files.
+    if (strcmp(music_pack_path, "") != 0)
+    {
+        musicdir = M_StringJoin(music_pack_path, DIR_SEPARATOR_S, NULL);
+    }
+    else if (!strcmp(configdir, ""))
     {
         musicdir = M_StringDuplicate("");
     }
diff --git a/src/i_sound.c b/src/i_sound.c
index b55684cd..e0c912e8 100644
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -75,6 +75,7 @@ extern int opl_io_port;

 // For native music module:

+extern char *music_pack_path;
 extern char *timidity_cfg_path;

 // DOS-specific options: These are unused but should be maintained
@@ -450,6 +451,7 @@ void I_BindSoundVariables(void)
     M_BindIntVariable("opl_io_port",             &opl_io_port);
     M_BindIntVariable("snd_pitchshift",          &snd_pitchshift);

+    M_BindStringVariable("music_pack_path",      &music_pack_path);
     M_BindStringVariable("timidity_cfg_path",    &timidity_cfg_path);
     M_BindStringVariable("gus_patch_path",       &gus_patch_path);
     M_BindIntVariable("gus_ram_kb",              &gus_ram_kb);
diff --git a/src/m_config.c b/src/m_config.c
index d45b42eb..718226bc 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -888,6 +888,15 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_FLOAT(libsamplerate_scale),

+    //!
+    // Full path to a directory containing configuration files for
+    // substitute music packs. These packs contain high quality renderings
+    // of game music to be played instead of using the system's built-in
+    // MIDI playback.
+    //
+
+    CONFIG_VARIABLE_STRING(music_pack_path),
+
     //!
     // Full path to a Timidity configuration file to use for MIDI
     // playback. The file will be evaluated from the directory where