diff options
Diffstat (limited to 'src/i_sdlmusic.c')
-rw-r--r-- | src/i_sdlmusic.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c index e1f9212d..79755890 100644 --- a/src/i_sdlmusic.c +++ b/src/i_sdlmusic.c @@ -36,6 +36,7 @@ #include "mus2mid.h" #include "deh_str.h" +#include "gusconf.h" #include "i_sound.h" #include "m_misc.h" #include "w_wad.h" @@ -54,6 +55,7 @@ static boolean musicpaused = false; static int current_music_volume; char *timidity_cfg_path = ""; + static char *temp_timidity_cfg = NULL; // If the temp_timidity_cfg config variable is set, generate a "wrapper" @@ -61,27 +63,21 @@ static char *temp_timidity_cfg = NULL; // is needed to inject a "dir" command so that the patches are read // relative to the actual config file. -void I_InitTimidityConfig(void) +static boolean WriteWrapperTimidityConfig(char *write_path) { - char *env_string; char *p, *path; FILE *fstream; - temp_timidity_cfg = NULL; - if (!strcmp(timidity_cfg_path, "")) { - return; + return false; } - temp_timidity_cfg = M_TempFile("timidity.cfg"); - fstream = fopen(temp_timidity_cfg, "w"); + fstream = fopen(write_path, "w"); if (fstream == NULL) { - Z_Free(temp_timidity_cfg); - temp_timidity_cfg = NULL; - return; + return false; } p = strrchr(timidity_cfg_path, DIR_SEPARATOR); @@ -96,12 +92,39 @@ void I_InitTimidityConfig(void) fprintf(fstream, "source %s\n", timidity_cfg_path); fclose(fstream); + return true; +} + +void I_InitTimidityConfig(void) +{ + char *env_string; + boolean success; + + temp_timidity_cfg = M_TempFile("timidity.cfg"); + + if (snd_musicdevice == SNDDEVICE_GUS) + { + success = GUS_WriteConfig(temp_timidity_cfg); + } + else + { + success = WriteWrapperTimidityConfig(temp_timidity_cfg); + } + // Set the TIMIDITY_CFG environment variable to point to the temporary // config file. - env_string = malloc(strlen(temp_timidity_cfg) + 15); - sprintf(env_string, "TIMIDITY_CFG=%s", temp_timidity_cfg); - putenv(env_string); + if (success) + { + env_string = malloc(strlen(temp_timidity_cfg) + 15); + sprintf(env_string, "TIMIDITY_CFG=%s", temp_timidity_cfg); + putenv(env_string); + } + else + { + Z_Free(temp_timidity_cfg); + temp_timidity_cfg = NULL; + } } // Remove the temporary config file generated by I_InitTimidityConfig(). |