summaryrefslogtreecommitdiff
path: root/src/i_sdlmusic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/i_sdlmusic.c')
-rw-r--r--src/i_sdlmusic.c95
1 files changed, 83 insertions, 12 deletions
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index 0418e025..12167665 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -53,10 +53,73 @@ static boolean sdl_was_initialized = false;
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"
+// config file for Timidity to point to the actual config file. This
+// is needed to inject a "dir" command so that the patches are read
+// relative to the actual config file.
+
+void I_InitTimidityConfig(void)
+{
+ char *env_string;
+ char *p, *path;
+ FILE *fstream;
+
+ temp_timidity_cfg = NULL;
+
+ if (!strcmp(timidity_cfg_path, ""))
+ {
+ return;
+ }
+
+ temp_timidity_cfg = M_TempFile("timidity.cfg");
+ fstream = fopen(temp_timidity_cfg, "w");
+
+ if (fstream == NULL)
+ {
+ free(temp_timidity_cfg);
+ temp_timidity_cfg = NULL;
+ return;
+ }
+
+ p = strrchr(timidity_cfg_path, DIR_SEPARATOR);
+ if (p != NULL)
+ {
+ path = strdup(timidity_cfg_path);
+ path[p - timidity_cfg_path] = '\0';
+ fprintf(fstream, "dir %s\n", path);
+ free(path);
+ }
+
+ fprintf(fstream, "source %s\n", timidity_cfg_path);
+ fclose(fstream);
+
+ // 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);
+ free(env_string);
+}
+
+// Remove the temporary config file generated by I_InitTimidityConfig().
+
+static void RemoveTimidityConfig(void)
+{
+ if (temp_timidity_cfg != NULL)
+ {
+ remove(temp_timidity_cfg);
+ free(temp_timidity_cfg);
+ }
+}
+
// Shutdown music
static void I_SDL_ShutdownMusic(void)
-{
+{
if (music_initialized)
{
Mix_HaltMusic();
@@ -107,29 +170,37 @@ static boolean I_SDL_InitMusic(void)
// If SDL_mixer is not initialized, we have to initialize it
// and have the responsibility to shut it down later on.
- if (!SDLIsInitialized())
+ if (SDLIsInitialized())
+ {
+ music_initialized = true;
+ }
+ else
{
if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
fprintf(stderr, "Unable to set up sound.\n");
- return false;
}
-
- if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, 1024) < 0)
+ else if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, 1024) < 0)
{
- fprintf(stderr, "Error initializing SDL_mixer: %s\n", Mix_GetError());
+ fprintf(stderr, "Error initializing SDL_mixer: %s\n",
+ Mix_GetError());
SDL_QuitSubSystem(SDL_INIT_AUDIO);
- return false;
}
+ else
+ {
+ SDL_PauseAudio(0);
- SDL_PauseAudio(0);
-
- sdl_was_initialized = true;
+ sdl_was_initialized = true;
+ music_initialized = true;
+ }
}
- music_initialized = true;
+ // Once initialization is complete, the temporary Timidity config
+ // file can be removed.
+
+ RemoveTimidityConfig();
- return true;
+ return music_initialized;
}
//