foxygit / doom Log in
commit f4abf51e5c0c6dc4768e38fb2958d21e01af797a
Author:     Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Wed Nov 22 20:46:04 2017 +0100
Commit:     Fabian Greffrath <fabian@greffrath.com>
CommitDate: Wed Nov 22 20:46:04 2017 +0100

    i_sdlmusic: avoid code duplication and code path splitting
---
 src/i_midipipe.h |  6 ++++++
 src/i_sdlmusic.c | 21 +++------------------
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/src/i_midipipe.h b/src/i_midipipe.h
index 2700d96d..72f26381 100644
--- a/src/i_midipipe.h
+++ b/src/i_midipipe.h
@@ -36,6 +36,12 @@ void I_MidiPipe_ShutdownServer();

 boolean I_MidiPipe_InitServer();

+#else
+
+#include "doomtype.h"
+
+static const boolean midi_server_registered = false;
+
 #endif

 #endif
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index 1b658a3e..67c01b9d 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -1030,11 +1030,7 @@ static void I_SDL_PlaySong(void *handle, boolean looping)
         return;
     }

-#if defined(_WIN32)
     if (handle == NULL && !midi_server_registered)
-#else
-    if (handle == NULL)
-#endif
     {
         return;
     }
@@ -1067,12 +1063,10 @@ static void I_SDL_PlaySong(void *handle, boolean looping)
         I_MidiPipe_PlaySong(loops);
     }
     else
+#endif
     {
         Mix_PlayMusic(current_track_music, loops);
     }
-#else
-    Mix_PlayMusic(current_track_music, loops);
-#endif
 }

 static void I_SDL_PauseSong(void)
@@ -1112,12 +1106,10 @@ static void I_SDL_StopSong(void)
         I_MidiPipe_StopSong();
     }
     else
+#endif
     {
         Mix_HaltMusic();
     }
-#else
-    Mix_HaltMusic();
-#endif

     playing_substitute = false;
     current_track_music = NULL;
@@ -1242,6 +1234,7 @@ static void *I_SDL_RegisterSong(void *data, int len)
         }
     }
     else
+#endif
     {
         music = Mix_LoadMUS(filename);
         if (music == NULL)
@@ -1250,14 +1243,6 @@ static void *I_SDL_RegisterSong(void *data, int len)
             fprintf(stderr, "Error loading midi: %s\n", Mix_GetError());
         }
     }
-#else
-    music = Mix_LoadMUS(filename);
-    if (music == NULL)
-    {
-        // Failed to load
-        fprintf(stderr, "Error loading midi: %s\n", Mix_GetError());
-    }
-#endif

     // Remove the temporary MIDI file; however, when using an external
     // MIDI program we can't delete the file. Otherwise, the program