From d0eafb0124a39eeda6c00595a943ce9811d589c4 Mon Sep 17 00:00:00 2001 From: manuel Date: Sun, 10 Apr 2011 20:50:54 +0200 Subject: major audio rewrite --- pacman-c++/audio.h | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 pacman-c++/audio.h (limited to 'pacman-c++/audio.h') 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 @@ +#ifndef AUDIO_H +#define AUDIO_H + +#include +#include +#include +#include +#include + +namespace Phonon +{ + class AudioOutput; +} + +namespace Sound +{ + enum Type + { + Intro = 0, + WakaWaka, + EatingCherry, + Die + }; +}; + +class AudioPlayer + : public Phonon::MediaObject +{ + Q_OBJECT + friend class AudioManager; + +private: + class Sleeper + : public QThread + { + public: + static void sleep(unsigned long secs); + static void msleep(unsigned long msecs); + static void usleep(unsigned long usecs); + }; + +public: + AudioPlayer(QObject *parent = 0); + bool isWorking() const; + void setMuted(bool mute = true); + bool isMuted() const; + void setLoop(QFile *sound); + void setLoop(Sound::Type sound); + +private: + void test(QFile *testsound); + +public slots: + void loopEnqueue(); + +private slots: + void testFinished(); + void stateChanged_ex(Phonon::State newstate, Phonon::State oldstate); + +private: + bool m_working; + QFile *m_loopsound; + Phonon::AudioOutput *m_output; +}; + +class AudioManager + : public QObject +{ + Q_OBJECT + friend class AudioPlayer; + +public: + AudioManager(); + static AudioManager *self(); + bool isWorking() const; + void setMuted(bool mute = true); + bool isMuted() const; + void pause(); + void stop(); + void clear(); + void clearQueue() const; + + AudioPlayer *audioPlayer(); + void play(Sound::Type sound); + void enqueue(Sound::Type sound); + + void registerAudioPlayer(AudioPlayer *player); + void unregisterAudioPlayer(AudioPlayer *player); + +signals: + void mutedChanged(bool muted); + +private slots: + void unregisterAudioPlayer_helper(QObject *player); + +private: + void preload(); + QFile *sound(Sound::Type sound); + +private: + bool m_muted; + static bool m_working; + static AudioManager *m_instance; + QList m_sounds; + QList m_players; +}; + +#endif // AUDIOPLAYER_H -- cgit v1.2.3