summaryrefslogtreecommitdiffstats
path: root/pacman-c++/common/audio.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-05-05 00:57:07 +0200
committermanuel <manuel@mausz.at>2011-05-05 00:57:07 +0200
commitce48af53646cd9e7ec762fc1ac176b3aa620b11d (patch)
treef8fbf2cae8c7d0cbac2696a8f4cf94410bfb4928 /pacman-c++/common/audio.h
parente54ccad07e256ba877bd41d70bd358bd0085bd1e (diff)
downloadfoop-ce48af53646cd9e7ec762fc1ac176b3aa620b11d.tar.gz
foop-ce48af53646cd9e7ec762fc1ac176b3aa620b11d.tar.bz2
foop-ce48af53646cd9e7ec762fc1ac176b3aa620b11d.zip
- refactorized the whole project and made a few subprojects
- replaced tcp with enet - added connect dialog - some smaller bugfixes
Diffstat (limited to 'pacman-c++/common/audio.h')
-rw-r--r--pacman-c++/common/audio.h148
1 files changed, 148 insertions, 0 deletions
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 @@
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
10namespace Phonon
11{
12 class AudioOutput;
13}
14
15namespace Sound
16{
17 enum Type
18 {
19 Intro = 0,
20 WakaWaka,
21 EatingFruit,
22 EatingGhost,
23 Die,
24 Ambient
25 };
26
27 const unsigned int length[] = {
28 4310, 2090, 570, 570, 1720,
29 };
30};
31
32/* --------------------------------------------------------------- */
33
34class AudioPlayer
35 : public Phonon::MediaObject
36{
37 Q_OBJECT
38 friend class AudioManager;
39
40private:
41 class Sleeper
42 : public QThread
43 {
44 public:
45 static void sleep(unsigned long secs);
46 static void msleep(unsigned long msecs);
47 static void usleep(unsigned long usecs);
48 };
49
50public:
51 AudioPlayer(QObject *parent = 0);
52 bool isWorking() const;
53 void setMuted(bool mute = true);
54 bool isMuted() const;
55 void setLoop(Sound::Type sound);
56 void play();
57 void play(Sound::Type sound, bool wait = false);
58
59protected:
60 void test(QFile *testsound);
61 void setLoop(QFile *sound);
62
63public slots:
64 void loopEnqueue();
65
66protected slots:
67 void finished_ex();
68 void testFinished();
69 void stateChanged_ex(Phonon::State newstate, Phonon::State oldstate);
70
71protected:
72 bool m_working;
73 QFile *m_loopsound;
74 Phonon::AudioOutput *m_output;
75};
76
77/* --------------------------------------------------------------- */
78
79class GaplessAudioPlayer
80 : public QObject
81{
82 Q_OBJECT
83
84public:
85 GaplessAudioPlayer(Sound::Type sound, qint32 mark, QObject *parent = 0);
86 bool isWorking() const;
87 void setMuted(bool mute = true);
88 bool isMuted() const;
89 void play();
90 void pause();
91
92protected slots:
93 void startPlayer1();
94 void startPlayer2();
95
96protected:
97 bool m_working;
98 Sound::Type m_sound;
99 AudioPlayer *m_player1;
100 AudioPlayer *m_player2;
101};
102
103/* --------------------------------------------------------------- */
104
105class AudioManager
106 : public QObject
107{
108 Q_OBJECT
109 friend class AudioPlayer;
110 friend class GaplessAudioPlayer;
111
112public:
113 AudioManager();
114 static AudioManager *self();
115 bool isWorking() const;
116 void setMuted(bool mute = true);
117 bool isMuted() const;
118 void pause();
119 void stop();
120 void clear();
121 void clearQueue() const;
122
123 AudioPlayer *audioPlayer();
124 void play(Sound::Type sound, bool wait = false);
125 void enqueue(Sound::Type sound);
126
127 void registerAudioPlayer(AudioPlayer *player);
128 void unregisterAudioPlayer(AudioPlayer *player);
129
130signals:
131 void mutedChanged(bool muted);
132
133private slots:
134 void unregisterAudioPlayer_helper(QObject *player);
135
136private:
137 void preload();
138 QFile *sound(Sound::Type sound);
139
140private:
141 bool m_muted;
142 static bool m_working;
143 static AudioManager *m_instance;
144 QList<QFile *> m_sounds;
145 QList<AudioPlayer *> m_players;
146};
147
148#endif // AUDIOPLAYER_H