foxygit / doom Log in
commit 5616ae0648ae9e11b3d9f4c889adecf0e6628a99
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Fri Oct 24 19:41:57 2014 -0400
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Fri Oct 24 19:41:57 2014 -0400

    Ignore loop tags on non-looping substitute tracks.

    If a substitute music track is played in a non-looping configuration
    (eg. the title screen music), ignore loop tags in the file to be
    consistent with other source ports. This fixes a bug that was discussed
    on #245.
---
 src/i_sdlmusic.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index cca41322..16c5d517 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -1247,34 +1247,26 @@ static void RestartCurrentTrack(void)
     double start = (double) file_metadata.start_time
                  / file_metadata.samplerate_hz;

-    // If the track is playing on loop then reset to the start point.
-    // Otherwise we need to stop the track.
-    if (current_track_loop)
+    // If the track finished we need to restart it.
+    if (current_track_music != NULL)
     {
-        // If the track finished we need to restart it.
-        if (current_track_music != NULL)
-        {
-            Mix_PlayMusic(current_track_music, 1);
-        }
-
-        Mix_SetMusicPosition(start);
-        SDL_LockAudio();
-        current_track_pos = file_metadata.start_time;
-        SDL_UnlockAudio();
-    }
-    else
-    {
-        Mix_HaltMusic();
-        current_track_music = NULL;
-        playing_substitute = false;
+        Mix_PlayMusic(current_track_music, 1);
     }
+
+    Mix_SetMusicPosition(start);
+    SDL_LockAudio();
+    current_track_pos = file_metadata.start_time;
+    SDL_UnlockAudio();
 }

 // Poll music position; if we have passed the loop point end position
 // then we need to go back.
 static void I_SDL_PollMusic(void)
 {
-    if (playing_substitute && file_metadata.valid)
+    // When playing substitute tracks, loop tags only apply if we're playing
+    // a looping track. Tracks like the title screen music have the loop
+    // tags ignored.
+    if (current_track_loop && playing_substitute && file_metadata.valid)
     {
         double end = (double) file_metadata.end_time
                    / file_metadata.samplerate_hz;
@@ -1286,7 +1278,7 @@ static void I_SDL_PollMusic(void)
         }

         // Have we reached the actual end of track (not loop end)?
-        if (!Mix_PlayingMusic() && current_track_loop)
+        if (!Mix_PlayingMusic())
         {
             RestartCurrentTrack();
         }