Skip to content

Commit

Permalink
Merge pull request #7 from tomneda/dev_tomneda
Browse files Browse the repository at this point in the history
Adapt audio output
  • Loading branch information
m1ld3 authored Feb 9, 2025
2 parents 1c81285 + 212edee commit 821a8b7
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 199 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@
CMakeLists.txt.user
CMakeFiles/
*.autosave

# CLion, Linux
/cmake-build-*/
/build/
/.idea/
1 change: 1 addition & 0 deletions inc/alltime_stats_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QChart>
#include <QLineSeries>
#include <QChartView>
#include <QPointer>

namespace Ui
{
Expand Down
33 changes: 20 additions & 13 deletions inc/sound_handler.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef SOUND_HANDLER_H
#define SOUND_HANDLER_H

#include <QSoundEffect>
#include <QMediaPlayer>
#include <QAudioOutput>


class CSoundHandler : public QObject
Expand All @@ -18,13 +19,13 @@ class CSoundHandler : public QObject

void set_muted(bool iMuted)
{
mBustedSound.setMuted(iMuted);
mGameShotSound.setMuted(iMuted);
mGameOnSound.setMuted(iMuted);
mScoreSound.setMuted(iMuted);
mBustedSound.audioOutput()->setMuted(iMuted);
mGameShotSound.audioOutput()->setMuted(iMuted);
mGameOnSound.audioOutput()->setMuted(iMuted);
mScoreSound.audioOutput()->setMuted(iMuted);
}

void set_score_sound_source(const QString & iSoundPath) { mScoreSound.setSource(iSoundPath); }
void set_score_sound_source(const QString & iSoundPath) { mScoreSound.setSource(QUrl(iSoundPath)); }
void play_score_sound() { mScoreSound.play(); }
void play_game_on_sound() { mGameOnSound.play(); }
void play_busted_sound() { mBustedSound.play(); }
Expand All @@ -38,15 +39,21 @@ class CSoundHandler : public QObject
, mGameOnSound(this)
, mScoreSound(this)
{
mBustedSound.setSource(QUrl("qrc:/resources/sounds/busted.wav"));
mGameShotSound.setSource(QUrl("qrc:/resources/sounds/gameshot.wav"));
mGameOnSound.setSource(QUrl("qrc:/resources/sounds/gameon.wav"));
// each QMediaPlayer needs its own QAudioOutput
mBustedSound.setAudioOutput(new QAudioOutput);
mGameShotSound.setAudioOutput(new QAudioOutput);
mGameOnSound.setAudioOutput(new QAudioOutput);
mScoreSound.setAudioOutput(new QAudioOutput);

mBustedSound.setSource(QUrl("qrc:/resources/sounds/busted.mp3"));
mGameShotSound.setSource(QUrl("qrc:/resources/sounds/gameshot.mp3"));
mGameOnSound.setSource(QUrl("qrc:/resources/sounds/gameon.mp3"));
}

QSoundEffect mBustedSound;
QSoundEffect mGameShotSound;
QSoundEffect mGameOnSound;
QSoundEffect mScoreSound;
QMediaPlayer mBustedSound;
QMediaPlayer mGameShotSound;
QMediaPlayer mGameOnSound;
QMediaPlayer mScoreSound;
};

#endif // SOUND_HANDLER_H
Loading

0 comments on commit 821a8b7

Please sign in to comment.