diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-01-24 19:40:02 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-01-24 19:40:02 +0000 |
| commit | ec3636befb2b12138c9de05ae4ffd432fd8b528a (patch) | |
| tree | 6f9470d705d1b99dc60cc5bf0a04d0eb6b691168 | |
| parent | 357811219a245f0c9fccffe9ca1a50adfa403e62 (diff) | |
[FIX] Revision 42 date
[FIX] Replaced AudioCache with an Audio wrapper
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@43 6ecfd1a5-f3ed-3746-8530-beee90d26b22
| -rw-r--r-- | Changelog | 10 | ||||
| -rw-r--r-- | general/Audio.cpp (renamed from general/AudioCache.cpp) | 55 | ||||
| -rw-r--r-- | general/Audio.h (renamed from general/AudioCache.h) | 60 | ||||
| -rw-r--r-- | general/general.pro | 1 |
4 files changed, 71 insertions, 55 deletions
@@ -1,6 +1,14 @@ ----------------- +Rev: 43 +Date: 24 January 2008 +User: MathStuf +----------------- +[FIX] Revision 42 date +[FIX] Replaced AudioCache with an Audio wrapper + +----------------- Rev: 42 -Date: 23 January 2008 +Date: 24 January 2008 User: MathStuf ----------------- [FIX] BugCatcher now asks if the user wants to open KBugReport diff --git a/general/AudioCache.cpp b/general/Audio.cpp index 7cc6de53..034de04d 100644 --- a/general/AudioCache.cpp +++ b/general/Audio.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: general/AudioCache.cpp +// Name: general/Audio.cpp // Purpose: Cache for sound effects // Author: Ben Boeckel // Modified by: Ben Boeckel @@ -20,50 +20,53 @@ // with this program. If not, see <http://www.gnu.org/licenses/>. ///////////////////////////////////////////////////////////////////////////// -#include "AudioCache.h" +#include "Audio.h" -QCache<QString, Phonon::MediaObject> AudioCache::cache(100); -Phonon::AudioOutput AudioCache::output(Phonon::MusicCategory); -bool AudioCache::started = false; - -void AudioCache::playSFX(const QString& url, const bool force) throw(OpenException) +void Audio::playSFX(const QString& url) throw(OpenException) { - if (force) - cache.remove(url); - if (!cache.contains(url)) - { - Phonon::MediaObject* sfx = new Phonon::MediaObject(); - sfx->setCurrentSource(url); - if (sfx->state() == Phonon::ErrorState) - throw(OpenException("AudioCache", url)); - cache.insert(url, sfx, 1); - } - Phonon::MediaObject* sfx = cache.object(url); - sfx = *(); - sfx.play(); + Phonon::MediaObject* sfx = new Phonon::MediaObject(); + sfx->setCurrentSource(url); + if (sfx->state() == Phonon::ErrorState) + throw(OpenException("Audio", url)); + sfx->play(); curPlay.append(sfx); - curPlay[curPlay.size() - 1].play(); } -void AudioCache::playMusic(const QString& url) +void Audio::playMusic(const QString& url) throw(OpenException) { if (!started) start(); musicUrl = url; if (music.state() == Phonon::PlayingState) - music.seek(music.totalTime - 1000); + music.seek(music.totalTime() - 1000); else { music.setCurrentSource(url); + if (music.state() == Phonon::ErrorState) + throw(OpenException("Audio", url)); music.play(); } } -void AudioCache::prune() +void Audio::prune() { - for (QMutableListIterator<Phonon::MediaObject> i(curPlay); i.hasNext(); i.next()) + for (QMutableListIterator<Phonon::MediaObject*> i(curPlay); i.hasNext(); i.next()) { - if (i.value().state() == Phonon::StoppedState) + if (i.value()->state() == Phonon::StoppedState) + { + delete i.value(); i.remove(); + } + } +} + +void Audio::clear() +{ + for (QMutableListIterator<Phonon::MediaObject*> i(curPlay); i.hasNext(); i.next()) + { + if (i.value()->state() == Phonon::PlayingState) + i.value()->stop(); + delete i.value(); + i.remove(); } } diff --git a/general/AudioCache.h b/general/Audio.h index c97275e4..60e3a784 100644 --- a/general/AudioCache.h +++ b/general/Audio.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: general/SoundEffects.h +// Name: general/Audio.h // Purpose: Sound effect handling // Author: Ben Boeckel // Modified by: Ben Boeckel @@ -20,58 +20,62 @@ // with this program. If not, see <http://www.gnu.org/licenses/>. ///////////////////////////////////////////////////////////////////////////// -#ifndef __SOUNDEFFECTS__ -#define __SOUNDEFFECTS__ +#ifndef __AUDIO__ +#define __AUDIO__ #include <phonon/audiooutput.h> //#include <Phonon/AudioOutput> #include <phonon/mediaobject.h> //#include <Phonon/MediaObject> +#include <QObject> #include "Exception.h" -class Audio +class Audio : public QObject { + Q_OBJECT + public: - static void playSFX(const QString& url, const bool force = false) throw(OpenException); - static void playMusic(const QString& url); - - static void prune(); - static void clear() + Audio() : + output(Phonon::MusicCategory), + started(false) { - cache.clear(); } - - static void remove(const QString& url) + ~Audio() { - cache.remove(url); + clear(); } - static float getVolume() + void playSFX(const QString& url) throw(OpenException); + void playMusic(const QString& url) throw(OpenException); + + void prune(); + void clear(); + + double getVolume() { - return output.volume; + return output.volume(); } - static void setVolume(const float v) + void setVolume(const double v) { - output.volume = v; + output.setVolume(v); } private: - static void start() + void start() { if (!started) - connect(&music, SIGNAL(aboutToFinish()), SLOT(loopMusic())); + connect(&music, SIGNAL(aboutToFinish()), this, SLOT(loopMusic())); } - - static void loopMusic() + private slots: + void loopMusic() { music.enqueue(musicUrl); } - - static QCache<QString, Phonon::MediaObject> cache; - static QList<Phonon::MediaObject> curPlay; - static Phonon::MediaObject music; - static QString musicUrl; - static Phonon::AudioOutput output; - static bool started; + private: + QList<Phonon::MediaObject*> curPlay; + Phonon::MediaObject music; + QString musicUrl; + Phonon::AudioOutput output; + bool started; }; #endif diff --git a/general/general.pro b/general/general.pro index d9d26206..50d493fe 100644 --- a/general/general.pro +++ b/general/general.pro @@ -1,5 +1,6 @@ OBJECTS_DIR = .obj DESTDIR = ../../lib +MOC_DIR = .moc LANGUAGE = C++ TEMPLATE = lib INCLUDEPATH+=/usr/include/kde4 |
