openclonk/src/platform/C4MusicSystem.cpp

602 lines
13 KiB
C++
Raw Normal View History

2009-05-08 13:28:41 +00:00
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 1998-2000, Matthes Bender
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
* Copyright (c) 2009-2013, The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
* Distributed under the terms of the ISC license; see accompanying file
* "COPYING" for details.
2009-05-08 13:28:41 +00:00
*
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
* See accompanying file "TRADEMARK" for details.
2009-05-08 13:28:41 +00:00
*
* To redistribute this file separately, substitute the full license texts
* for the above references.
2009-05-08 13:28:41 +00:00
*/
2011-03-13 15:16:45 +00:00
/* Handles Music.ocg and randomly plays songs */
2009-05-08 13:28:41 +00:00
#include <C4Include.h>
#include <C4MusicSystem.h>
#include <C4Window.h>
2009-05-08 13:28:41 +00:00
#include <C4MusicFile.h>
#include <C4Application.h>
#include <C4Random.h>
#include <C4Log.h>
#include <C4Game.h>
#include <C4GraphicsSystem.h>
2009-05-08 13:28:41 +00:00
#if defined HAVE_FMOD
2009-05-08 13:28:41 +00:00
#include <fmod_errors.h>
#elif defined HAVE_LIBSDL_MIXER
2009-05-08 13:28:41 +00:00
#include <SDL.h>
#endif
#if defined(USE_OPEN_AL) && !defined(__APPLE__)
#include <AL/alut.h>
#endif
2009-05-08 13:28:41 +00:00
C4MusicSystem::C4MusicSystem():
2010-03-28 18:58:01 +00:00
Songs(NULL),
SongCount(0),
PlayMusicFile(NULL),
Volume(100)
#ifdef USE_OPEN_AL
, alcDevice(NULL), alcContext(NULL)
#endif
2010-03-28 18:58:01 +00:00
{
}
2009-05-08 13:28:41 +00:00
C4MusicSystem::~C4MusicSystem()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
Clear();
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
#ifdef USE_OPEN_AL
void C4MusicSystem::SelectContext()
{
alcMakeContextCurrent(alcContext);
}
#endif
2009-05-08 13:28:41 +00:00
bool C4MusicSystem::InitializeMOD()
{
#if defined HAVE_FMOD
2009-05-08 13:28:41 +00:00
#ifdef _WIN32
// Debug code
2010-03-28 18:58:01 +00:00
switch (Config.Sound.FMMode)
{
case 0:
FSOUND_SetOutput(FSOUND_OUTPUT_WINMM);
break;
case 1:
FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
#ifdef USE_WIN32_WINDOWS
2010-03-28 18:58:01 +00:00
FSOUND_SetHWND(Application.pWindow->hWindow);
#endif
2010-03-28 18:58:01 +00:00
break;
case 2:
FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
FSOUND_SetDriver(0);
break;
}
2009-05-08 13:28:41 +00:00
FSOUND_SetMixer(FSOUND_MIXER_QUALITY_AUTODETECT);
#endif
if (FSOUND_GetVersion() < FMOD_VERSION)
2010-03-28 18:58:01 +00:00
{
2009-05-11 13:09:53 +00:00
LogF("FMod: You are using the wrong DLL version! You should be using %.02f", FMOD_VERSION);
return false;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
if (!FSOUND_Init(44100, 32, 0))
2010-03-28 18:58:01 +00:00
{
2009-05-11 13:09:53 +00:00
LogF("FMod: %s", FMOD_ErrorString(FSOUND_GetError()));
return false;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// ok
MODInitialized = true;
return true;
#elif defined HAVE_LIBSDL_MIXER
2009-05-08 13:28:41 +00:00
SDL_version compile_version;
const SDL_version * link_version;
MIX_VERSION(&compile_version);
link_version=Mix_Linked_Version();
LogF("SDL_mixer runtime version is %d.%d.%d (compiled with %d.%d.%d)",
2010-03-28 18:58:01 +00:00
link_version->major, link_version->minor, link_version->patch,
compile_version.major, compile_version.minor, compile_version.patch);
2009-05-08 13:28:41 +00:00
if (!SDL_WasInit(SDL_INIT_AUDIO) && SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE))
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
LogF("SDL: %s", SDL_GetError());
return false;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
//frequency, format, stereo, chunksize
2010-03-28 18:58:01 +00:00
if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 1024))
{
2009-05-08 13:28:41 +00:00
LogF("SDL_mixer: %s", SDL_GetError());
return false;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
MODInitialized = true;
return true;
#elif defined(USE_OPEN_AL)
alcDevice = alcOpenDevice(NULL);
if (!alcDevice)
{
LogF("Sound system: OpenAL create context error");
return false;
}
alcContext = alcCreateContext(alcDevice, NULL);
if (!alcContext)
{
LogF("Sound system: OpenAL create context error");
return false;
}
#ifndef __APPLE__
if (!alutInitWithoutContext(NULL, NULL))
{
LogF("Sound system: ALUT init error");
return false;
}
#endif
MODInitialized = true;
return true;
2009-05-08 13:28:41 +00:00
#endif
return false;
}
void C4MusicSystem::DeinitializeMOD()
{
#if defined HAVE_FMOD
2009-05-08 13:28:41 +00:00
FSOUND_StopSound(FSOUND_ALL); /* to prevent some hangs in FMOD */
#ifdef DEBUG
Sleep(0);
#endif
FSOUND_Close();
#elif defined HAVE_LIBSDL_MIXER
2009-05-08 13:28:41 +00:00
Mix_CloseAudio();
SDL_Quit();
#elif defined(USE_OPEN_AL)
#ifndef __APPLE__
alutExit();
#endif
alcDestroyContext(alcContext);
alcCloseDevice(alcDevice);
alcContext = NULL;
alcDevice = NULL;
2009-05-08 13:28:41 +00:00
#endif
MODInitialized = false;
2009-05-08 13:28:41 +00:00
}
bool C4MusicSystem::Init(const char * PlayList)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// init mod
2010-03-28 18:58:01 +00:00
if (!MODInitialized && !InitializeMOD()) return false;
2009-05-08 13:28:41 +00:00
// Might be reinitialisation
ClearSongs();
// Global music file
LoadDir(Config.AtSystemDataPath(C4CFN_Music));
// User music file
LoadDir(Config.AtUserDataPath(C4CFN_Music));
// read MoreMusic.txt
LoadMoreMusic();
// set play list
if (PlayList) SetPlayList(PlayList); else SetPlayList(0);
// set initial volume
SetVolume(Config.Sound.MusicVolume);
// ok
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4MusicSystem::InitForScenario(C4Group & hGroup)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// check if the scenario contains music
bool fLocalMusic = false;
StdStrBuf MusicDir;
if (GrpContainsMusic(hGroup))
{
// clear global songs
ClearSongs();
fLocalMusic = true;
// add songs
MusicDir.Take(Game.ScenarioFile.GetFullName());
LoadDir(MusicDir.getData());
// log
LogF(LoadResStr("IDS_PRC_LOCALMUSIC"), MusicDir.getData());
2009-05-08 13:28:41 +00:00
}
// check for music folders in group set
C4Group *pMusicFolder = NULL;
2010-03-28 18:58:01 +00:00
while ((pMusicFolder = Game.GroupSet.FindGroup(C4GSCnt_Music, pMusicFolder)))
{
2009-05-08 13:28:41 +00:00
if (!fLocalMusic)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// clear global songs
ClearSongs();
fLocalMusic = true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// add songs
MusicDir.Take(pMusicFolder->GetFullName());
MusicDir.AppendChar(DirectorySeparator);
MusicDir.Append(C4CFN_Music);
LoadDir(MusicDir.getData());
// log
LogF(LoadResStr("IDS_PRC_LOCALMUSIC"), MusicDir.getData());
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// no music?
2010-03-28 18:58:01 +00:00
if (!SongCount) return false;
2009-05-08 13:28:41 +00:00
// set play list
SetPlayList(0);
// ok
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4MusicSystem::Load(const char *szFile)
{
// safety
if (!szFile || !*szFile) return;
C4MusicFile *NewSong=NULL;
// get extension
#if defined HAVE_FMOD
2009-05-08 13:28:41 +00:00
const char *szExt = GetExtension(szFile);
// get type
switch (GetMusicFileTypeByExtension(GetExtension(szFile)))
2010-03-28 18:58:01 +00:00
{
case MUSICTYPE_MOD:
if (MODInitialized) NewSong = new C4MusicFileMOD;
break;
case MUSICTYPE_MP3:
if (MODInitialized) NewSong = new C4MusicFileMP3;
break;
case MUSICTYPE_OGG:
if (MODInitialized) NewSong = new C4MusicFileOgg;
break;
case MUSICTYPE_MID:
if (MODInitialized)
NewSong = new C4MusicFileMID;
break;
2010-04-28 21:43:25 +00:00
default: return; // safety
2010-03-28 18:58:01 +00:00
}
#elif defined HAVE_LIBSDL_MIXER
2009-05-08 13:28:41 +00:00
if (GetMusicFileTypeByExtension(GetExtension(szFile)) == MUSICTYPE_UNKNOWN) return;
NewSong = new C4MusicFileSDL;
#endif
// unrecognized type/mod not initialized?
if (!NewSong) return;
// init music file
NewSong->Init(szFile);
// add song to list (push back)
C4MusicFile *pCurr = Songs;
2010-03-28 18:58:01 +00:00
while (pCurr && pCurr->pNext) pCurr = pCurr->pNext;
if (pCurr) pCurr->pNext = NewSong; else Songs = NewSong;
2009-05-08 13:28:41 +00:00
NewSong->pNext = NULL;
// count songs
SongCount++;
}
void C4MusicSystem::LoadDir(const char *szPath)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
char Path[_MAX_FNAME + 1], File[_MAX_FNAME + 1];
C4Group *pDirGroup = NULL;
// split path
SCopy(szPath, Path, _MAX_FNAME);
char *pFileName = GetFilename(Path);
SCopy(pFileName, File);
*(pFileName - 1) = 0;
// no file name?
2010-03-28 18:58:01 +00:00
if (!File[0])
2009-05-08 13:28:41 +00:00
// -> add the whole directory
SCopy("*", File);
// no wildcard match?
2010-03-28 18:58:01 +00:00
else if (!SSearch(File, "*?"))
{
2009-05-08 13:28:41 +00:00
// then it's either a file or a directory - do the test with C4Group
pDirGroup = new C4Group();
2010-03-28 18:58:01 +00:00
if (!pDirGroup->Open(szPath))
{
2009-05-08 13:28:41 +00:00
// so it must be a file
2010-03-28 18:58:01 +00:00
if (!pDirGroup->Open(Path))
{
2009-05-08 13:28:41 +00:00
// -> file/dir doesn't exist
LogF("Music File not found: %s", szPath);
delete pDirGroup;
return;
}
2010-03-28 18:58:01 +00:00
// mother group is open... proceed with normal handling
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// ok, set wildcard (load the whole directory)
SCopy(szPath, Path);
SCopy("*", File);
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// open directory group, if not already done so
2010-03-28 18:58:01 +00:00
if (!pDirGroup)
2009-05-08 13:28:41 +00:00
{
pDirGroup = new C4Group();
2010-03-28 18:58:01 +00:00
if (!pDirGroup->Open(Path))
2009-05-08 13:28:41 +00:00
{
LogF("Music File not found: %s", szPath);
delete pDirGroup;
return;
}
}
// search file(s)
char szFile[_MAX_FNAME + 1];
pDirGroup->ResetSearch();
2010-03-28 18:58:01 +00:00
while (pDirGroup->FindNextEntry(File, szFile))
2009-05-08 13:28:41 +00:00
{
char strFullPath[_MAX_FNAME + 1];
sprintf(strFullPath, "%s%c%s", Path, DirectorySeparator, szFile);
Load(strFullPath);
}
// free it
delete pDirGroup;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4MusicSystem::LoadMoreMusic()
2010-03-28 18:58:01 +00:00
{
2011-06-19 14:35:06 +00:00
StdStrBuf MoreMusicFile;
2009-05-08 13:28:41 +00:00
// load MoreMusic.txt
2011-06-19 14:35:06 +00:00
if (!MoreMusicFile.LoadFromFile(Config.AtUserDataPath(C4CFN_MoreMusic))) return;
2009-05-08 13:28:41 +00:00
// read contents
2011-06-19 14:35:06 +00:00
char *pPos = MoreMusicFile.getMData();
2010-03-28 18:58:01 +00:00
while (pPos && *pPos)
{
2009-05-08 13:28:41 +00:00
// get line
char szLine[1024 + 1];
SCopyUntil(pPos, szLine, '\n', 1024);
2010-03-28 18:58:01 +00:00
pPos = strchr(pPos, '\n'); if (pPos) pPos++;
2009-05-08 13:28:41 +00:00
// remove leading whitespace
char *pLine = szLine;
2010-03-28 18:58:01 +00:00
while (*pLine == ' ' || *pLine == '\t' || *pLine == '\r') pLine++;
2009-05-08 13:28:41 +00:00
// and whitespace at end
char *p = pLine + strlen(pLine) - 1;
2010-03-28 18:58:01 +00:00
while (*p == ' ' || *p == '\t' || *p == '\r') { *p = 0; --p; }
2009-05-08 13:28:41 +00:00
// comment?
2010-03-28 18:58:01 +00:00
if (*pLine == '#')
2009-05-08 13:28:41 +00:00
{
// might be a "directive"
2010-03-28 18:58:01 +00:00
if (SEqual(pLine, "#clear"))
2009-05-08 13:28:41 +00:00
ClearSongs();
continue;
}
// try to load file(s)
LoadDir(pLine);
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4MusicSystem::ClearSongs()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
Stop();
2010-03-28 18:58:01 +00:00
while (Songs)
{
2009-05-08 13:28:41 +00:00
C4MusicFile *pFile = Songs;
Songs = pFile->pNext;
delete pFile;
}
2010-03-28 18:58:01 +00:00
SongCount = 0;
}
2009-05-08 13:28:41 +00:00
void C4MusicSystem::Clear()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
#ifdef HAVE_LIBSDL_MIXER
// Stop a fadeout
Mix_HaltMusic();
#endif
ClearSongs();
2010-03-28 18:58:01 +00:00
if (MODInitialized) { DeinitializeMOD(); }
}
2009-05-08 13:28:41 +00:00
void C4MusicSystem::Execute()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
#ifndef HAVE_LIBSDL_MIXER
if (!::Game.iTick35)
2009-05-08 13:28:41 +00:00
#endif
2010-04-28 21:43:25 +00:00
{
if (!PlayMusicFile)
Play();
else
PlayMusicFile->CheckIfPlaying();
2010-04-28 21:43:25 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4MusicSystem::Play(const char *szSongname, bool fLoop)
2010-03-28 18:58:01 +00:00
{
if (Game.IsRunning ? !Config.Sound.RXMusic : !Config.Sound.FEMusic)
return false;
2009-05-08 13:28:41 +00:00
C4MusicFile* NewFile = NULL;
// Specified song name
if (szSongname && szSongname[0])
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Search in list
for (NewFile=Songs; NewFile; NewFile = NewFile->pNext)
2010-03-28 18:58:01 +00:00
{
char songname[_MAX_FNAME+1];
SCopy(szSongname, songname); DefaultExtension(songname, "mid");
if (SEqual(GetFilename(NewFile->FileName), songname))
break;
SCopy(szSongname, songname); DefaultExtension(songname, "ogg");
if (SEqual(GetFilename(NewFile->FileName), songname))
break;
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Random song
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// try to find random song
for (int i = 0; i <= 1000; i++)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
int nmb = SafeRandom(Max(ASongCount / 2 + ASongCount % 2, ASongCount - SCounter));
int j;
2010-03-28 18:58:01 +00:00
for (j = 0, NewFile = Songs; NewFile; NewFile = NewFile->pNext)
if (!NewFile->NoPlay)
if (NewFile->LastPlayed == -1 || NewFile->LastPlayed < SCounter - ASongCount / 2)
{
2009-05-08 13:28:41 +00:00
j++;
2010-03-28 18:58:01 +00:00
if (j > nmb) break;
}
2009-05-08 13:28:41 +00:00
if (NewFile) break;
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// File found?
if (!NewFile)
return false;
2009-05-08 13:28:41 +00:00
// Stop old music
Stop();
LogF(LoadResStr("IDS_PRC_PLAYMUSIC"), GetFilename(NewFile->FileName));
// Play new song
2010-03-28 18:58:01 +00:00
if (!NewFile->Play(fLoop)) return false;
2009-05-08 13:28:41 +00:00
PlayMusicFile = NewFile;
NewFile->LastPlayed = SCounter++;
Loop = fLoop;
// Set volume
PlayMusicFile->SetVolume(Volume);
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4MusicSystem::NotifySuccess()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// nothing played?
if (!PlayMusicFile) return;
// loop?
if (Loop)
if (PlayMusicFile->Play())
return;
// stop
Stop();
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4MusicSystem::FadeOut(int fadeout_ms)
2010-03-28 18:58:01 +00:00
{
if (PlayMusicFile)
2009-05-08 13:28:41 +00:00
{
PlayMusicFile->Stop(fadeout_ms);
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4MusicSystem::Stop()
2010-03-28 18:58:01 +00:00
{
if (PlayMusicFile)
2009-05-08 13:28:41 +00:00
{
PlayMusicFile->Stop();
PlayMusicFile=NULL;
}
2010-03-28 18:58:01 +00:00
return true;
}
2009-05-08 13:28:41 +00:00
int C4MusicSystem::SetVolume(int iLevel)
2010-03-28 18:58:01 +00:00
{
if (iLevel > 100) iLevel = 100;
if (iLevel < 0) iLevel = 0;
2009-05-08 13:28:41 +00:00
// Save volume for next file
Volume = iLevel;
// Tell it to the act file
2010-03-28 18:58:01 +00:00
if (PlayMusicFile)
2009-05-08 13:28:41 +00:00
PlayMusicFile->SetVolume(iLevel);
return iLevel;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
MusicType GetMusicFileTypeByExtension(const char* ext)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
if (SEqualNoCase(ext, "mid"))
return MUSICTYPE_MID;
#if defined HAVE_FMOD || defined HAVE_LIBSDL_MIXER
2009-05-08 13:28:41 +00:00
else if (SEqualNoCase(ext, "xm") || SEqualNoCase(ext, "it") || SEqualNoCase(ext, "s3m") || SEqualNoCase(ext, "mod"))
return MUSICTYPE_MOD;
#ifdef USE_MP3
else if (SEqualNoCase(ext, "mp3"))
return MUSICTYPE_MP3;
#endif
#endif
else if (SEqualNoCase(ext, "ogg"))
return MUSICTYPE_OGG;
return MUSICTYPE_UNKNOWN;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4MusicSystem::GrpContainsMusic(C4Group &rGrp)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// search for known file extensions
return rGrp.FindEntry("*.mid")
#ifdef USE_MP3
2010-03-28 18:58:01 +00:00
|| rGrp.FindEntry("*.mp3")
2009-05-08 13:28:41 +00:00
#endif
2010-03-28 18:58:01 +00:00
|| rGrp.FindEntry("*.xm")
|| rGrp.FindEntry("*.it")
|| rGrp.FindEntry("*.s3m")
|| rGrp.FindEntry("*.mod")
|| rGrp.FindEntry("*.ogg");
}
2009-05-08 13:28:41 +00:00
int C4MusicSystem::SetPlayList(const char *szPlayList)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// reset
C4MusicFile *pFile;
2010-03-28 18:58:01 +00:00
for (pFile = Songs; pFile; pFile = pFile->pNext)
{
pFile->NoPlay = true;
2009-05-08 13:28:41 +00:00
pFile->LastPlayed = -1;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
ASongCount = 0;
SCounter = 0;
2010-03-28 18:58:01 +00:00
if (szPlayList && *szPlayList)
{
2009-05-08 13:28:41 +00:00
// match
char szFileName[_MAX_FNAME + 1];
2010-03-28 18:58:01 +00:00
for (int cnt = 0; SGetModule(szPlayList, cnt, szFileName, _MAX_FNAME); cnt++)
for (pFile = Songs; pFile; pFile = pFile->pNext)
if (pFile->NoPlay && WildcardMatch(szFileName, GetFilename(pFile->FileName)))
{
2009-05-08 13:28:41 +00:00
ASongCount++;
pFile->NoPlay = false;
2010-03-28 18:58:01 +00:00
}
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// default: all files except the ones beginning with an at ('@')
// Ignore frontend and credits music
2010-03-28 18:58:01 +00:00
for (pFile = Songs; pFile; pFile = pFile->pNext)
if (*GetFilename(pFile->FileName) != '@' &&
!SEqual2(GetFilename(pFile->FileName), "Credits.") &&
!SEqual2(GetFilename(pFile->FileName), "Frontend."))
{
2009-05-08 13:28:41 +00:00
ASongCount++;
pFile->NoPlay = false;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
}
2010-03-28 18:58:01 +00:00
return ASongCount;
}
2009-05-08 13:28:41 +00:00
bool C4MusicSystem::ToggleOnOff()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// // command key for music toggle pressed
// use different settings for game/menu (lobby also counts as "menu", so go by Game.IsRunning-flag rather than startup)
if (Game.IsRunning)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// game music
Config.Sound.RXMusic = !Config.Sound.RXMusic;
if (!Config.Sound.RXMusic) Stop(); else Play();
::GraphicsSystem.FlashMessageOnOff(LoadResStr("IDS_CTL_MUSIC"), !!Config.Sound.RXMusic);
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
else
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// game menu
Config.Sound.FEMusic = !Config.Sound.FEMusic;
if (!Config.Sound.FEMusic) Stop(); else Play();
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// key processed
return true;
2010-03-28 18:58:01 +00:00
}