diff options
Diffstat (limited to 'pacman-c++/audio.h')
| -rw-r--r-- | pacman-c++/audio.h | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/pacman-c++/audio.h b/pacman-c++/audio.h new file mode 100644 index 0000000..bea7fb8 --- /dev/null +++ b/pacman-c++/audio.h | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | #ifndef AUDIO_H | ||
| 2 | #define AUDIO_H | ||
| 3 | |||
| 4 | #include <QObject> | ||
| 5 | #include <QList> | ||
| 6 | #include <QFile> | ||
| 7 | #include <QThread> | ||
| 8 | #include <phonon/MediaObject> | ||
| 9 | |||
| 10 | namespace Phonon | ||
| 11 | { | ||
| 12 | class AudioOutput; | ||
| 13 | } | ||
| 14 | |||
| 15 | namespace Sound | ||
| 16 | { | ||
| 17 | enum Type | ||
| 18 | { | ||
| 19 | Intro = 0, | ||
| 20 | WakaWaka, | ||
| 21 | EatingCherry, | ||
| 22 | Die | ||
| 23 | }; | ||
| 24 | }; | ||
| 25 | |||
| 26 | class AudioPlayer | ||
| 27 | : public Phonon::MediaObject | ||
| 28 | { | ||
| 29 | Q_OBJECT | ||
| 30 | friend class AudioManager; | ||
| 31 | |||
| 32 | private: | ||
| 33 | class Sleeper | ||
| 34 | : public QThread | ||
| 35 | { | ||
| 36 | public: | ||
| 37 | static void sleep(unsigned long secs); | ||
| 38 | static void msleep(unsigned long msecs); | ||
| 39 | static void usleep(unsigned long usecs); | ||
| 40 | }; | ||
| 41 | |||
| 42 | public: | ||
| 43 | AudioPlayer(QObject *parent = 0); | ||
| 44 | bool isWorking() const; | ||
| 45 | void setMuted(bool mute = true); | ||
| 46 | bool isMuted() const; | ||
| 47 | void setLoop(QFile *sound); | ||
| 48 | void setLoop(Sound::Type sound); | ||
| 49 | |||
| 50 | private: | ||
| 51 | void test(QFile *testsound); | ||
| 52 | |||
| 53 | public slots: | ||
| 54 | void loopEnqueue(); | ||
| 55 | |||
| 56 | private slots: | ||
| 57 | void testFinished(); | ||
| 58 | void stateChanged_ex(Phonon::State newstate, Phonon::State oldstate); | ||
| 59 | |||
| 60 | private: | ||
| 61 | bool m_working; | ||
| 62 | QFile *m_loopsound; | ||
| 63 | Phonon::AudioOutput *m_output; | ||
| 64 | }; | ||
| 65 | |||
| 66 | class AudioManager | ||
| 67 | : public QObject | ||
| 68 | { | ||
| 69 | Q_OBJECT | ||
| 70 | friend class AudioPlayer; | ||
| 71 | |||
| 72 | public: | ||
| 73 | AudioManager(); | ||
| 74 | static AudioManager *self(); | ||
| 75 | bool isWorking() const; | ||
| 76 | void setMuted(bool mute = true); | ||
| 77 | bool isMuted() const; | ||
| 78 | void pause(); | ||
| 79 | void stop(); | ||
| 80 | void clear(); | ||
| 81 | void clearQueue() const; | ||
| 82 | |||
| 83 | AudioPlayer *audioPlayer(); | ||
| 84 | void play(Sound::Type sound); | ||
| 85 | void enqueue(Sound::Type sound); | ||
| 86 | |||
| 87 | void registerAudioPlayer(AudioPlayer *player); | ||
| 88 | void unregisterAudioPlayer(AudioPlayer *player); | ||
| 89 | |||
| 90 | signals: | ||
| 91 | void mutedChanged(bool muted); | ||
| 92 | |||
| 93 | private slots: | ||
| 94 | void unregisterAudioPlayer_helper(QObject *player); | ||
| 95 | |||
| 96 | private: | ||
| 97 | void preload(); | ||
| 98 | QFile *sound(Sound::Type sound); | ||
| 99 | |||
| 100 | private: | ||
| 101 | bool m_muted; | ||
| 102 | static bool m_working; | ||
| 103 | static AudioManager *m_instance; | ||
| 104 | QList<QFile *> m_sounds; | ||
| 105 | QList<AudioPlayer *> m_players; | ||
| 106 | }; | ||
| 107 | |||
| 108 | #endif // AUDIOPLAYER_H | ||
