diff --git a/JGE/include/JSoundSystem.h b/JGE/include/JSoundSystem.h index 93fe4f1e3..7c7dc79b8 100644 --- a/JGE/include/JSoundSystem.h +++ b/JGE/include/JSoundSystem.h @@ -23,28 +23,32 @@ #include "SLES/OpenSLES_Android.h" #elif defined USE_PHONON - #include - #include +#include +#include #elif defined WIN32 - #include +#include #define WITH_FMOD #elif defined (PSP) - #include - #include - #include - #include - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include +#include +#include +#include - #include "JAudio.h" - #include "JMP3.h" +#include "JAudio.h" +#include "JMP3.h" +#elif defined QT_CONFIG +#include "QMediaPlayer" +#include "QMediaPlaylist" +#include "QSoundEffect" #endif #ifdef WITH_FMOD - #include "../Dependencies/include/fmod.h" +#include "../Dependencies/include/fmod.h" #endif //------------------------------------------------------------------------------------------------ @@ -67,7 +71,7 @@ public: #ifdef USE_PHONON Phonon::AudioOutput* mOutput; Phonon::MediaObject* mMediaObject; - public slots: +public slots: void seekAtTheBegining(); #elif defined (PSP) JMP3* mTrack; @@ -82,6 +86,10 @@ public: SLPlayItf playInterface; SLSeekItf seekInterface; SLVolumeItf musicVolumeInterface; +#elif defined QT_CONFIG + QMediaPlaylist* playlist; + QMediaPlayer* player; + string fullpath; #else void* mTrack; #endif //WITH_FMOD @@ -92,13 +100,15 @@ public: //------------------------------------------------------------------------------------------------ class JSample { - public: +public: JSample(); ~JSample(); unsigned long fileSize(); - -#if defined (PSP) +#ifdef QT_CONFIG + QSoundEffect effect; + void* mSample; +#elif defined (PSP) WAVDATA *mSample; #elif defined (IOS) std::string filename; @@ -133,126 +143,128 @@ class JSoundSystem public: - ////////////////////////////////////////////////////////////////////////// - /// Get the singleton instance - /// - ////////////////////////////////////////////////////////////////////////// - static JSoundSystem* GetInstance(); + ////////////////////////////////////////////////////////////////////////// + /// Get the singleton instance + /// + ////////////////////////////////////////////////////////////////////////// + static JSoundSystem* GetInstance(); - static void Destroy(); + static void Destroy(); - ////////////////////////////////////////////////////////////////////////// - /// Load music. - /// - /// @note MP3 is the only supported format for the moment. - /// - /// @param filename - Name of the music file. - /// - ////////////////////////////////////////////////////////////////////////// - JMusic *LoadMusic(const char *fileName); + ////////////////////////////////////////////////////////////////////////// + /// Load music. + /// + /// @note MP3 is the only supported format for the moment. + /// + /// @param filename - Name of the music file. + /// + ////////////////////////////////////////////////////////////////////////// + JMusic *LoadMusic(const char *fileName); - ////////////////////////////////////////////////////////////////////////// - /// Delete music from memory. - /// - /// @param music - Music to be deleted. - /// - ////////////////////////////////////////////////////////////////////////// - //void FreeMusic(JMusic *music); + ////////////////////////////////////////////////////////////////////////// + /// Delete music from memory. + /// + /// @param music - Music to be deleted. + /// + ////////////////////////////////////////////////////////////////////////// + //void FreeMusic(JMusic *music); - ////////////////////////////////////////////////////////////////////////// - /// Play music. - /// - /// @param music - Music to be played. - /// @param looping - Play the music in a loop. - /// - ////////////////////////////////////////////////////////////////////////// - void PlayMusic(JMusic *music, bool looping = false); + ////////////////////////////////////////////////////////////////////////// + /// Play music. + /// + /// @param music - Music to be played. + /// @param looping - Play the music in a loop. + /// + ////////////////////////////////////////////////////////////////////////// + void PlayMusic(JMusic *music, bool looping = false); - ////////////////////////////////////////////////////////////////////////// - /// Stop playing. - /// - /// @param music - Music to be stopped. - /// - ////////////////////////////////////////////////////////////////////////// - void StopMusic(JMusic *music); + ////////////////////////////////////////////////////////////////////////// + /// Stop playing. + /// + /// @param music - Music to be stopped. + /// + ////////////////////////////////////////////////////////////////////////// + void StopMusic(JMusic *music); - ////////////////////////////////////////////////////////////////////////// - /// Resume playing. - /// - /// @param music - Music to be resumed. - /// - ////////////////////////////////////////////////////////////////////////// - void ResumeMusic(JMusic *music); + ////////////////////////////////////////////////////////////////////////// + /// Resume playing. + /// + /// @param music - Music to be resumed. + /// + ////////////////////////////////////////////////////////////////////////// + void ResumeMusic(JMusic *music); - ////////////////////////////////////////////////////////////////////////// - /// Pause playing. - /// - /// @param music - Music to be paused. - /// - ////////////////////////////////////////////////////////////////////////// - void PauseMusic(JMusic *music); + ////////////////////////////////////////////////////////////////////////// + /// Pause playing. + /// + /// @param music - Music to be paused. + /// + ////////////////////////////////////////////////////////////////////////// + void PauseMusic(JMusic *music); - ////////////////////////////////////////////////////////////////////////// - /// Load sound effect. - /// - /// @note WAV sound effect only. - /// - /// @param fileName - Sound effect for loading. - /// - ////////////////////////////////////////////////////////////////////////// - JSample *LoadSample(const char *fileName); + ////////////////////////////////////////////////////////////////////////// + /// Load sound effect. + /// + /// @note WAV sound effect only. + /// + /// @param fileName - Sound effect for loading. + /// + ////////////////////////////////////////////////////////////////////////// + JSample *LoadSample(const char *fileName); - ////////////////////////////////////////////////////////////////////////// - /// Delete sound effect from memory. - /// - /// @param sample - Sound to be deleted. - /// - ////////////////////////////////////////////////////////////////////////// - //void FreeSample(JSample *sample); + ////////////////////////////////////////////////////////////////////////// + /// Delete sound effect from memory. + /// + /// @param sample - Sound to be deleted. + /// + ////////////////////////////////////////////////////////////////////////// + //void FreeSample(JSample *sample); - ////////////////////////////////////////////////////////////////////////// - /// Play sound effect. - /// - /// @param sample - Sound for playing. - /// - ////////////////////////////////////////////////////////////////////////// - void PlaySample(JSample *sample); + ////////////////////////////////////////////////////////////////////////// + /// Play sound effect. + /// + /// @param sample - Sound for playing. + /// + ////////////////////////////////////////////////////////////////////////// + void PlaySample(JSample *sample); - ////////////////////////////////////////////////////////////////////////// - /// Set volume for audio playback. - /// - /// @param volume - New volume. - /// - ////////////////////////////////////////////////////////////////////////// - void SetVolume(int volume); + ////////////////////////////////////////////////////////////////////////// + /// Set volume for audio playback. + /// + /// @param volume - New volume. + /// + ////////////////////////////////////////////////////////////////////////// + void SetVolume(int volume); - void SetMusicVolume(int volume); + void SetMusicVolume(int volume); - void SetSfxVolume(int volume); + void SetSfxVolume(int volume); - int mChannel; + int mChannel; protected: - JSoundSystem(); - ~JSoundSystem(); + JSoundSystem(); + ~JSoundSystem(); - void InitSoundSystem(); - void DestroySoundSystem(); + void InitSoundSystem(); + void DestroySoundSystem(); private: - - JMusic *mCurrentMusic; +#ifdef PSP + JMusic *mCurrentMusic; JSample *mCurrentSample; +#endif - int mVolume; - int mMusicVolume; - int mSampleVolume; + int mVolume; + int mMusicVolume; + int mSampleVolume; - static JSoundSystem* mInstance; + static JSoundSystem* mInstance; }; #endif + diff --git a/JGE/src/pc/JSfx.cpp b/JGE/src/pc/JSfx.cpp index 4977bc831..faa4fa71c 100644 --- a/JGE/src/pc/JSfx.cpp +++ b/JGE/src/pc/JSfx.cpp @@ -22,6 +22,8 @@ JMusic::JMusic() #ifdef USE_PHONON : mOutput(0), mMediaObject(0) +#elif defined QT_CONFIG + : playlist(0), player(0) #endif { } @@ -40,7 +42,12 @@ int JMusic::getPlayTime(){ JMusic::~JMusic() { -#ifdef USE_PHONON +#ifdef QT_CONFIG + if(player) + delete player; + if(playlist) + delete playlist; +#elif defined USE_PHONON if(mOutput) delete mOutput; if(mMediaObject) @@ -144,65 +151,88 @@ void JSoundSystem::DestroySoundSystem() JMusic *JSoundSystem::LoadMusic(const char *fileName) { -#ifdef USE_PHONON - JMusic* music = new JMusic(); - if (music) - { - music->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0); - music->mMediaObject = new Phonon::MediaObject(0); - string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName); - music->mMediaObject->setCurrentSource(QString(fullpath.c_str())); - Phonon::Path mediapath = Phonon::createPath(music->mMediaObject, music->mOutput); - Q_ASSERT(mediapath.isValid()); - } - return music; -#elif (defined WITH_FMOD) - JMusic* music = new JMusic(); - if (music) + JMusic* music = NULL; +#ifdef QT_CONFIG + music = new JMusic(); + if (music) { - JFileSystem* fileSystem = JFileSystem::GetInstance(); - if (fileSystem->OpenFile(fileName)) - { - int size = fileSystem->GetFileSize(); - char *buffer = new char[size]; - fileSystem->ReadFile(buffer, size); - music->mTrack = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, FSOUND_LOADMEMORY, 0, size); - - delete[] buffer; - fileSystem->CloseFile(); - } + music->player = new QMediaPlayer; + music->player->setVolume(100); + music->playlist = new QMediaPlaylist; + music->fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName); + music->playlist->addMedia(QUrl(music->fullpath.c_str())); + music->playlist->setCurrentIndex(0); + } +#elif defined USE_PHONON + music = new JMusic(); + if (music) + { + music->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0); + music->mMediaObject = new Phonon::MediaObject(0); + string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName); + music->mMediaObject->setCurrentSource(QString(fullpath.c_str())); + Phonon::Path mediapath = Phonon::createPath(music->mMediaObject, music->mOutput); + Q_ASSERT(mediapath.isValid()); + } +#elif (defined WITH_FMOD) + music = new JMusic(); + if (music) + { + JFileSystem* fileSystem = JFileSystem::GetInstance(); + if (fileSystem->OpenFile(fileName)) + { + int size = fileSystem->GetFileSize(); + char *buffer = new char[size]; + fileSystem->ReadFile(buffer, size); + music->mTrack = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, FSOUND_LOADMEMORY, 0, size); + + delete[] buffer; + fileSystem->CloseFile(); + } } - return music; #else cerr << fileName << endl; - return NULL; #endif + return music; } void JSoundSystem::PlayMusic(JMusic *music, bool looping) { -#ifdef USE_PHONON - if (music && music->mMediaObject && music->mOutput) - { - if(looping) +#ifdef QT_CONFIG + if(music && music->player && music->playlist) { - music->mMediaObject->connect(music->mMediaObject, SIGNAL(aboutToFinish()), music, SLOT(seekAtTheBegining())); + if(looping) + music->playlist->setPlaybackMode(QMediaPlaylist::Loop); + +// music->player->setPlaylist(music->playlist); + music->player->setMedia(QUrl(music->fullpath.c_str())); + music->player->play(); + stringstream stream; + stream << "Player state : " << music->player->state(); + DebugTrace(stream.str()); } - music->mOutput->setVolume((qreal)mVolume*0.01); - music->mMediaObject->play(); - - } -#elif (defined WITH_FMOD) - if (music && music->mTrack) +#elif USE_PHONON + if (music && music->mMediaObject && music->mOutput) { - mChannel = FSOUND_PlaySound(mChannel, music->mTrack); - SetMusicVolume(mVolume); + if(looping) + { + music->mMediaObject->connect(music->mMediaObject, SIGNAL(aboutToFinish()), music, SLOT(seekAtTheBegining())); + } + music->mOutput->setVolume((qreal)mVolume*0.01); + music->mMediaObject->play(); - if (looping) - FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_NORMAL); - else - FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_OFF); + } +#elif (defined WITH_FMOD) + if (music && music->mTrack) + { + mChannel = FSOUND_PlaySound(mChannel, music->mTrack); + SetMusicVolume(mVolume); + + if (looping) + FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_NORMAL); + else + FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_OFF); } #else music = 0; @@ -213,7 +243,12 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping) void JSoundSystem::StopMusic(JMusic *music) { -#ifdef USE_PHONON +#ifdef QT_CONFIG + if (music && music->player && music->playlist) + { + music->player->stop(); + } +#elif defined USE_PHONON if (music && music->mMediaObject && music->mOutput) { music->mMediaObject->stop(); @@ -264,47 +299,61 @@ void JSoundSystem::SetSfxVolume(int volume){ JSample *JSoundSystem::LoadSample(const char *fileName) { -#if (defined USE_PHONON) - JSample* sample = new JSample(); - if (sample) - { - sample->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0); - sample->mMediaObject = new Phonon::MediaObject(0); - string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName); - sample->mMediaObject->setCurrentSource(QString(fullpath.c_str())); - Phonon::Path mediapath = Phonon::createPath(sample->mMediaObject, sample->mOutput); - Q_ASSERT(mediapath.isValid()); - } - return sample; -#elif (defined WITH_FMOD) - JSample* sample = new JSample(); - if (sample) + JSample* sample = NULL; +#ifdef QT_CONFIG + sample = new JSample(); + if (sample) { - JFileSystem* fileSystem = JFileSystem::GetInstance(); - if (fileSystem->OpenFile(fileName)) - { - int size = fileSystem->GetFileSize(); - char *buffer = new char[size]; - fileSystem->ReadFile(buffer, size); - sample->mSample = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, FSOUND_LOADMEMORY, 0, size); + string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName); + sample->effect.setSource(QUrl::fromLocalFile(fullpath.c_str())); + sample->effect.setLoopCount(0); + sample->effect.setVolume(1); + sample->mSample = &(sample->effect); + } +#elif (defined USE_PHONON) + sample = new JSample(); + if (sample) + { + sample->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0); + sample->mMediaObject = new Phonon::MediaObject(0); + string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName); + sample->mMediaObject->setCurrentSource(QString(fullpath.c_str())); + Phonon::Path mediapath = Phonon::createPath(sample->mMediaObject, sample->mOutput); + Q_ASSERT(mediapath.isValid()); + } +#elif (defined WITH_FMOD) + sample = new JSample(); + if (sample) + { + JFileSystem* fileSystem = JFileSystem::GetInstance(); + if (fileSystem->OpenFile(fileName)) + { + int size = fileSystem->GetFileSize(); + char *buffer = new char[size]; + fileSystem->ReadFile(buffer, size); + sample->mSample = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, FSOUND_LOADMEMORY, 0, size); - delete[] buffer; - fileSystem->CloseFile(); - }else - sample->mSample = NULL; + delete[] buffer; + fileSystem->CloseFile(); + }else + sample->mSample = NULL; } - return sample; #else cerr << fileName << endl; - return NULL; #endif + return sample; } void JSoundSystem::PlaySample(JSample *sample) { -#ifdef USE_PHONON +#ifdef QT_CONFIG + if(sample) + { + sample->effect.play(); + } +#elif defined USE_PHONON if (sample && sample->mMediaObject && sample->mOutput) { sample->mOutput->setVolume((qreal)mSampleVolume*0.01); diff --git a/projects/mtg/wagic-qt.pro b/projects/mtg/wagic-qt.pro index 487557c3f..40e4c5104 100644 --- a/projects/mtg/wagic-qt.pro +++ b/projects/mtg/wagic-qt.pro @@ -17,7 +17,7 @@ else:CONFIG(graphics, graphics|console){ folder_01.source = qml/QmlWagic folder_01.target = /usr/share DEPLOYMENTFOLDERS = folder_01 - QT += core gui opengl network + QT += core gui opengl network multimedia QT -= declarative quick qml #maemo5:DEFINES += QT_WIDGET DEFINES += QT_WIDGET @@ -46,6 +46,7 @@ CONFIG(graphics, graphics|console){ ../../JGE/src/qt/corewrapper.cpp\ ../../JGE/src/Qtmain.cpp\ ../../JGE/src/JMD2Model.cpp\ + ../../JGE/src/pc/JSfx.cpp\ ../../JGE/src/pc/JGfx.cpp } else:CONFIG(console, graphics|console){ diff --git a/projects/mtg/wagic.pri b/projects/mtg/wagic.pri index 7ed0465dc..6c8cd4198 100644 --- a/projects/mtg/wagic.pri +++ b/projects/mtg/wagic.pri @@ -303,7 +303,6 @@ SOURCES += \ ../../JGE/src/JSpline.cpp\ ../../JGE/src/JNetwork.cpp\ ../../JGE/src/pc/JSocket.cpp\ - ../../JGE/src/pc/JSfx.cpp\ ../../JGE/src/JSprite.cpp\ ../../JGE/src/Vector2D.cpp\ ../../JGE/src/tinyxml/tinystr.cpp\