diff --git a/BBGE/SoundManager.cpp b/BBGE/SoundManager.cpp index d9f5454..4dfa57c 100644 --- a/BBGE/SoundManager.cpp +++ b/BBGE/SoundManager.cpp @@ -90,6 +90,7 @@ namespace SoundCore bool stopMusicOnFadeOut=false; bool wasPlayingVoice=false; + bool playingMusicOnce=false; typedef std::list FadeChs; FadeChs fadeChs; @@ -466,7 +467,7 @@ void SoundManager::toggleEffectMusic(SoundEffectType effect, bool on) std::string SoundManager::getVolumeString() { std::ostringstream os; - os << "sfxFader: " << this->sfxFader << " sfxVol: " << this->sfxVol << std::endl; + os << "sfxFader: " << this->sfxFader << " sfxVol: " << this->sfxVol << " [" << lastMusic << "]" << std::endl; os << "musVol: " << musVol.y << " voxVol: " << voxVol.y << std::endl; float musicChannelVol = -1; @@ -657,21 +658,17 @@ void SoundManager::update(float dt) if (musicChannel) { - bool _isplaying = false; - result = musicChannel->isPlaying(&_isplaying); - checkError(); - if (!_isplaying) + if (!isPlayingMusic()) { - result = musicChannel->stop(); - checkError(); - musicChannel = 0; - - if (musicStream) + if(!playingMusicOnce && lastMusic.size()) { - result = musicStream->release(); - checkError(); - musicStream = 0; - } + debugLog("music not playing, but it should be - force restart"); + playMusic(lastMusic, SLT_LOOP, SFT_IN, 1, SCT_NORMAL); // FIXME: make sure this works with playMusicOnce() + } + else + { + stopMusic(); + } } } @@ -685,17 +682,7 @@ void SoundManager::update(float dt) if (musVol.y <= 0 && stopMusicOnFadeOut) { - result = musicChannel->stop(); - checkError(); - musicChannel = 0; - - if (musicStream) - { - result = musicStream->release(); - checkError(); - musicStream = 0; - } - + stopMusic(); stopMusicOnFadeOut = false; } } @@ -791,7 +778,6 @@ void SoundManager::fadeMusic(SoundFadeType sft, float t) case SFT_CROSS: { #ifdef BBGE_BUILD_FMODEX - if (musicChannel2) { musicChannel2->stop(); @@ -1342,9 +1328,11 @@ bool SoundManager::playMusic(const std::string &name, SoundLoopType slt, SoundFa case SLT_OFF: case SLT_NONE: mode |= FMOD_LOOP_OFF; + playingMusicOnce = true; break; default: mode |= FMOD_LOOP_NORMAL; + playingMusicOnce = false; break; } @@ -1388,18 +1376,20 @@ bool SoundManager::playMusic(const std::string &name, SoundLoopType slt, SoundFa result = musicChannel->setPaused(false); // This is where the sound really starts. checkError(); + debugLog("music play: " + fn); + } + else + { + debugLog("Failed to create music stream: " + fn); } #endif - debugLog("playmusic end"); - return true; } void SoundManager::stopMusic() { - #ifdef BBGE_BUILD_FMODEX if (musicChannel) { @@ -1414,7 +1404,7 @@ void SoundManager::stopMusic() musicChannel = 0; } #endif - + playingMusicOnce = false; lastMusic = ""; } @@ -1518,6 +1508,12 @@ Buffer SoundManager::loadSoundIntoBank(const std::string &filename, const std::s std::string f = filename, name; + // HACK: proper sound looping + bool loop = false; + stringToLower(f); + if (f.find("loop")!=std::string::npos) + loop = true; + // WARNING: local sounds should go here! debugLog(filename); @@ -1540,13 +1536,6 @@ Buffer SoundManager::loadSoundIntoBank(const std::string &filename, const std::s f = core->adjustFilenameCase(f); } - bool loop = false; - - if (filename.find("loop")!=std::string::npos) - { - loop = true; - } - int loc = f.find_last_of('/'); int loc2 = f.rfind('.'); if (loc != std::string::npos && loc2 != std::string::npos) diff --git a/BBGE/SoundManager.h b/BBGE/SoundManager.h index 83f6b77..eb9646f 100644 --- a/BBGE/SoundManager.h +++ b/BBGE/SoundManager.h @@ -213,8 +213,6 @@ public: void update(float dt); - std::string currentMusic; - bool enabled; bool checkError();