From f527735c54822d234864502825874e17e4ddc6df Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Sat, 15 Sep 2012 21:20:22 +0000 Subject: [PATCH] -added music resume after ios reload/enabling nand emulator --- source/loader/alt_ios.cpp | 2 +- source/menu/menu.cpp | 5 ++++- source/music/OggDecoder.cpp | 10 ++++++++++ source/music/OggDecoder.hpp | 2 ++ source/music/gui_sound.h | 2 ++ source/music/musicplayer.cpp | 18 +++++++++++++++++- source/music/musicplayer.h | 2 ++ 7 files changed, 38 insertions(+), 3 deletions(-) diff --git a/source/loader/alt_ios.cpp b/source/loader/alt_ios.cpp index 0a0d9940..e21eb931 100644 --- a/source/loader/alt_ios.cpp +++ b/source/loader/alt_ios.cpp @@ -91,7 +91,7 @@ bool loadIOS(int ios, bool MountDevices) { WDVD_Close(); Close_Inputs(); - m_music.Stop(); + m_music.StopAndSetPos(); gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS); ShutdownBeforeExit(); ret = IOS_ReloadIOS(ios) == 0; diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index be85fe88..8a04c40f 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -2140,7 +2140,10 @@ bool CMenu::_loadChannelList(void) Nand::Instance()->Disable_Emu(); if(!disable_emu) { - _TempLoadIOS(); + if(useMainIOS) + m_music.StopAndSetPos(); + else + _TempLoadIOS(); if(!DeviceHandler::Instance()->IsInserted(lastPartition)) DeviceHandler::Instance()->Mount(lastPartition); diff --git a/source/music/OggDecoder.cpp b/source/music/OggDecoder.cpp index e102f131..4be171e7 100644 --- a/source/music/OggDecoder.cpp +++ b/source/music/OggDecoder.cpp @@ -127,6 +127,16 @@ int OggDecoder::Rewind() return ret; } +int OggDecoder::Tell() +{ + return ov_raw_tell(&ogg_file); +} + +int OggDecoder::Seek(int pos) +{ + return ov_raw_seek(&ogg_file, pos); +} + int OggDecoder::Read(u8 * buffer, int buffer_size, int) { if(!file_fd) diff --git a/source/music/OggDecoder.hpp b/source/music/OggDecoder.hpp index 32efde35..2c22702f 100644 --- a/source/music/OggDecoder.hpp +++ b/source/music/OggDecoder.hpp @@ -38,6 +38,8 @@ public: int GetSampleRate(); int Rewind(); int Read(u8 * buffer, int buffer_size, int pos); + int Tell(); + int Seek(int pos); protected: void OpenFile(); OggVorbis_File ogg_file; diff --git a/source/music/gui_sound.h b/source/music/gui_sound.h index a9077ee4..2acfd42c 100644 --- a/source/music/gui_sound.h +++ b/source/music/gui_sound.h @@ -83,6 +83,8 @@ public: void SetLoop(u8 l); //!Needed for music etc void SetVoice(s8 v); + //!Needed for music :P + s8 GetVoice() { return voice; } private: //!Initializes the GuiSound object by setting the default values void Init(); diff --git a/source/music/musicplayer.cpp b/source/music/musicplayer.cpp index a1392a29..03b53fc4 100644 --- a/source/music/musicplayer.cpp +++ b/source/music/musicplayer.cpp @@ -3,6 +3,7 @@ #include #include "musicplayer.h" +#include "SoundHandler.hpp" #include "fileOps/fileOps.h" #include "gui/text.hpp" @@ -16,6 +17,7 @@ void MusicPlayer::cleanup() void MusicPlayer::Init(Config &cfg, string musicDir, string themeMusicDir) { m_stopped = true; + CurrentPosition = 0; m_fade_rate = cfg.getInt("GENERAL", "music_fade_rate", 8); m_music_volume = cfg.getInt("GENERAL", "sound_volume_music", 255); @@ -78,7 +80,15 @@ void MusicPlayer::Next() { if(m_music_files.empty()) return; - + if(CurrentPosition) + { + LoadCurrentFile(); + MusicFile.Pause(); + SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Seek(CurrentPosition); + CurrentPosition = 0; + MusicFile.Resume(); + return; + } m_current_music++; if (m_current_music == m_music_files.end()) m_current_music = m_music_files.begin(); @@ -86,6 +96,12 @@ void MusicPlayer::Next() LoadCurrentFile(); } +void MusicPlayer::StopAndSetPos() +{ + CurrentPosition = SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Tell(); + Stop(); +} + void MusicPlayer::Play() { SetVolume(m_music_current_volume); diff --git a/source/music/musicplayer.h b/source/music/musicplayer.h index cf6b57c8..7895dd16 100644 --- a/source/music/musicplayer.h +++ b/source/music/musicplayer.h @@ -23,6 +23,7 @@ public: void Next(); void Play(); void Stop(); + void StopAndSetPos(); bool IsStopped() { return m_stopped; }; @@ -33,6 +34,7 @@ protected: u8 m_music_volume; u8 m_music_current_volume; u8 m_fade_rate; + int CurrentPosition; bool m_stopped; GuiSound MusicFile;