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
8f6de663
Commit
8f6de663
authored
Apr 22, 2012
by
Max-Wilhelm Bruker
Browse files
don't call QAudioOutput constructor unless sound is enabled
parent
81d7c08f
Changes
4
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/settingscache.cpp
View file @
8f6de663
...
...
@@ -191,6 +191,7 @@ void SettingsCache::setSoundEnabled(int _soundEnabled)
{
soundEnabled
=
_soundEnabled
;
settings
->
setValue
(
"sound/enabled"
,
soundEnabled
);
emit
soundEnabledChanged
();
}
void
SettingsCache
::
setSoundPath
(
const
QString
&
_soundPath
)
...
...
cockatrice/src/settingscache.h
View file @
8f6de663
...
...
@@ -22,6 +22,7 @@ signals:
void
horizontalHandChanged
();
void
invertVerticalCoordinateChanged
();
void
minPlayersForMultiColumnLayoutChanged
();
void
soundEnabledChanged
();
void
soundPathChanged
();
void
ignoreUnregisteredUsersChanged
();
private:
...
...
cockatrice/src/soundengine.cpp
View file @
8f6de663
...
...
@@ -6,20 +6,14 @@
#include
<QBuffer>
SoundEngine
::
SoundEngine
(
QObject
*
parent
)
:
QObject
(
parent
)
:
QObject
(
parent
)
,
audio
(
0
)
{
inputBuffer
=
new
QBuffer
;
QAudioFormat
format
;
format
.
setFrequency
(
44100
);
format
.
setChannels
(
1
);
format
.
setSampleSize
(
16
);
format
.
setCodec
(
"audio/pcm"
);
format
.
setByteOrder
(
QAudioFormat
::
LittleEndian
);
format
.
setSampleType
(
QAudioFormat
::
SignedInt
);
audio
=
new
QAudioOutput
(
format
,
this
);
inputBuffer
=
new
QBuffer
(
this
);
connect
(
settingsCache
,
SIGNAL
(
soundPathChanged
()),
this
,
SLOT
(
cacheData
()));
connect
(
settingsCache
,
SIGNAL
(
soundEnabledChanged
()),
this
,
SLOT
(
soundEnabledChanged
()));
cacheData
();
soundEnabledChanged
();
}
void
SoundEngine
::
cacheData
()
...
...
@@ -34,9 +28,29 @@ void SoundEngine::cacheData()
}
}
void
SoundEngine
::
soundEnabledChanged
()
{
if
(
settingsCache
->
getSoundEnabled
())
{
qDebug
(
"SoundEngine: enabling sound"
);
QAudioFormat
format
;
format
.
setFrequency
(
44100
);
format
.
setChannels
(
1
);
format
.
setSampleSize
(
16
);
format
.
setCodec
(
"audio/pcm"
);
format
.
setByteOrder
(
QAudioFormat
::
LittleEndian
);
format
.
setSampleType
(
QAudioFormat
::
SignedInt
);
audio
=
new
QAudioOutput
(
format
,
this
);
}
else
if
(
audio
)
{
qDebug
(
"SoundEngine: disabling sound"
);
audio
->
stop
();
audio
->
deleteLater
();
audio
=
0
;
}
}
void
SoundEngine
::
playSound
(
const
QString
&
fileName
)
{
if
(
!
settingsCache
->
getSoundEnabled
()
)
if
(
!
audio
)
return
;
audio
->
stop
();
...
...
cockatrice/src/soundengine.h
View file @
8f6de663
...
...
@@ -16,6 +16,7 @@ private:
QAudioOutput
*
audio
;
private
slots
:
void
cacheData
();
void
soundEnabledChanged
();
public:
SoundEngine
(
QObject
*
parent
=
0
);
public
slots
:
...
...
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