added function to get music filename by music ID
authorHolger Schemel <info@artsoft.org>
Fri, 2 Feb 2018 23:40:20 +0000 (00:40 +0100)
committerHolger Schemel <info@artsoft.org>
Fri, 2 Feb 2018 23:45:37 +0000 (00:45 +0100)
- this does (still) not work correctly for negative music IDs
- negative music IDs are used for (game) music files not specified in a GIC
- handling negative music IDs will be fixed in the next commit

src/game.c
src/libgame/sound.c
src/libgame/sound.h
src/tools.c

index ee6de4e8fd13b2ee20f78413c8c628b648c6e118..a3ad6f14842b48d363b52286776b2ffa97ffd748 100644 (file)
@@ -14250,7 +14250,7 @@ static void FadeLevelMusic()
 {
   int music_nr = getLevelMusicNr();
   char *curr_music = getCurrentlyPlayingMusicFilename();
-  char *next_music = getMusicListEntry(music_nr)->filename;
+  char *next_music = getMusicInfoEntryFilename(music_nr);
 
   if (!strEqual(curr_music, next_music))
     FadeMusic();
@@ -14266,7 +14266,7 @@ static void PlayLevelMusic()
 {
   int music_nr = getLevelMusicNr();
   char *curr_music = getCurrentlyPlayingMusicFilename();
-  char *next_music = getMusicListEntry(music_nr)->filename;
+  char *next_music = getMusicInfoEntryFilename(music_nr);
 
   if (!strEqual(curr_music, next_music))
     PlayMusic(music_nr);
index 8371b9b5cd879d02b56fabe8ab4487faa2da3fe3..ea055503cbaa0204a18f0c8ba6e88b8b8fe8a82c 100644 (file)
@@ -725,6 +725,16 @@ static MusicInfo *getMusicInfoEntryFromMusicID(int pos)
   return mus_info[list_pos];
 }
 
+char *getMusicInfoEntryFilename(int pos)
+{
+  MusicInfo *mus_info = getMusicInfoEntryFromMusicID(pos);
+
+  if (mus_info == NULL)
+    return NULL;
+
+  return getBaseNamePtr(mus_info->source_filename);
+}
+
 char *getCurrentlyPlayingMusicFilename()
 {
   return currently_playing_music_filename;
index 8eb344ef2e921dfae3d8ef554d86d77784740b04..9d496c3c8b4c075c4ee5ace15f0b83e5ece50652 100644 (file)
@@ -121,6 +121,7 @@ int getSoundListSize();
 int getMusicListSize();
 struct FileInfo *getSoundListEntry(int);
 struct FileInfo *getMusicListEntry(int);
+char *getMusicInfoEntryFilename(int);
 char *getCurrentlyPlayingMusicFilename();
 int getSoundListPropertyMappingSize();
 int getMusicListPropertyMappingSize();
index 43df704a17ea08c8301600f8276b3b75b79263c2..1230cf0ab482d1e455907ffba4c854c0677b48c8 100644 (file)
@@ -8498,7 +8498,7 @@ void PlayMenuMusicExt(int music)
 void PlayMenuMusic()
 {
   char *curr_music = getCurrentlyPlayingMusicFilename();
-  char *next_music = getMusicListEntry(menu.music[game_status])->filename;
+  char *next_music = getMusicInfoEntryFilename(menu.music[game_status]);
 
   if (!strEqual(curr_music, next_music))
     PlayMenuMusicExt(menu.music[game_status]);
@@ -8518,7 +8518,7 @@ static void FadeMenuSounds()
 static void FadeMenuMusic()
 {
   char *curr_music = getCurrentlyPlayingMusicFilename();
-  char *next_music = getMusicListEntry(menu.music[game_status])->filename;
+  char *next_music = getMusicInfoEntryFilename(menu.music[game_status]);
 
   if (!strEqual(curr_music, next_music))
     FadeMusic();