-fixed the background music issue FINALLY the correct way, found

the core of the problem :D
-made background music code easier and smaller, cleaned it up
This commit is contained in:
fix94.1 2012-08-15 22:33:54 +00:00
parent 6963b0c637
commit 5cef9d88e6
10 changed files with 102 additions and 168 deletions

View File

@ -140,12 +140,12 @@ CMenu::CMenu(CVideo &vid) :
m_initialCoverStatusComplete = false; m_initialCoverStatusComplete = false;
m_reload = false; m_reload = false;
m_gamesound_changed = false; m_gamesound_changed = false;
m_video_playing = false;
m_base_font_size = 0; m_base_font_size = 0;
m_current_view = COVERFLOW_USB; m_current_view = COVERFLOW_USB;
m_Emulator_boot = false; m_Emulator_boot = false;
m_banner = new BannerWindow; m_banner = new BannerWindow;
m_music = new MusicPlayer; //Voice 0 m_gameSound.SetVoice(1);
m_gameSound = new GuiSound; //Voice 1
} }
void CMenu::init(void) void CMenu::init(void)
@ -437,7 +437,7 @@ void CMenu::init(void)
} }
m_btnMgr.init(m_vid); m_btnMgr.init(m_vid);
m_music->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(); _buildMenus();
@ -502,7 +502,7 @@ void CMenu::cleanup(bool hb)
m_plugin.Cleanup(); m_plugin.Cleanup();
_stopSounds(); _stopSounds();
delete m_music; m_music.cleanup();
m_cameraSound.release(); m_cameraSound.release();
ClearGameSoundThreadStack(); ClearGameSoundThreadStack();
SoundHandler::DestroyInstance(); SoundHandler::DestroyInstance();
@ -1814,17 +1814,17 @@ void CMenu::_mainLoopCommon(bool withCF, bool blockReboot, bool adjusting)
Sys_Test(); Sys_Test();
} }
if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound->IsPlaying() && m_music->GetVolume() == 0) if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound.IsPlaying() && m_music.GetVolume() == 0)
{ {
CheckGameSoundThread(); CheckGameSoundThread();
m_gameSound->Play(m_bnrSndVol); m_gameSound.Play(m_bnrSndVol);
m_gamesound_changed = false; m_gamesound_changed = false;
} }
else if(!m_gameSelected) else if(!m_gameSelected)
m_gameSound->Stop(); m_gameSound.Stop();
m_music->Tick(m_video_playing || (m_gameSelected && m_music.Tick(m_video_playing || (m_gameSelected &&
m_gameSound->IsLoaded()) || m_gameSound->IsPlaying()); m_gameSound.IsLoaded()) || m_gameSound.IsPlaying());
//Take Screenshot //Take Screenshot
if(gc_btnsPressed & PAD_TRIGGER_Z) if(gc_btnsPressed & PAD_TRIGGER_Z)
@ -2243,21 +2243,21 @@ void CMenu::_stopSounds(void)
// Fade out sounds // Fade out sounds
int fade_rate = m_cfg.getInt("GENERAL", "music_fade_rate", 8); int fade_rate = m_cfg.getInt("GENERAL", "music_fade_rate", 8);
if(!m_music->IsStopped()) if(!m_music.IsStopped())
{ {
while(m_music->GetVolume() > 0 || m_gameSound->GetVolume() > 0) while(m_music.GetVolume() > 0 || m_gameSound.GetVolume() > 0)
{ {
m_music->Tick(true); m_music.Tick(true);
if(m_gameSound->GetVolume() > 0) if(m_gameSound.GetVolume() > 0)
m_gameSound->SetVolume(m_gameSound->GetVolume() < fade_rate ? 0 : m_gameSound->GetVolume() - fade_rate); m_gameSound.SetVolume(m_gameSound.GetVolume() < fade_rate ? 0 : m_gameSound.GetVolume() - fade_rate);
VIDEO_WaitVSync(); VIDEO_WaitVSync();
} }
} }
m_btnMgr.stopSounds(); m_btnMgr.stopSounds();
m_cf.stopSound(); m_cf.stopSound();
m_music->Stop(); m_music.Stop();
m_gameSound->Stop(); m_gameSound.Stop();
} }
bool CMenu::_loadFile(SmartBuf &buffer, u32 &size, const char *path, const char *file) bool CMenu::_loadFile(SmartBuf &buffer, u32 &size, const char *path, const char *file)

View File

@ -678,7 +678,7 @@ private:
volatile float m_fileProgress; volatile float m_fileProgress;
volatile bool m_thrdMessageAdded; volatile bool m_thrdMessageAdded;
volatile bool m_gameSelected; volatile bool m_gameSelected;
GuiSound *m_gameSound; GuiSound m_gameSound;
SmartGuiSound m_cameraSound; SmartGuiSound m_cameraSound;
dir_discHdr *m_gameSoundHdr; dir_discHdr *m_gameSoundHdr;
lwp_t m_gameSoundThread; lwp_t m_gameSoundThread;

View File

@ -101,14 +101,14 @@ int CMenu::_configSnd(void)
int musicVol = min(m_cfg.getInt("GENERAL", "sound_volume_music", 255) + step, 255); int musicVol = min(m_cfg.getInt("GENERAL", "sound_volume_music", 255) + step, 255);
m_cfg.setInt("GENERAL", "sound_volume_music", musicVol); m_cfg.setInt("GENERAL", "sound_volume_music", musicVol);
_showConfigSnd(); _showConfigSnd();
m_music->SetVolume(m_music->GetVolume(), musicVol); m_music.SetVolume(musicVol);
} }
else if (m_btnMgr.selected(m_configSndBtnMusicVolM)) else if (m_btnMgr.selected(m_configSndBtnMusicVolM))
{ {
int musicVol = max(m_cfg.getInt("GENERAL", "sound_volume_music", 255) - step, 0); int musicVol = max(m_cfg.getInt("GENERAL", "sound_volume_music", 255) - step, 0);
m_cfg.setInt("GENERAL", "sound_volume_music", musicVol); m_cfg.setInt("GENERAL", "sound_volume_music", musicVol);
_showConfigSnd(); _showConfigSnd();
m_music->SetVolume(m_music->GetVolume(), musicVol); m_music.SetVolume(musicVol);
} }
else if (m_btnMgr.selected(m_configSndBtnCFVolP)) else if (m_btnMgr.selected(m_configSndBtnCFVolP))
{ {

View File

@ -419,13 +419,13 @@ void CMenu::_game(bool launch)
m_banner->DeleteBanner(); m_banner->DeleteBanner();
_CategorySettings(true); _CategorySettings(true);
_showGame(); _showGame();
if (!m_gameSound->IsPlaying()) if(!m_gameSound.IsPlaying())
startGameSound = -6; startGameSound = -6;
continue; continue;
} }
if(BTN_HOME_PRESSED || BTN_B_PRESSED) if(BTN_HOME_PRESSED || BTN_B_PRESSED)
{ {
m_gameSound->FreeMemory(); m_gameSound.FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack(); ClearGameSoundThreadStack();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
@ -438,7 +438,7 @@ void CMenu::_game(bool launch)
m_gameSelected = true; m_gameSelected = true;
_gameinfo(); _gameinfo();
_showGame(); _showGame();
if (!m_gameSound->IsPlaying()) if(!m_gameSound.IsPlaying())
startGameSound = -6; startGameSound = -6;
} }
else if(BTN_MINUS_PRESSED) else if(BTN_MINUS_PRESSED)
@ -467,7 +467,7 @@ void CMenu::_game(bool launch)
} }
movie.Stop(); movie.Stop();
_showGame(); _showGame();
m_music->Play(); m_music.Play();
m_video_playing = false; m_video_playing = false;
//m_gameSound->play(m_bnrSndVol); //m_gameSound->play(m_bnrSndVol);
} }
@ -492,7 +492,7 @@ void CMenu::_game(bool launch)
_hideGame(); _hideGame();
if(_wbfsOp(CMenu::WO_REMOVE_GAME)) if(_wbfsOp(CMenu::WO_REMOVE_GAME))
{ {
m_gameSound->FreeMemory(); m_gameSound.FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack(); ClearGameSoundThreadStack();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
@ -507,7 +507,7 @@ void CMenu::_game(bool launch)
m_gcfg1.setBool("ADULTONLY", id, !m_gcfg1.getBool("ADULTONLY", id, false)); m_gcfg1.setBool("ADULTONLY", id, !m_gcfg1.getBool("ADULTONLY", id, false));
else if(m_btnMgr.selected(m_gameBtnBack) || m_btnMgr.selected(m_gameBtnBackFull)) else if(m_btnMgr.selected(m_gameBtnBack) || m_btnMgr.selected(m_gameBtnBackFull))
{ {
m_gameSound->FreeMemory(); m_gameSound.FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack(); ClearGameSoundThreadStack();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
@ -529,7 +529,7 @@ void CMenu::_game(bool launch)
m_banner->ToogleGameSettings(); m_banner->ToogleGameSettings();
_showGame(); _showGame();
if(!m_gameSound->IsPlaying()) if(!m_gameSound.IsPlaying())
startGameSound = -6; startGameSound = -6;
} }
else if(launch || m_btnMgr.selected(m_gameBtnPlay) || m_btnMgr.selected(m_gameBtnPlayFull) || (!WPadIR_Valid(0) && !WPadIR_Valid(1) && !WPadIR_Valid(2) && !WPadIR_Valid(3) && m_btnMgr.selected((u16)-1))) else if(launch || m_btnMgr.selected(m_gameBtnPlay) || m_btnMgr.selected(m_gameBtnPlayFull) || (!WPadIR_Valid(0) && !WPadIR_Valid(1) && !WPadIR_Valid(2) && !WPadIR_Valid(3) && m_btnMgr.selected((u16)-1)))
@ -633,7 +633,7 @@ void CMenu::_game(bool launch)
} }
if(startGameSound == -10) if(startGameSound == -10)
{ {
m_gameSound->Stop(); m_gameSound.Stop();
m_gameSelected = false; m_gameSelected = false;
m_fa.unload(); m_fa.unload();
m_banner->DeleteBanner(true); m_banner->DeleteBanner(true);
@ -1539,7 +1539,7 @@ void CMenu::_gameSoundThread(CMenu *m)
if(m->m_cf.getHdr()->type == TYPE_PLUGIN) if(m->m_cf.getHdr()->type == TYPE_PLUGIN)
{ {
m_banner->DeleteBanner(); m_banner->DeleteBanner();
m->m_gameSound->Load(m->m_plugin.GetBannerSound(m->m_cf.getHdr()->settings[0]), m->m_plugin.GetBannerSoundSize(), false); m->m_gameSound.Load(m->m_plugin.GetBannerSound(m->m_cf.getHdr()->settings[0]), m->m_plugin.GetBannerSoundSize(), false);
m->m_gamesound_changed = true; m->m_gamesound_changed = true;
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
return; return;
@ -1568,7 +1568,7 @@ void CMenu::_gameSoundThread(CMenu *m)
cached_bnr_file = (u8*)malloc(cached_bnr_size); cached_bnr_file = (u8*)malloc(cached_bnr_size);
if(cached_bnr_file == NULL) if(cached_bnr_file == NULL)
{ {
m->m_gameSound->FreeMemory(); m->m_gameSound.FreeMemory();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
return; return;
@ -1592,7 +1592,7 @@ void CMenu::_gameSoundThread(CMenu *m)
u8 *opening_bnr = disc.GetGameCubeBanner(); u8 *opening_bnr = disc.GetGameCubeBanner();
if(opening_bnr != NULL) if(opening_bnr != NULL)
m_banner->CreateGCBanner(opening_bnr, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get(), m->m_cf.getHdr()->title); m_banner->CreateGCBanner(opening_bnr, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get(), m->m_cf.getHdr()->title);
m->m_gameSound->Load(gc_ogg, gc_ogg_size, false); m->m_gameSound.Load(gc_ogg, gc_ogg_size, false);
m->m_gamesound_changed = true; m->m_gamesound_changed = true;
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
disc.clear(); disc.clear();
@ -1608,7 +1608,7 @@ void CMenu::_gameSoundThread(CMenu *m)
custom_bnr_file = (u8*)malloc(custom_bnr_size); custom_bnr_file = (u8*)malloc(custom_bnr_size);
if(custom_bnr_file == NULL) if(custom_bnr_file == NULL)
{ {
m->m_gameSound->FreeMemory(); m->m_gameSound.FreeMemory();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
return; return;
@ -1631,7 +1631,7 @@ void CMenu::_gameSoundThread(CMenu *m)
} }
else else
{ {
m->m_gameSound->FreeMemory(); m->m_gameSound.FreeMemory();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
delete banner; delete banner;
@ -1650,9 +1650,9 @@ void CMenu::_gameSoundThread(CMenu *m)
{ {
u32 newSize = 0; u32 newSize = 0;
u8 *newSound = DecompressCopy(soundBin, sndSize, &newSize); u8 *newSound = DecompressCopy(soundBin, sndSize, &newSize);
if(newSound == NULL || newSize == 0 || !m->m_gameSound->Load(newSound, newSize)) if(newSound == NULL || newSize == 0 || !m->m_gameSound.Load(newSound, newSize))
{ {
m->m_gameSound->FreeMemory(); m->m_gameSound.FreeMemory();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
return; return;
@ -1660,13 +1660,13 @@ void CMenu::_gameSoundThread(CMenu *m)
free(soundBin); free(soundBin);
} }
else else
m->m_gameSound->Load(soundBin, sndSize); m->m_gameSound.Load(soundBin, sndSize);
if(m->m_gameSound->IsLoaded()) if(m->m_gameSound.IsLoaded())
m->m_gamesound_changed = true; m->m_gamesound_changed = true;
else else
{ {
m->m_gameSound->FreeMemory(); m->m_gameSound.FreeMemory();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
} }
} }
@ -1674,7 +1674,7 @@ void CMenu::_gameSoundThread(CMenu *m)
{ {
gprintf("WARNING: No sound found in banner!\n"); gprintf("WARNING: No sound found in banner!\n");
m->m_gamesound_changed = true; m->m_gamesound_changed = true;
m->m_gameSound->FreeMemory(); m->m_gameSound.FreeMemory();
} }
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
} }

View File

@ -272,7 +272,7 @@ int CMenu::main(void)
_initAsyncNetwork(); _initAsyncNetwork();
SetupInput(true); SetupInput(true);
m_music->Play(); m_music.Play();
GameTDB m_gametdb; GameTDB m_gametdb;
m_gametdb.OpenFile(fmt("%s/wiitdb.xml", m_settingsDir.c_str())); m_gametdb.OpenFile(fmt("%s/wiitdb.xml", m_settingsDir.c_str()));
@ -538,14 +538,14 @@ int CMenu::main(void)
else if(BTN_MINUS_PRESSED) else if(BTN_MINUS_PRESSED)
{ {
if(b_lr_mode) if(b_lr_mode)
m_music->Previous(); m_music.Previous();
else else
m_cf.pageUp(); m_cf.pageUp();
} }
else if(BTN_PLUS_PRESSED) else if(BTN_PLUS_PRESSED)
{ {
if(b_lr_mode) if(b_lr_mode)
m_music->Next(); m_music.Next();
else else
m_cf.pageDown(); m_cf.pageDown();
} }
@ -588,7 +588,7 @@ int CMenu::main(void)
if(b_lr_mode) if(b_lr_mode)
m_cf.pageUp(); m_cf.pageUp();
else else
m_music->Previous(); m_music.Previous();
} }
else if(BTN_RIGHT_PRESSED) else if(BTN_RIGHT_PRESSED)
{ {
@ -596,7 +596,7 @@ int CMenu::main(void)
if(b_lr_mode) if(b_lr_mode)
m_cf.pageDown(); m_cf.pageDown();
else else
m_music->Next(); m_music.Next();
} }
else if(BTN_PLUS_PRESSED && !m_locked) else if(BTN_PLUS_PRESSED && !m_locked)
{ {

View File

@ -433,7 +433,7 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op)
m_thrdMessageAdded = false; m_thrdMessageAdded = false;
m_cf.stopCoverLoader(); m_cf.stopCoverLoader();
_stopSounds(); _stopSounds();
m_music->cleanup(); m_music.cleanup();
SoundHandler::DestroyInstance(); SoundHandler::DestroyInstance();
soundDeinit(); soundDeinit();
Nand::Instance()->Disable_Emu(); Nand::Instance()->Disable_Emu();

View File

@ -373,6 +373,11 @@ void GuiSound::Rewind()
decoder->Rewind(); decoder->Rewind();
} }
void GuiSound::SetVoice(s8 v)
{
this->voice = v;
}
void soundInit(void) void soundInit(void)
{ {
ASND_Init(); ASND_Init();

View File

@ -81,6 +81,8 @@ public:
void SetVolume(int v); void SetVolume(int v);
//!\param l Loop (true to loop) //!\param l Loop (true to loop)
void SetLoop(u8 l); void SetLoop(u8 l);
//!Needed for music etc
void SetVoice(s8 v);
private: private:
//!Initializes the GuiSound object by setting the default values //!Initializes the GuiSound object by setting the default values
void Init(); void Init();

View File

@ -2,76 +2,50 @@
using namespace std; using namespace std;
MusicPlayer *m_music; MusicPlayer m_music;
MusicPlayer::MusicPlayer()
{
m_music = NULL;
}
void MusicPlayer::cleanup() void MusicPlayer::cleanup()
{ {
if (m_music != NULL) MusicFile.FreeMemory();
{
m_music->Stop();
delete m_music;
}
} }
void MusicPlayer::Init(Config &cfg, string musicDir, string themeMusicDir) void MusicPlayer::Init(Config &cfg, string musicDir, string themeMusicDir)
{ {
m_manual_stop = true;
m_stopped = true; m_stopped = true;
m_fade_rate = cfg.getInt("GENERAL", "music_fade_rate", 8); m_fade_rate = cfg.getInt("GENERAL", "music_fade_rate", 8);
m_music_volume = cfg.getInt("GENERAL", "sound_volume_music", 255); m_music_volume = cfg.getInt("GENERAL", "sound_volume_music", 255);
SetVolume(0); // Fades in with tick() SetVolume(0);
MusicFile.SetVoice(0);
MusicDirectory dir = (MusicDirectory) cfg.getInt("GENERAL", "music_directories", NORMAL_MUSIC | THEME_MUSIC);
MusicDirectory dir = (MusicDirectory)cfg.getInt("GENERAL", "music_directories", NORMAL_MUSIC | THEME_MUSIC);
m_music_files.Init(cfg.getString("GENERAL", "dir_list_cache"), std::string(), std::string(), std::string(), false); m_music_files.Init(cfg.getString("GENERAL", "dir_list_cache"), std::string(), std::string(), std::string(), false);
if (dir & THEME_MUSIC) if(dir & THEME_MUSIC)
m_music_files.Load(themeMusicDir, ".ogg|.mp3", "EN", cfg); //|.mod|.xm|.s3m|.wav|.aiff"); m_music_files.Load(themeMusicDir, ".ogg|.mp3", "EN", cfg); //|.mod|.xm|.s3m|.wav|.aiff");
if (dir & NORMAL_MUSIC) if(dir & NORMAL_MUSIC)
m_music_files.Load(musicDir, ".ogg|.mp3", "EN", cfg); //|.mod|.xm|.s3m|.wav|.aiff"); m_music_files.Load(musicDir, ".ogg|.mp3", "EN", cfg); //|.mod|.xm|.s3m|.wav|.aiff");
if (cfg.getBool("GENERAL", "randomize_music", true) && m_music_files.size() > 0) if(cfg.getBool("GENERAL", "randomize_music", true) && m_music_files.size() > 0)
{ {
srand(unsigned(time(NULL))); srand(unsigned(time(NULL)));
random_shuffle(m_music_files.begin(), m_music_files.end()); random_shuffle(m_music_files.begin(), m_music_files.end());
} }
m_current_music = m_music_files.begin(); m_current_music = m_music_files.begin();
} }
MusicPlayer::~MusicPlayer() void MusicPlayer::SetVolume(u8 volume)
{ {
if (m_music != NULL) m_music_current_volume = volume;
{ MusicFile.SetVolume(m_music_current_volume);
m_music->Stop();
delete m_music;
}
}
void MusicPlayer::SetVolume(int volume)
{
m_music_current_volume = volume > m_music_volume ? m_music_volume : volume;
if (m_music != NULL)
m_music->SetVolume(m_music_current_volume);
}
void MusicPlayer::SetVolume(int volume, int max_volume)
{
m_music_volume = max_volume;
SetVolume(volume);
} }
void MusicPlayer::Previous() void MusicPlayer::Previous()
{ {
if (m_music_files.empty()) return; if(m_music_files.empty())
return;
if (m_current_music == m_music_files.begin()) if(m_current_music == m_music_files.begin())
m_current_music = m_music_files.end(); m_current_music = m_music_files.end();
m_current_music--; m_current_music--;
@ -81,7 +55,8 @@ void MusicPlayer::Previous()
void MusicPlayer::Next() void MusicPlayer::Next()
{ {
if (m_music_files.empty()) return; if(m_music_files.empty())
return;
m_current_music++; m_current_music++;
if (m_current_music == m_music_files.end()) if (m_current_music == m_music_files.end())
@ -90,75 +65,40 @@ void MusicPlayer::Next()
LoadCurrentFile(); LoadCurrentFile();
} }
void MusicPlayer::Pause()
{
if (m_music != NULL)
m_music->Pause();
m_paused = true;
}
void MusicPlayer::Play() void MusicPlayer::Play()
{ {
m_manual_stop = m_paused = false; // Next tick will start the music SetVolume(m_music_current_volume);
if (m_music != NULL) MusicFile.Play();
m_music->SetVolume(m_music_current_volume); m_stopped = false;
} }
void MusicPlayer::Stop() void MusicPlayer::Stop()
{ {
m_manual_stop = true; MusicFile.Pause();
if (m_music != NULL) MusicFile.Stop();
{
m_music->Pause();
m_music->Stop();
delete m_music;
m_music = NULL;
}
m_stopped = true; m_stopped = true;
} }
void MusicPlayer::Tick(bool attenuate) void MusicPlayer::Tick(bool attenuate)
{ {
if (m_music_files.empty()) return; if(m_music_files.empty())
if (m_music_current_volume == 0 && attenuate) return; return;
if(!attenuate && m_music_current_volume < m_music_volume)
if (m_music != NULL)
{ {
if (!attenuate && m_music_current_volume < m_music_volume) SetVolume(m_music_current_volume + m_fade_rate > m_music_volume ? m_music_volume
{ : m_music_current_volume + m_fade_rate);
int volume = m_music_current_volume + m_fade_rate > m_music_volume ? if(!MusicFile.IsPlaying())
m_music_volume : m_music_current_volume + m_fade_rate; Next();
SetVolume(volume); }
} else if(attenuate && m_music_current_volume > 0)
else if (attenuate && m_music_current_volume > 0) {
{ SetVolume(m_music_current_volume - m_fade_rate < 0 ? 0
int volume = m_music_current_volume - m_fade_rate < 0 ? : m_music_current_volume - m_fade_rate);
0 : m_music_current_volume - m_fade_rate;
SetVolume(volume);
}
} }
if (!attenuate && !m_manual_stop && (m_music == NULL || m_stopped || !m_music->IsPlaying()))
Next();
} }
void MusicPlayer::LoadCurrentFile() void MusicPlayer::LoadCurrentFile()
{ {
if (m_music_files.empty()) return; MusicFile.Load((*m_current_music).c_str());
Play();
if (m_music != NULL)
m_music->Stop();
if (m_music == NULL)
m_music = new GuiSound((*m_current_music).c_str(), ASND_MUSIC_VOICE);
else
m_music->Load((*m_current_music).c_str());
if (m_music != NULL && !m_manual_stop)
{
m_music->SetVolume(m_music_current_volume);
m_music->Play();
m_stopped = false;
}
} }

View File

@ -12,50 +12,37 @@ enum MusicDirectory
THEME_MUSIC = 2 THEME_MUSIC = 2
}; };
#define ASND_MUSIC_VOICE 0
class MusicPlayer class MusicPlayer
{ {
public: public:
MusicPlayer();
~MusicPlayer();
void cleanup(); void cleanup();
void Init(Config &cfg, std::string musicDir, std::string themeMusicDir); void Init(Config &cfg, std::string musicDir, std::string themeMusicDir);
void Tick(bool attenuate); void Tick(bool attenuate);
void SetVolume(int volume); void SetVolume(u8 volume);
void SetVolume(int volume, int max_volume); u8 GetVolume() { return m_music_current_volume; };
int GetVolume() { return m_music != NULL ? m_music_current_volume : 0; }; u8 GetMaxVolume() { return m_music_volume; };
int GetMaxVolume() { return m_music_volume; };
void Previous(); void Previous();
void Next(); void Next();
void Pause();
void Play(); void Play();
void Stop(); void Stop();
bool IsStopped() { return m_stopped; }; bool IsStopped() { return m_stopped; };
private:
protected:
void LoadCurrentFile(); void LoadCurrentFile();
u8 m_music_volume;
u8 m_music_current_volume;
u8 m_fade_rate;
bool m_stopped;
GuiSound MusicFile;
CachedList<std::string> m_music_files; CachedList<std::string> m_music_files;
vector<std::string>::iterator m_current_music; vector<std::string>::iterator m_current_music;
int m_fade_rate;
int m_music_volume;
int m_music_current_volume;
bool m_manual_stop;
bool m_paused;
bool m_stopped;
bool m_playbackFinished;
GuiSound *m_music;
u32 *m_songCount;
}; };
extern MusicPlayer *m_music; extern MusicPlayer m_music;
#endif #endif