From ce48af53646cd9e7ec762fc1ac176b3aa620b11d Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 5 May 2011 00:57:07 +0200 Subject: - refactorized the whole project and made a few subprojects - replaced tcp with enet - added connect dialog - some smaller bugfixes --- pacman-c++/common/audio.h | 148 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 pacman-c++/common/audio.h (limited to 'pacman-c++/common/audio.h') diff --git a/pacman-c++/common/audio.h b/pacman-c++/common/audio.h new file mode 100644 index 0000000..6aec42d --- /dev/null +++ b/pacman-c++/common/audio.h @@ -0,0 +1,148 @@ +#ifndef AUDIO_H +#define AUDIO_H + +#include +#include +#include +#include +#include + +namespace Phonon +{ + class AudioOutput; +} + +namespace Sound +{ + enum Type + { + Intro = 0, + WakaWaka, + EatingFruit, + EatingGhost, + Die, + Ambient + }; + + const unsigned int length[] = { + 4310, 2090, 570, 570, 1720, + }; +}; + +/* --------------------------------------------------------------- */ + +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(Sound::Type sound); + void play(); + void play(Sound::Type sound, bool wait = false); + +protected: + void test(QFile *testsound); + void setLoop(QFile *sound); + +public slots: + void loopEnqueue(); + +protected slots: + void finished_ex(); + void testFinished(); + void stateChanged_ex(Phonon::State newstate, Phonon::State oldstate); + +protected: + bool m_working; + QFile *m_loopsound; + Phonon::AudioOutput *m_output; +}; + +/* --------------------------------------------------------------- */ + +class GaplessAudioPlayer + : public QObject +{ + Q_OBJECT + +public: + GaplessAudioPlayer(Sound::Type sound, qint32 mark, QObject *parent = 0); + bool isWorking() const; + void setMuted(bool mute = true); + bool isMuted() const; + void play(); + void pause(); + +protected slots: + void startPlayer1(); + void startPlayer2(); + +protected: + bool m_working; + Sound::Type m_sound; + AudioPlayer *m_player1; + AudioPlayer *m_player2; +}; + +/* --------------------------------------------------------------- */ + +class AudioManager + : public QObject +{ + Q_OBJECT + friend class AudioPlayer; + friend class GaplessAudioPlayer; + +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, bool wait = false); + 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