Log music system info if Config.Sound.Verbose is enabled.

shapetextures
Sven Eberhardt 2015-12-02 23:08:50 -05:00
parent cc12230d56
commit cbb7b0ba2c
4 changed files with 47 additions and 0 deletions

View File

@ -294,6 +294,23 @@ bool C4MusicFileOgg::Init(const char *strFile)
return loaded = true;
}
StdStrBuf C4MusicFileOgg::GetDebugInfo() const
{
StdStrBuf result;
result.Append(FileName);
result.AppendFormat("[%.0lf]", last_playback_pos_sec);
result.AppendChar('[');
bool sec = false;
for (auto i = categories.cbegin(); i != categories.cend(); ++i)
{
if (sec) result.AppendChar(',');
result.Append(i->getData());
sec = true;
}
result.AppendChar(']');
return result;
}
void C4MusicFileOgg::UnprepareSourceFileReading()
{
// The file loader could just keep all files open. But if someone symlinks

View File

@ -50,6 +50,8 @@ public:
virtual bool HasResumePos() const { return false; }
virtual void ClearResumePos() { }
virtual StdStrBuf GetDebugInfo() const { return StdStrBuf(FileName); }
bool IsLooping() const { return loop; }
bool HasBeenAnnounced() const { return announced; }
@ -98,6 +100,7 @@ public:
double GetRemainingTime();
bool HasResumePos() const { return (last_playback_pos_sec > 0); }
void ClearResumePos() { last_playback_pos_sec = 0.0; }
virtual StdStrBuf GetDebugInfo() const;
private:
enum { num_buffers = 4, buffer_size = 160*1024 };
::C4SoundLoaders::VorbisLoader::CompressedData data;

View File

@ -34,6 +34,7 @@ C4MusicSystem::C4MusicSystem():
PlayMusicFile(NULL),
game_music_level(100),
playlist(),
playlist_valid(false),
music_break_min(DefaultMusicBreak), music_break_max(DefaultMusicBreak),
Volume(100),
is_waiting(false),
@ -212,6 +213,7 @@ void C4MusicSystem::Load(const char *szFile)
NewSong->pNext = NULL;
// count songs
SongCount++;
playlist_valid = false;
}
void C4MusicSystem::LoadDir(const char *szPath)
@ -318,6 +320,7 @@ void C4MusicSystem::ClearSongs()
}
SongCount = 0;
FadeMusicFile = upcoming_music_file = PlayMusicFile = NULL;
playlist_valid = false;
}
void C4MusicSystem::Clear()
@ -408,6 +411,12 @@ bool C4MusicSystem::Play(const char *szSongname, bool fLoop, int fadetime_ms, do
if (Game.IsRunning ? !Config.Sound.RXMusic : !Config.Sound.FEMusic)
return false;
// info
if (::Config.Sound.Verbose)
{
LogF("MusicSystem: Play(\"%s\", %s, %d, %.3lf, %s)", szSongname ? szSongname : "(null)", fLoop ? "true" : "false", fadetime_ms, max_resume_time, allow_break ? "true" : "false");
}
C4MusicFile* NewFile = NULL;
// Specified song name
@ -526,6 +535,11 @@ bool C4MusicSystem::Play(const char *szSongname, bool fLoop, int fadetime_ms, do
bool C4MusicSystem::Play(C4MusicFile *NewFile, bool fLoop, double max_resume_time)
{
// info
if (::Config.Sound.Verbose)
{
LogF("MusicSystem: PlaySong(\"%s\", %s, %.3lf)", NewFile->GetDebugInfo().getData(), fLoop ? "true" : "false", max_resume_time);
}
// Play new song directly
if (!NewFile->Play(fLoop, max_resume_time)) return false;
PlayMusicFile = NewFile;
@ -569,6 +583,10 @@ bool C4MusicSystem::ScheduleWaitTime()
{
is_waiting = true;
wait_time_end = C4TimeMilliseconds::Now() + music_break;
if (::Config.Sound.Verbose)
{
LogF("MusicSystem: Pause (%d secs)", (int)music_break);
}
// After wait, do not resume previously started songs
for (C4MusicFile *check_file = Songs; check_file; check_file = check_file->pNext)
check_file->ClearResumePos();
@ -648,6 +666,13 @@ bool C4MusicSystem::GrpContainsMusic(C4Group &rGrp)
int C4MusicSystem::SetPlayList(const char *szPlayList, bool fForceSwitch, int fadetime_ms, double max_resume_time)
{
// Shortcut if no change
if (playlist_valid && playlist == szPlayList) return 0;
// info
if (::Config.Sound.Verbose)
{
LogF("MusicSystem: SetPlayList(\"%s\", %s, %d, %.3lf)", szPlayList ? szPlayList : "(null)", fForceSwitch ? "true" : "false", fadetime_ms, max_resume_time);
}
// reset
C4MusicFile *pFile;
for (pFile = Songs; pFile; pFile = pFile->pNext)
@ -701,6 +726,7 @@ int C4MusicSystem::SetPlayList(const char *szPlayList, bool fForceSwitch, int fa
}
// Remember setting (e.g. to be saved in savegames)
playlist.Copy(szPlayList);
playlist_valid = true; // do not re-calculate available song if playlist is reset to same value in the future
return ASongCount;
}

View File

@ -97,6 +97,7 @@ private:
int32_t game_music_level;
// current play list
StdCopyStrBuf playlist;
bool playlist_valid;
// Set to nonzero to allow pauses between songs
int32_t music_break_min, music_break_max, music_break_chance;