diff options
Diffstat (limited to 'pacman-c++/audio.cpp')
| -rw-r--r-- | pacman-c++/audio.cpp | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/pacman-c++/audio.cpp b/pacman-c++/audio.cpp index 6365a15..c0cc5b0 100644 --- a/pacman-c++/audio.cpp +++ b/pacman-c++/audio.cpp | |||
| @@ -155,9 +155,9 @@ QFile *AudioManager::sound(Sound::Type sound) | |||
| 155 | AudioPlayer::AudioPlayer(QObject *parent) | 155 | AudioPlayer::AudioPlayer(QObject *parent) |
| 156 | : Phonon::MediaObject(parent) | 156 | : Phonon::MediaObject(parent) |
| 157 | { | 157 | { |
| 158 | m_working = AudioManager::m_working; | ||
| 158 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); | 159 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); |
| 159 | Phonon::createPath(this, m_output); | 160 | Phonon::createPath(this, m_output); |
| 160 | m_working = AudioManager::m_working; | ||
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | bool AudioPlayer::isWorking() const | 163 | bool AudioPlayer::isWorking() const |
| @@ -255,6 +255,72 @@ void AudioPlayer::loopEnqueue() | |||
| 255 | 255 | ||
| 256 | /* --------------------------------------------------------------- */ | 256 | /* --------------------------------------------------------------- */ |
| 257 | 257 | ||
| 258 | GaplessAudioPlayer::GaplessAudioPlayer(Sound::Type sound, qint32 mark, QObject *parent) | ||
| 259 | : QObject(parent), m_sound(sound) | ||
| 260 | { | ||
| 261 | m_working = AudioManager::m_working; | ||
| 262 | if (!m_working) | ||
| 263 | return; | ||
| 264 | |||
| 265 | m_player1 = new AudioPlayer(this); | ||
| 266 | m_player2 = new AudioPlayer(this); | ||
| 267 | |||
| 268 | m_player2->setPrefinishMark(mark); | ||
| 269 | m_player1->setPrefinishMark(mark); | ||
| 270 | |||
| 271 | connect(m_player1, SIGNAL(prefinishMarkReached(qint32)), this, SLOT(startPlayer2())); | ||
| 272 | connect(m_player2, SIGNAL(prefinishMarkReached(qint32)), this, SLOT(startPlayer1())); | ||
| 273 | |||
| 274 | AudioManager::self()->registerAudioPlayer(m_player1); | ||
| 275 | AudioManager::self()->registerAudioPlayer(m_player2); | ||
| 276 | } | ||
| 277 | |||
| 278 | bool GaplessAudioPlayer::isWorking() const | ||
| 279 | { | ||
| 280 | return m_working; | ||
| 281 | } | ||
| 282 | |||
| 283 | void GaplessAudioPlayer::setMuted(bool mute) | ||
| 284 | { | ||
| 285 | m_player1->setMuted(mute); | ||
| 286 | m_player2->setMuted(mute); | ||
| 287 | } | ||
| 288 | |||
| 289 | bool GaplessAudioPlayer::isMuted() const | ||
| 290 | { | ||
| 291 | return m_player1->isMuted() && m_player2->isMuted(); | ||
| 292 | } | ||
| 293 | |||
| 294 | void GaplessAudioPlayer::play() | ||
| 295 | { | ||
| 296 | if (!m_working) | ||
| 297 | return; | ||
| 298 | if (m_player1->state() != Phonon::PlayingState && m_player2->state() != Phonon::PlayingState) | ||
| 299 | startPlayer1(); | ||
| 300 | } | ||
| 301 | |||
| 302 | void GaplessAudioPlayer::pause() | ||
| 303 | { | ||
| 304 | if (!m_working) | ||
| 305 | return; | ||
| 306 | if (m_player1->state() != Phonon::PausedState) | ||
| 307 | m_player1->pause(); | ||
| 308 | if (m_player2->state() != Phonon::PausedState) | ||
| 309 | m_player2->pause(); | ||
| 310 | } | ||
| 311 | |||
| 312 | void GaplessAudioPlayer::startPlayer1() | ||
| 313 | { | ||
| 314 | m_player1->play(m_sound); | ||
| 315 | } | ||
| 316 | |||
| 317 | void GaplessAudioPlayer::startPlayer2() | ||
| 318 | { | ||
| 319 | m_player2->play(m_sound); | ||
| 320 | } | ||
| 321 | |||
| 322 | /* --------------------------------------------------------------- */ | ||
| 323 | |||
| 258 | void AudioPlayer::Sleeper::sleep(unsigned long secs) | 324 | void AudioPlayer::Sleeper::sleep(unsigned long secs) |
| 259 | { | 325 | { |
| 260 | QThread::sleep(secs); | 326 | QThread::sleep(secs); |
