Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
f78c01fa
Commit
f78c01fa
authored
Sep 13, 2015
by
Fabio Bas
Browse files
Avoid multiple sounds playing at the same time
parent
85aa866e
Changes
2
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/soundengine.cpp
View file @
f78c01fa
...
...
@@ -33,7 +33,7 @@
#define TEST_SOUND_FILENAME "player_join"
SoundEngine
::
SoundEngine
(
QObject
*
parent
)
:
QObject
(
parent
),
en
abled
(
false
)
:
QObject
(
parent
),
en
gine
(
0
)
{
ensureThemeDirectoryExists
();
connect
(
settingsCache
,
SIGNAL
(
soundThemeChanged
()),
this
,
SLOT
(
themeChangedSlot
()));
...
...
@@ -43,6 +43,15 @@ SoundEngine::SoundEngine(QObject *parent)
themeChangedSlot
();
}
SoundEngine
::~
SoundEngine
()
{
if
(
engine
)
{
delete
engine
;
engine
=
0
;
}
}
void
SoundEngine
::
soundEnabledChanged
()
{
if
(
settingsCache
->
getSoundEnabled
())
{
...
...
@@ -57,7 +66,7 @@ void SoundEngine::soundEnabledChanged()
}
#else
qDebug
(
"SoundEngine: enabling sound"
);
enabled
=
true
;
enabled
=
true
;
#endif
}
else
{
qDebug
(
"SoundEngine: disabling sound"
);
...
...
@@ -76,7 +85,19 @@ void SoundEngine::playSound(QString fileName)
if
(
!
fi
.
exists
())
return
;
QSound
::
play
(
fi
.
absoluteFilePath
());
if
(
engine
)
{
if
(
engine
->
isFinished
())
{
engine
->
stop
();
delete
engine
;
}
else
{
return
;
}
}
engine
=
new
QSound
(
fi
.
absoluteFilePath
());
engine
->
play
();
}
void
SoundEngine
::
testSound
()
...
...
cockatrice/src/soundengine.h
View file @
f78c01fa
...
...
@@ -6,16 +6,20 @@
#include
<QDir>
#include
<QString>
class
QSound
;
typedef
QMap
<
QString
,
QString
>
QStringMap
;
class
SoundEngine
:
public
QObject
{
Q_OBJECT
public:
SoundEngine
(
QObject
*
parent
=
0
);
~
SoundEngine
();
void
playSound
(
QString
fileName
);
QStringMap
&
getAvailableThemes
();
private:
bool
enabled
;
QSound
*
engine
;
QStringMap
availableThemes
;
protected:
void
ensureThemeDirectoryExists
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment