From ca29fc0babe8fc985a9e4656f80fc7faec4ac8a5 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 11 May 2011 17:38:29 +0200 Subject: - fix audio plugin and make that a real interface - that fixes a duplicate statis audiomanager (1x pacman, 1x audio plugin) on windows - display won/lost dialog upon gameend --- pacman-c++/common/audio.h | 96 +++++++++++------------------------------------ 1 file changed, 21 insertions(+), 75 deletions(-) (limited to 'pacman-c++/common/audio.h') diff --git a/pacman-c++/common/audio.h b/pacman-c++/common/audio.h index bc7d66e..45af34b 100644 --- a/pacman-c++/common/audio.h +++ b/pacman-c++/common/audio.h @@ -1,6 +1,7 @@ #ifndef AUDIO_H #define AUDIO_H +#include "audiointerface.h" #include #include #include @@ -19,52 +20,12 @@ namespace Sound }; const unsigned int length[] = { - 4310, 2090, 570, 570, 1720, + 4310, 2090, 570, 570, 1720, 1990 }; }; /* --------------------------------------------------------------- */ -class AudioPlayer - : public QObject -{ - Q_OBJECT - friend class AudioManager; - -public: - AudioPlayer(QObject *parent = 0) - : QObject(parent) - {} - virtual ~AudioPlayer() - {} - virtual bool isWorking() const = 0; - virtual void setMuted(bool mute = true) = 0; - virtual bool isMuted() const = 0; - virtual void play() = 0; - virtual void play(Sound::Type sound) = 0; - virtual bool isPlaying() = 0; - virtual void enqueue(Sound::Type sound) = 0; - virtual void pause() = 0; - virtual bool isPaused() = 0; - virtual void stop() = 0; - virtual bool isStopped() = 0; - virtual void clear() = 0; - virtual void clearQueue() = 0; - virtual void setPrefinishMark(qint32 msecToEnd) = 0; - -protected slots: - virtual void prefinishMarkReached_ex(qint32 mark) = 0; - -signals: - void finished(); - void prefinishMarkReached(qint32 mark); - -protected: - virtual void test(QFile *testsound, qint32 length) = 0; -}; - -/* --------------------------------------------------------------- */ - class NoopAudioPlayer : public AudioPlayer { @@ -72,14 +33,11 @@ class NoopAudioPlayer friend class AudioManager; public: - NoopAudioPlayer(QObject *parent = 0); virtual bool isWorking() const; virtual void setMuted(bool mute = true); virtual bool isMuted() const; virtual void play(); - virtual void play(Sound::Type sound); virtual bool isPlaying(); - virtual void enqueue(Sound::Type sound); virtual void pause(); virtual bool isPaused(); virtual void stop(); @@ -87,13 +45,19 @@ public: virtual void clear(); virtual void clearQueue(); virtual void setPrefinishMark(qint32 msecToEnd); + virtual void seek(qint64 time); + +protected: + NoopAudioPlayer(QObject *parent = 0); + virtual void setWorking(bool working = true); + virtual void test(QFile *sound, unsigned int length); + virtual void play(QFile *sound, unsigned int length); + virtual void setSource(QFile *sound, unsigned int length); + virtual void enqueue(QFile *sound, unsigned int length); protected slots: virtual void prefinishMarkReached_ex(qint32 mark); -protected: - virtual void test(QFile *testsound, qint32 length); - protected: bool m_working; bool m_muted; @@ -109,9 +73,9 @@ class FakeAudioPlayer Q_OBJECT friend class AudioManager; -public: +protected: FakeAudioPlayer(QObject *parent = 0); - virtual void play(Sound::Type sound); + virtual void play(QFile *sound, unsigned int length); protected slots: void finished_ex(); @@ -148,27 +112,6 @@ protected: /* --------------------------------------------------------------- */ -class AudioPlayerFactory -{ -public: - virtual ~AudioPlayerFactory() - {} - virtual AudioPlayer *create(QObject *parent = 0) = 0; -}; - -Q_DECLARE_INTERFACE(AudioPlayerFactory, "at.ac.tuwien.foop.pacman.AudioPlayerFactory/1.0"); - -/* --------------------------------------------------------------- */ - -class NoopAudioPlayerFactory - : public AudioPlayerFactory -{ -public: - virtual AudioPlayer *create(QObject *parent = 0); -}; - -/* --------------------------------------------------------------- */ - class AudioManager : public QObject { @@ -189,8 +132,9 @@ public: AudioPlayer *audioPlayer(); void registerAudioPlayer(AudioPlayer *player); void unregisterAudioPlayer(AudioPlayer *player); - - QFile *sound(Sound::Type sound); + void play(Sound::Type sound, AudioPlayer *player = NULL); + void setSource(Sound::Type sound, AudioPlayer *player = NULL); + void enqueue(Sound::Type sound, AudioPlayer *player = NULL); signals: void mutedChanged(bool muted); @@ -200,8 +144,10 @@ private slots: protected: void preload(); - bool tryLoadPhononPlugin(); - AudioPlayer *createAudioPlayer(); + bool tryLoadAudioPlugin(const QString &libraryname); + AudioPlayer *createAudioPlayer(QObject *parent = 0); + QFile *sound(Sound::Type sound); + unsigned int length(Sound::Type sound); private: bool m_muted; @@ -212,4 +158,4 @@ private: AudioPlayerFactory *m_factory; }; -#endif // AUDIOPLAYER_H +#endif // AUDIO_H -- cgit v1.2.3