fixed bug with not recognizing ".mode_loop: false" for music
authorHolger Schemel <info@artsoft.org>
Wed, 12 Sep 2018 07:04:51 +0000 (09:04 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 12 Sep 2018 07:04:51 +0000 (09:04 +0200)
Before, music was always played in loop mode, even if it was defined
with option "<music>.mode_loop: false".

Now, disabling loop mode for music in config files will indeed cause
music to be played only once.

Note: This commit changed the behaviour of the existing function
"PlayMusic()" (which always played music in loop mode before), which
will now play music only once, while a new function "PlayMusicLoop()"
was added, which always plays music in loop mode.

src/anim.c
src/game.c
src/libgame/sound.c
src/libgame/sound.h
src/main.h
src/screens.c
src/tools.c

index 0a278aa35cb36a97983be9ea1cc7b62934bb3799..1623cdc4685b6da6d5c8ae52c862e3256e41aa56 100644 (file)
@@ -917,7 +917,10 @@ static void PlayGlobalAnimMusic(struct GlobalAnimPartControlInfo *part)
   if (!setup.sound_music)
     return;
 
-  PlayMusic(music);
+  if (IS_LOOP_MUSIC(music))
+    PlayMusicLoop(music);
+  else
+    PlayMusic(music);
 
 #if 0
   printf("::: PLAY MUSIC %d.%d.%d: %d\n",
index 965e42308c307329d1b6b7a7c0e9c3599d455a81..4c9c56e8f81825e57bebbd3e92dd0f3bb6c3adaa 100644 (file)
@@ -14594,7 +14594,7 @@ static void PlayLevelMusic()
   char *next_music = getMusicInfoEntryFilename(music_nr);
 
   if (!strEqual(curr_music, next_music))
-    PlayMusic(music_nr);
+    PlayMusicLoop(music_nr);
 }
 
 void PlayLevelSound_EM(int xx, int yy, int element_em, int sample)
index 15354b68575dbc6b95b97563b996905ed17f24cb..c9a74eb1b262056ec279873861f8511148f074a4 100644 (file)
@@ -59,9 +59,9 @@
 #define SOUND_VOLUME_LOOPS(v)  SOUND_VOLUME_FROM_PERCENT(v, setup.volume_loops)
 #define SOUND_VOLUME_MUSIC(v)  SOUND_VOLUME_FROM_PERCENT(v, setup.volume_music)
 
-#define SETUP_SOUND_VOLUME(v,s)                ((s) == SND_CTRL_PLAY_MUSIC ?   \
+#define SETUP_SOUND_VOLUME(v,s)                ((s) & SND_CTRL_MUSIC ?         \
                                         SOUND_VOLUME_MUSIC(v) :        \
-                                        (s) == SND_CTRL_PLAY_LOOP ?    \
+                                        (s) & SND_CTRL_LOOP ?          \
                                         SOUND_VOLUME_LOOPS(v) :        \
                                         SOUND_VOLUME_SIMPLE(v))
 
@@ -221,10 +221,12 @@ static void Mixer_PlayMusicChannel()
 
   if (mixer[audio.music_channel].type != MUS_TYPE_WAV)
   {
+    int loops = (IS_LOOP(mixer[audio.music_channel]) ? -1 : 1);
+
     // use short fade-in to prevent "plop" sound for certain music files
     // (this may happen when switching on music while playing the game)
     Mix_VolumeMusic(mixer[audio.music_channel].volume);
-    Mix_FadeInMusic(mixer[audio.music_channel].data_ptr, -1, 100);
+    Mix_FadeInMusic(mixer[audio.music_channel].data_ptr, loops, 100);
 
 #if defined(PLATFORM_WIN32)
     // playing MIDI music is broken since Windows Vista, as it sets the volume
@@ -923,6 +925,14 @@ void PlayMusic(int nr)
   PlaySoundMusic(nr);
 }
 
+void PlayMusicLoop(int nr)
+{
+  if (!audio.music_available)
+    return;
+
+  PlaySoundMusicLoop(nr);
+}
+
 void PlaySound(int nr)
 {
   if (!setup.sound_simple)
@@ -955,6 +965,14 @@ void PlaySoundMusic(int nr)
   PlaySoundExt(nr, SOUND_MAX_VOLUME, SOUND_MIDDLE, SND_CTRL_PLAY_MUSIC);
 }
 
+void PlaySoundMusicLoop(int nr)
+{
+  if (!setup.sound_music)
+    return;
+
+  PlaySoundExt(nr, SOUND_MAX_VOLUME, SOUND_MIDDLE, SND_CTRL_PLAY_MUSIC_LOOP);
+}
+
 void PlaySoundExt(int nr, int volume, int stereo_position, int state)
 {
   SoundControl snd_ctrl;
index 9d496c3c8b4c075c4ee5ace15f0b83e5ece50652..e2d2054ae404fae4454885738b2fc9b4f93b9c56 100644 (file)
@@ -60,7 +60,8 @@
 
 #define SND_CTRL_PLAY_SOUND            (SND_CTRL_NONE)
 #define SND_CTRL_PLAY_LOOP             (SND_CTRL_LOOP)
-#define SND_CTRL_PLAY_MUSIC            (SND_CTRL_LOOP | SND_CTRL_MUSIC)
+#define SND_CTRL_PLAY_MUSIC            (SND_CTRL_MUSIC)
+#define SND_CTRL_PLAY_MUSIC_LOOP       (SND_CTRL_MUSIC | SND_CTRL_LOOP)
 
 #define SND_CTRL_FADE_SOUND            (SND_CTRL_FADE)
 #define SND_CTRL_FADE_MUSIC            (SND_CTRL_FADE | SND_CTRL_MUSIC)
@@ -102,10 +103,12 @@ void StartMixer(void);
 
 /* sound client functions */
 void PlayMusic(int);
+void PlayMusicLoop(int);
 void PlaySound(int);
 void PlaySoundStereo(int, int);
 void PlaySoundLoop(int);
 void PlaySoundMusic(int);
+void PlaySoundMusicLoop(int);
 void PlaySoundExt(int, int, int, int);
 void FadeMusic(void);
 void FadeSound(int);
index f722f9c4d0e5fc7097bb9d046fad53a798c1ad71..3c6e492ce8f6b5f8002e5ceb78828f3c41a3e1e2 100644 (file)
 #define IS_NEXT_FRAME(f, g)    (IS_NEW_FRAME(f, g) && (f) > 0)
 
 #define IS_LOOP_SOUND(s)       (sound_info[s].loop)
+#define IS_LOOP_MUSIC(s)       (music_info[s].loop)
 
 #define IS_SPECIAL_GFX_ARG(a)  ((a) >= 0 && (a) < NUM_SPECIAL_GFX_ARGS)
 
index 337bd5652fafbfb5934c884626da4f9618646d05..5e0740b6366566b53340f5d1971412ee717941bf 100644 (file)
@@ -3096,7 +3096,12 @@ void HandleInfoScreen_Music(int button)
     }
     else
     {
-      PlayMusic(list->music);
+      int music = list->music;
+
+      if (music_info[music].loop)
+       PlayMusicLoop(music);
+      else
+       PlayMusic(music);
 
       DrawTextSCentered(ystart, font_title, "The Game Background Music:");
     }
index e6f09e1c330d32f0f48fdb992fa0fa9448c8d25a..a11f692eb2d66a2abd495ceab77017d10b0de2ca 100644 (file)
@@ -9215,7 +9215,10 @@ void PlayMenuMusicExt(int music)
   if (!setup.sound_music)
     return;
 
-  PlayMusic(music);
+  if (IS_LOOP_MUSIC(music))
+    PlayMusicLoop(music);
+  else
+    PlayMusic(music);
 }
 
 void PlayMenuMusic()