shithub: choc

Download patch

ref: 1ba7b1ddfd66e1ec98e4c47a79c3facbd84a7495
parent: 02a491c087794f1e170adc3eadcc9375c8d7be29
author: Simon Howard <[email protected]>
date: Sat Oct 15 12:58:31 EDT 2005

Fix MIDI music not pausing when using SDL_mixer's native MIDI playback.
The SDL_mixer native MIDI code does not pause music properly - use
a workaround of setting the volume to 0.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 196

--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@
      * Crash when switching applications while running fullscreen
      * Lost soul bounce logic (do not bounce in Registered/Shareware)
      * Mouse buttons mapped incorrectly (button 1 is right, 2 is middle)
+     * Music not pausing when game is paused, when using SDL_mixer's 
+       native MIDI playback.
 
 0.1.0 (2005-10-09):
     Dehacked support
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_sound.c 152 2005-10-02 20:23:04Z fraggle $
+// $Id: i_sound.c 196 2005-10-15 16:58:31Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.21  2005/10/15 16:58:31  fraggle
+// Fix MIDI music not pausing when using SDL_mixer's native MIDI playback.
+// The SDL_mixer native MIDI code does not pause music properly - use
+// a workaround of setting the volume to 0.
+//
 // Revision 1.20  2005/10/02 20:23:04  fraggle
 // Guard against music lumps containing non-MUS data, document in bugs list
 //
@@ -96,7 +101,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_sound.c 152 2005-10-02 20:23:04Z fraggle $";
+rcsid[] = "$Id: i_sound.c 196 2005-10-15 16:58:31Z fraggle $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -270,16 +275,7 @@
     snd_SfxVolume = volume;
 }
 
-// MUSIC API - dummy. Some code from DOS version.
-void I_SetMusicVolume(int volume)
-{
-    // Internal state variable.
-    snd_MusicVolume = volume;
 
-    Mix_VolumeMusic((volume * MIX_MAX_VOLUME) / 15);
-}
-
-
 //
 // Retrieve the raw data lump index
 //  for a given SFX name.
@@ -505,7 +501,34 @@
 
 static int	looping=0;
 static int	musicdies=-1;
+static boolean  musicpaused = false;
 
+//
+// SDL_mixer's native MIDI music playing does not pause properly.
+// As a workaround, set the volume to 0 when paused.
+//
+
+static void UpdateMusicVolume(void)
+{
+    int vol;
+
+    if (musicpaused)
+        vol = 0;
+    else
+        vol = (snd_MusicVolume * MIX_MAX_VOLUME) / 15;
+
+    Mix_VolumeMusic(vol);
+}
+
+// MUSIC API - dummy. Some code from DOS version.
+void I_SetMusicVolume(int volume)
+{
+    // Internal state variable.
+    snd_MusicVolume = volume;
+
+    UpdateMusicVolume();
+}
+
 void I_PlaySong(void *handle, int looping)
 {
     Mix_Music *music = (Mix_Music *) handle;
@@ -530,7 +553,9 @@
     if (!music_initialised)
         return;
 
-    Mix_PauseMusic();
+    musicpaused = true;
+
+    UpdateMusicVolume();
 }
 
 void I_ResumeSong (void *handle)
@@ -538,7 +563,9 @@
     if (!music_initialised)
         return;
 
-    Mix_ResumeMusic();
+    musicpaused = false;
+
+    UpdateMusicVolume();
 }
 
 void I_StopSong(void *handle)