From 7b3991f74b0e0dc6774453a59e674696560c2d93 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 3 Feb 2018 00:40:20 +0100 Subject: [PATCH] added function to get music filename by music ID - 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 | 4 ++-- src/libgame/sound.c | 10 ++++++++++ src/libgame/sound.h | 1 + src/tools.c | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/game.c b/src/game.c index ee6de4e8..a3ad6f14 100644 --- a/src/game.c +++ b/src/game.c @@ -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); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 8371b9b5..ea055503 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -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; diff --git a/src/libgame/sound.h b/src/libgame/sound.h index 8eb344ef..9d496c3c 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -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(); diff --git a/src/tools.c b/src/tools.c index 43df704a..1230cf0a 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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(); -- 2.34.1