diff --git a/source/gui/WiiMovie.cpp b/source/gui/WiiMovie.cpp index d9703e3b..54d2d1ad 100644 --- a/source/gui/WiiMovie.cpp +++ b/source/gui/WiiMovie.cpp @@ -30,7 +30,6 @@ #include "wiiuse/wpad.h" #include "WiiMovie.hpp" -#include "musicplayer.h" #include "gecko.h" #include "mem2.hpp" @@ -98,8 +97,6 @@ WiiMovie::~WiiMovie() LWP_MutexDestroy(mutex); ASND_StopVoice(10); - MusicPlayer::Instance()->Play(); - if (ReadThread != LWP_THREAD_NULL) { LWP_ResumeThread(ReadThread); diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 008909af..f8257cfd 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -143,6 +143,7 @@ CMenu::CMenu(CVideo &vid) : m_current_view = COVERFLOW_USB; m_Emulator_boot = false; m_banner = new BannerWindow; + m_music = new MusicPlayer; } void CMenu::init(void) @@ -419,7 +420,7 @@ void CMenu::init(void) } m_btnMgr.init(m_vid); - MusicPlayer::Instance()->Init(m_cfg, m_musicDir, sfmt("%s/music", m_themeDataDir.c_str())); + m_music->Init(m_cfg, m_musicDir, sfmt("%s/music", m_themeDataDir.c_str())); _buildMenus(); @@ -488,7 +489,7 @@ void CMenu::cleanup(bool ios_reload) if (!ios_reload) m_cameraSound.release(); - MusicPlayer::DestroyInstance(); + m_music->cleanup(); SoundHandler::DestroyInstance(); soundDeinit(); @@ -1787,7 +1788,7 @@ void CMenu::_mainLoopCommon(bool withCF, bool blockReboot, bool adjusting) Sys_Test(); } - if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound.IsPlaying() && MusicPlayer::Instance()->GetVolume() == 0) + if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound.IsPlaying() && m_music->GetVolume() == 0) { CheckGameSoundThread(); m_gameSound.Play(m_bnrSndVol); @@ -1796,7 +1797,7 @@ void CMenu::_mainLoopCommon(bool withCF, bool blockReboot, bool adjusting) else if(!m_gameSelected) m_gameSound.Stop(); - MusicPlayer::Instance()->Tick(m_video_playing || (m_gameSelected && + m_music->Tick(m_video_playing || (m_gameSelected && m_gameSound.IsLoaded()) || m_gameSound.IsPlaying()); //Take Screenshot @@ -2217,11 +2218,11 @@ void CMenu::_stopSounds(void) // Fade out sounds int fade_rate = m_cfg.getInt("GENERAL", "music_fade_rate", 8); - if(!MusicPlayer::Instance()->IsStopped()) + if(!m_music->IsStopped()) { - while(MusicPlayer::Instance()->GetVolume() > 0 || m_gameSound.GetVolume() > 0) + while(m_music->GetVolume() > 0 || m_gameSound.GetVolume() > 0) { - MusicPlayer::Instance()->Tick(true); + m_music->Tick(true); if(m_gameSound.GetVolume() > 0) m_gameSound.SetVolume(m_gameSound.GetVolume() < fade_rate ? 0 : m_gameSound.GetVolume() - fade_rate); VIDEO_WaitVSync(); @@ -2230,7 +2231,7 @@ void CMenu::_stopSounds(void) m_btnMgr.stopSounds(); m_cf.stopSound(); - MusicPlayer::Instance()->Stop(); + m_music->Stop(); m_gameSound.Stop(); } diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index feb7fe07..7af3e31e 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -60,7 +60,7 @@ private: CVideo &m_vid; CCursor m_cursor[WPAD_MAX_WIIMOTES]; CButtonsMgr m_btnMgr; - + MusicPlayer *m_music; CCoverFlow m_cf; CFanart m_fa; CachedList m_gameList; diff --git a/source/menu/menu_configsnd.cpp b/source/menu/menu_configsnd.cpp index 9b3aab21..e27d09a3 100644 --- a/source/menu/menu_configsnd.cpp +++ b/source/menu/menu_configsnd.cpp @@ -101,14 +101,14 @@ int CMenu::_configSnd(void) int musicVol = min(m_cfg.getInt("GENERAL", "sound_volume_music", 255) + step, 255); m_cfg.setInt("GENERAL", "sound_volume_music", musicVol); _showConfigSnd(); - MusicPlayer::Instance()->SetVolume(MusicPlayer::Instance()->GetVolume(), musicVol); + m_music->SetVolume(m_music->GetVolume(), musicVol); } else if (m_btnMgr.selected(m_configSndBtnMusicVolM)) { int musicVol = max(m_cfg.getInt("GENERAL", "sound_volume_music", 255) - step, 0); m_cfg.setInt("GENERAL", "sound_volume_music", musicVol); _showConfigSnd(); - MusicPlayer::Instance()->SetVolume(MusicPlayer::Instance()->GetVolume(), musicVol); + m_music->SetVolume(m_music->GetVolume(), musicVol); } else if (m_btnMgr.selected(m_configSndBtnCFVolP)) { diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index d3ea4399..26539c35 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -461,6 +461,7 @@ void CMenu::_game(bool launch) } movie.Stop(); _showGame(); + m_music->Play(); m_video_playing = false; //m_gameSound.play(m_bnrSndVol); } diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index 69c23ce5..51fac6d8 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -273,7 +273,7 @@ int CMenu::main(void) _initAsyncNetwork(); SetupInput(true); - MusicPlayer::Instance()->Play(); + m_music->Play(); GameTDB m_gametdb; m_gametdb.OpenFile(fmt("%s/wiitdb.xml", m_settingsDir.c_str())); @@ -543,14 +543,14 @@ int CMenu::main(void) else if(BTN_MINUS_PRESSED) { if(b_lr_mode) - MusicPlayer::Instance()->Previous(); + m_music->Previous(); else m_cf.pageUp(); } else if(BTN_PLUS_PRESSED) { if(b_lr_mode) - MusicPlayer::Instance()->Next(); + m_music->Next(); else m_cf.pageDown(); } @@ -593,7 +593,7 @@ int CMenu::main(void) if(b_lr_mode) m_cf.pageUp(); else - MusicPlayer::Instance()->Previous(); + m_music->Previous(); } else if(BTN_RIGHT_PRESSED) { @@ -601,7 +601,7 @@ int CMenu::main(void) if(b_lr_mode) m_cf.pageDown(); else - MusicPlayer::Instance()->Next(); + m_music->Next(); } else if(BTN_PLUS_PRESSED && !m_locked) { diff --git a/source/menu/menu_wbfs.cpp b/source/menu/menu_wbfs.cpp index 7ee8daac..3689e5e5 100644 --- a/source/menu/menu_wbfs.cpp +++ b/source/menu/menu_wbfs.cpp @@ -432,7 +432,7 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) m_thrdMessageAdded = false; m_cf.stopCoverLoader(); _stopSounds(); - MusicPlayer::DestroyInstance(); + m_music->cleanup(); SoundHandler::DestroyInstance(); soundDeinit(); Nand::Instance()->Disable_Emu(); diff --git a/source/music/musicplayer.cpp b/source/music/musicplayer.cpp index 9360f0d8..ab2f9ba8 100644 --- a/source/music/musicplayer.cpp +++ b/source/music/musicplayer.cpp @@ -2,27 +2,22 @@ using namespace std; -MusicPlayer *MusicPlayer::instance = NULL; - -MusicPlayer *MusicPlayer::Instance() +MusicPlayer::MusicPlayer() { - if (instance == NULL) - instance = new MusicPlayer(); - - return instance; + m_music = NULL; } -void MusicPlayer::DestroyInstance() +void MusicPlayer::cleanup() { - if (instance != NULL) - delete instance; - - instance = NULL; + if (m_music != NULL) + { + m_music->Stop(); + delete m_music; + } } void MusicPlayer::Init(Config &cfg, string musicDir, string themeMusicDir) { - m_music = NULL; m_manual_stop = true; m_stopped = true; m_fade_rate = cfg.getInt("GENERAL", "music_fade_rate", 8); diff --git a/source/music/musicplayer.h b/source/music/musicplayer.h index 48a8c04f..5aa38818 100644 --- a/source/music/musicplayer.h +++ b/source/music/musicplayer.h @@ -18,12 +18,11 @@ enum MusicDirectory class MusicPlayer { public: - static MusicPlayer *Instance(); - static void DestroyInstance(); - + MusicPlayer(); + void cleanup(); void Init(Config &cfg, std::string musicDir, std::string themeMusicDir); void Tick(bool attenuate); - + void SetVolume(int volume); void SetVolume(int volume, int max_volume); int GetVolume() { return m_music != NULL ? m_music_current_volume : 0; }; @@ -39,8 +38,6 @@ public: private: ~MusicPlayer(); - static MusicPlayer *instance; - void LoadCurrentFile(); CachedList m_music_files;