shithub: choc

Download patch

ref: 5616ae0648ae9e11b3d9f4c889adecf0e6628a99
parent: 68a553ddb3ca81e6df0815860021ea774f6006a7
author: Simon Howard <fraggle@gmail.com>
date: Fri Oct 24 15:41:57 EDT 2014

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.

--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -1247,27 +1247,16 @@
     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();
+        Mix_PlayMusic(current_track_music, 1);
     }
-    else
-    {
-        Mix_HaltMusic();
-        current_track_music = NULL;
-        playing_substitute = false;
-    }
+
+    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
@@ -1274,7 +1263,10 @@
 // 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 @@
         }
 
         // Have we reached the actual end of track (not loop end)?
-        if (!Mix_PlayingMusic() && current_track_loop)
+        if (!Mix_PlayingMusic())
         {
             RestartCurrentTrack();
         }