diff options
| author | manuel <manuel@mausz.at> | 2011-05-10 22:28:58 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-05-10 22:28:58 +0200 |
| commit | 1a6c940ed9d7f6136da0e13148314072665342c5 (patch) | |
| tree | 467b259d966ea1ddf9f66440066f57cf3eed68c4 /pacman-c++/common/audio.h | |
| parent | cc1bb779661217171418adb0ddbd1ce01815463b (diff) | |
| download | foop-1a6c940ed9d7f6136da0e13148314072665342c5.tar.gz foop-1a6c940ed9d7f6136da0e13148314072665342c5.tar.bz2 foop-1a6c940ed9d7f6136da0e13148314072665342c5.zip | |
- refactorized audio once more: audio is now a plugin which gets loaded at runtime
- thus server has no dependency to phonon any more
- remove client dependency to qtnetwork
- fix enet deinitialization on windows
Diffstat (limited to 'pacman-c++/common/audio.h')
| -rw-r--r-- | pacman-c++/common/audio.h | 147 |
1 files changed, 107 insertions, 40 deletions
diff --git a/pacman-c++/common/audio.h b/pacman-c++/common/audio.h index 6aec42d..bc7d66e 100644 --- a/pacman-c++/common/audio.h +++ b/pacman-c++/common/audio.h | |||
| @@ -4,13 +4,7 @@ | |||
| 4 | #include <QObject> | 4 | #include <QObject> |
| 5 | #include <QList> | 5 | #include <QList> |
| 6 | #include <QFile> | 6 | #include <QFile> |
| 7 | #include <QThread> | 7 | #include <QTimer> |
| 8 | #include <phonon/MediaObject> | ||
| 9 | |||
| 10 | namespace Phonon | ||
| 11 | { | ||
| 12 | class AudioOutput; | ||
| 13 | } | ||
| 14 | 8 | ||
| 15 | namespace Sound | 9 | namespace Sound |
| 16 | { | 10 | { |
| @@ -32,46 +26,98 @@ namespace Sound | |||
| 32 | /* --------------------------------------------------------------- */ | 26 | /* --------------------------------------------------------------- */ |
| 33 | 27 | ||
| 34 | class AudioPlayer | 28 | class AudioPlayer |
| 35 | : public Phonon::MediaObject | 29 | : public QObject |
| 36 | { | 30 | { |
| 37 | Q_OBJECT | 31 | Q_OBJECT |
| 38 | friend class AudioManager; | 32 | friend class AudioManager; |
| 39 | 33 | ||
| 40 | private: | 34 | public: |
| 41 | class Sleeper | 35 | AudioPlayer(QObject *parent = 0) |
| 42 | : public QThread | 36 | : QObject(parent) |
| 43 | { | 37 | {} |
| 44 | public: | 38 | virtual ~AudioPlayer() |
| 45 | static void sleep(unsigned long secs); | 39 | {} |
| 46 | static void msleep(unsigned long msecs); | 40 | virtual bool isWorking() const = 0; |
| 47 | static void usleep(unsigned long usecs); | 41 | virtual void setMuted(bool mute = true) = 0; |
| 48 | }; | 42 | virtual bool isMuted() const = 0; |
| 43 | virtual void play() = 0; | ||
| 44 | virtual void play(Sound::Type sound) = 0; | ||
| 45 | virtual bool isPlaying() = 0; | ||
| 46 | virtual void enqueue(Sound::Type sound) = 0; | ||
| 47 | virtual void pause() = 0; | ||
| 48 | virtual bool isPaused() = 0; | ||
| 49 | virtual void stop() = 0; | ||
| 50 | virtual bool isStopped() = 0; | ||
| 51 | virtual void clear() = 0; | ||
| 52 | virtual void clearQueue() = 0; | ||
| 53 | virtual void setPrefinishMark(qint32 msecToEnd) = 0; | ||
| 54 | |||
| 55 | protected slots: | ||
| 56 | virtual void prefinishMarkReached_ex(qint32 mark) = 0; | ||
| 57 | |||
| 58 | signals: | ||
| 59 | void finished(); | ||
| 60 | void prefinishMarkReached(qint32 mark); | ||
| 61 | |||
| 62 | protected: | ||
| 63 | virtual void test(QFile *testsound, qint32 length) = 0; | ||
| 64 | }; | ||
| 65 | |||
| 66 | /* --------------------------------------------------------------- */ | ||
| 67 | |||
| 68 | class NoopAudioPlayer | ||
| 69 | : public AudioPlayer | ||
| 70 | { | ||
| 71 | Q_OBJECT | ||
| 72 | friend class AudioManager; | ||
| 49 | 73 | ||
| 50 | public: | 74 | public: |
| 51 | AudioPlayer(QObject *parent = 0); | 75 | NoopAudioPlayer(QObject *parent = 0); |
| 52 | bool isWorking() const; | 76 | virtual bool isWorking() const; |
| 53 | void setMuted(bool mute = true); | 77 | virtual void setMuted(bool mute = true); |
| 54 | bool isMuted() const; | 78 | virtual bool isMuted() const; |
| 55 | void setLoop(Sound::Type sound); | 79 | virtual void play(); |
| 56 | void play(); | 80 | virtual void play(Sound::Type sound); |
| 57 | void play(Sound::Type sound, bool wait = false); | 81 | virtual bool isPlaying(); |
| 82 | virtual void enqueue(Sound::Type sound); | ||
| 83 | virtual void pause(); | ||
| 84 | virtual bool isPaused(); | ||
| 85 | virtual void stop(); | ||
| 86 | virtual bool isStopped(); | ||
| 87 | virtual void clear(); | ||
| 88 | virtual void clearQueue(); | ||
| 89 | virtual void setPrefinishMark(qint32 msecToEnd); | ||
| 90 | |||
| 91 | protected slots: | ||
| 92 | virtual void prefinishMarkReached_ex(qint32 mark); | ||
| 58 | 93 | ||
| 59 | protected: | 94 | protected: |
| 60 | void test(QFile *testsound); | 95 | virtual void test(QFile *testsound, qint32 length); |
| 61 | void setLoop(QFile *sound); | ||
| 62 | 96 | ||
| 63 | public slots: | 97 | protected: |
| 64 | void loopEnqueue(); | 98 | bool m_working; |
| 99 | bool m_muted; | ||
| 100 | bool m_playing; | ||
| 101 | bool m_paused; | ||
| 102 | }; | ||
| 103 | |||
| 104 | /* --------------------------------------------------------------- */ | ||
| 105 | |||
| 106 | class FakeAudioPlayer | ||
| 107 | : public NoopAudioPlayer | ||
| 108 | { | ||
| 109 | Q_OBJECT | ||
| 110 | friend class AudioManager; | ||
| 111 | |||
| 112 | public: | ||
| 113 | FakeAudioPlayer(QObject *parent = 0); | ||
| 114 | virtual void play(Sound::Type sound); | ||
| 65 | 115 | ||
| 66 | protected slots: | 116 | protected slots: |
| 67 | void finished_ex(); | 117 | void finished_ex(); |
| 68 | void testFinished(); | ||
| 69 | void stateChanged_ex(Phonon::State newstate, Phonon::State oldstate); | ||
| 70 | 118 | ||
| 71 | protected: | 119 | protected: |
| 72 | bool m_working; | 120 | QTimer m_timer; |
| 73 | QFile *m_loopsound; | ||
| 74 | Phonon::AudioOutput *m_output; | ||
| 75 | }; | 121 | }; |
| 76 | 122 | ||
| 77 | /* --------------------------------------------------------------- */ | 123 | /* --------------------------------------------------------------- */ |
| @@ -102,17 +148,37 @@ protected: | |||
| 102 | 148 | ||
| 103 | /* --------------------------------------------------------------- */ | 149 | /* --------------------------------------------------------------- */ |
| 104 | 150 | ||
| 151 | class AudioPlayerFactory | ||
| 152 | { | ||
| 153 | public: | ||
| 154 | virtual ~AudioPlayerFactory() | ||
| 155 | {} | ||
| 156 | virtual AudioPlayer *create(QObject *parent = 0) = 0; | ||
| 157 | }; | ||
| 158 | |||
| 159 | Q_DECLARE_INTERFACE(AudioPlayerFactory, "at.ac.tuwien.foop.pacman.AudioPlayerFactory/1.0"); | ||
| 160 | |||
| 161 | /* --------------------------------------------------------------- */ | ||
| 162 | |||
| 163 | class NoopAudioPlayerFactory | ||
| 164 | : public AudioPlayerFactory | ||
| 165 | { | ||
| 166 | public: | ||
| 167 | virtual AudioPlayer *create(QObject *parent = 0); | ||
| 168 | }; | ||
| 169 | |||
| 170 | /* --------------------------------------------------------------- */ | ||
| 171 | |||
| 105 | class AudioManager | 172 | class AudioManager |
| 106 | : public QObject | 173 | : public QObject |
| 107 | { | 174 | { |
| 108 | Q_OBJECT | 175 | Q_OBJECT |
| 109 | friend class AudioPlayer; | ||
| 110 | friend class GaplessAudioPlayer; | 176 | friend class GaplessAudioPlayer; |
| 111 | 177 | ||
| 112 | public: | 178 | public: |
| 113 | AudioManager(); | 179 | AudioManager(); |
| 114 | static AudioManager *self(); | 180 | static AudioManager *self(); |
| 115 | bool isWorking() const; | 181 | static bool isWorking(); |
| 116 | void setMuted(bool mute = true); | 182 | void setMuted(bool mute = true); |
| 117 | bool isMuted() const; | 183 | bool isMuted() const; |
| 118 | void pause(); | 184 | void pause(); |
| @@ -121,21 +187,21 @@ public: | |||
| 121 | void clearQueue() const; | 187 | void clearQueue() const; |
| 122 | 188 | ||
| 123 | AudioPlayer *audioPlayer(); | 189 | AudioPlayer *audioPlayer(); |
| 124 | void play(Sound::Type sound, bool wait = false); | ||
| 125 | void enqueue(Sound::Type sound); | ||
| 126 | |||
| 127 | void registerAudioPlayer(AudioPlayer *player); | 190 | void registerAudioPlayer(AudioPlayer *player); |
| 128 | void unregisterAudioPlayer(AudioPlayer *player); | 191 | void unregisterAudioPlayer(AudioPlayer *player); |
| 129 | 192 | ||
| 193 | QFile *sound(Sound::Type sound); | ||
| 194 | |||
| 130 | signals: | 195 | signals: |
| 131 | void mutedChanged(bool muted); | 196 | void mutedChanged(bool muted); |
| 132 | 197 | ||
| 133 | private slots: | 198 | private slots: |
| 134 | void unregisterAudioPlayer_helper(QObject *player); | 199 | void unregisterAudioPlayer_helper(QObject *player); |
| 135 | 200 | ||
| 136 | private: | 201 | protected: |
| 137 | void preload(); | 202 | void preload(); |
| 138 | QFile *sound(Sound::Type sound); | 203 | bool tryLoadPhononPlugin(); |
| 204 | AudioPlayer *createAudioPlayer(); | ||
| 139 | 205 | ||
| 140 | private: | 206 | private: |
| 141 | bool m_muted; | 207 | bool m_muted; |
| @@ -143,6 +209,7 @@ private: | |||
| 143 | static AudioManager *m_instance; | 209 | static AudioManager *m_instance; |
| 144 | QList<QFile *> m_sounds; | 210 | QList<QFile *> m_sounds; |
| 145 | QList<AudioPlayer *> m_players; | 211 | QList<AudioPlayer *> m_players; |
| 212 | AudioPlayerFactory *m_factory; | ||
| 146 | }; | 213 | }; |
| 147 | 214 | ||
| 148 | #endif // AUDIOPLAYER_H | 215 | #endif // AUDIOPLAYER_H |
