diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp
index 00dbd3a6..9f77faaf 100644
--- a/cockatrice/src/chatview.cpp
+++ b/cockatrice/src/chatview.cpp
@@ -11,6 +11,7 @@
#include "pixmapgenerator.h"
#include "settingscache.h"
#include "tab_userlists.h"
+#include "soundengine.h"
const QColor DEFAULT_MENTION_COLOR = QColor(194, 31, 47);
const QColor OTHER_USER_COLOR = QColor(0, 65, 255); // dark blue
@@ -276,6 +277,7 @@ void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &send
if (userName.toLower() == fullMentionUpToSpaceOrEnd.toLower()) // Is this user you?
{
// You have received a valid mention!!
+ soundEngine->playSound("chat_mention");
mentionFormat.setBackground(QBrush(getCustomMentionColor()));
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
cursor.insertText(mention, mentionFormat);
@@ -301,6 +303,7 @@ void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &send
if (isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd)) {
// Moderator Sending Global Message
+ soundEngine->playSound("all_mention");
mentionFormat.setBackground(QBrush(getCustomMentionColor()));
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
cursor.insertText("@" + fullMentionUpToSpaceOrEnd, mentionFormat);
diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp
index 7b76d8b9..127c0d3d 100644
--- a/cockatrice/src/messagelogwidget.cpp
+++ b/cockatrice/src/messagelogwidget.cpp
@@ -37,7 +37,7 @@ bool MessageLogWidget::userIsFemale() const
void MessageLogWidget::logGameJoined(int gameId)
{
- soundEngine->playerJoined();
+ soundEngine->playSound("player_join");
if (userIsFemale())
appendHtmlServerMessage(tr("You have joined game #%1.", "female").arg(""+ QString::number(gameId) + ""));
else
@@ -54,7 +54,7 @@ void MessageLogWidget::logReplayStarted(int gameId)
void MessageLogWidget::logJoin(Player *player)
{
- soundEngine->playerJoined();
+ soundEngine->playSound("player_join");
if (isFemale(player))
appendHtmlServerMessage(tr("%1 has joined the game.", "female").arg(sanitizeHtml(player->getName())));
else
@@ -63,6 +63,7 @@ void MessageLogWidget::logJoin(Player *player)
void MessageLogWidget::logLeave(Player *player)
{
+ soundEngine->playSound("player_leave");
if (isFemale(player))
appendHtmlServerMessage(tr("%1 has left the game.", "female").arg(sanitizeHtml(player->getName())));
else
@@ -81,11 +82,13 @@ void MessageLogWidget::logKicked()
void MessageLogWidget::logJoinSpectator(QString name)
{
+ soundEngine->playSound("spectator_join");
appendHtmlServerMessage(tr("%1 is now watching the game.").arg(sanitizeHtml(name)));
}
void MessageLogWidget::logLeaveSpectator(QString name)
{
+ soundEngine->playSound("spectator_leave");
appendHtmlServerMessage(tr("%1 is not watching the game any more.").arg(sanitizeHtml(name)));
}
@@ -134,6 +137,7 @@ void MessageLogWidget::logSetSideboardLock(Player *player, bool locked)
void MessageLogWidget::logConcede(Player *player)
{
+ soundEngine->playSound("player_concede");
if (isFemale(player))
appendHtmlServerMessage(tr("%1 has conceded the game.", "female").arg(sanitizeHtml(player->getName())));
else
@@ -148,11 +152,13 @@ void MessageLogWidget::logGameStart()
void MessageLogWidget::logConnectionStateChanged(Player *player, bool connectionState)
{
if (connectionState) {
+ soundEngine->playSound("player_reconnect");
if (isFemale(player))
appendHtmlServerMessage(tr("%1 has restored connection to the game.", "female").arg(sanitizeHtml(player->getName())));
else
appendHtmlServerMessage(tr("%1 has restored connection to the game.", "male").arg(sanitizeHtml(player->getName())));
} else {
+ soundEngine->playSound("player_disconnect");
if (isFemale(player))
appendHtmlServerMessage(tr("%1 has lost connection to the game.", "female").arg(sanitizeHtml(player->getName())));
else
@@ -172,6 +178,7 @@ void MessageLogWidget::logSpectatorSay(QString spectatorName, UserLevelFlags spe
void MessageLogWidget::logShuffle(Player *player, CardZone *zone)
{
+ soundEngine->playSound("shuffle");
if (currentContext != MessageContext_Mulligan) {
appendHtmlServerMessage((isFemale(player)
? tr("%1 shuffles %2.", "female")
@@ -183,6 +190,7 @@ void MessageLogWidget::logShuffle(Player *player, CardZone *zone)
void MessageLogWidget::logRollDie(Player *player, int sides, int roll)
{
+ soundEngine->playSound("roll_dice");
if (isFemale(player))
appendHtmlServerMessage(tr("%1 rolls a %2 with a %3-sided die.", "female").arg(sanitizeHtml(player->getName())).arg("" + QString::number(roll) + "").arg("" + QString::number(sides) + ""));
else
@@ -194,6 +202,7 @@ void MessageLogWidget::logDrawCards(Player *player, int number)
if (currentContext == MessageContext_Mulligan)
mulliganPlayer = player;
else {
+ soundEngine->playSound("draw_card");
if (isFemale(player))
appendHtmlServerMessage(tr("%1 draws %2 card(s).", "female").arg(sanitizeHtml(player->getName())).arg("" + QString::number(number) + ""));
else
@@ -296,6 +305,7 @@ void MessageLogWidget::doMoveCard(LogMoveCard &attributes)
QString finalStr;
if (targetName == "table") {
+ soundEngine->playSound("play_card");
if (moveCardTapped.value(attributes.card))
finalStr = tr("%1 puts %2 into play tapped%3.");
else
@@ -318,6 +328,7 @@ void MessageLogWidget::doMoveCard(LogMoveCard &attributes)
} else if (targetName == "sb")
finalStr = tr("%1 moves %2%3 to sideboard.");
else if (targetName == "stack") {
+ soundEngine->playSound("play_card");
finalStr = tr("%1 plays %2%3.");
}
@@ -565,7 +576,10 @@ void MessageLogWidget::logSetCardCounter(Player *player, QString cardName, int c
void MessageLogWidget::logSetTapped(Player *player, CardItem *card, bool tapped)
{
- soundEngine->tap();
+ if (tapped)
+ soundEngine->playSound("tap_card");
+ else
+ soundEngine->playSound("untap_card");
if (currentContext == MessageContext_MoveCard)
moveCardTapped.insert(card, tapped);
@@ -603,6 +617,9 @@ void MessageLogWidget::logSetTapped(Player *player, CardItem *card, bool tapped)
void MessageLogWidget::logSetCounter(Player *player, QString counterName, int value, int oldValue)
{
+ if (counterName == "life")
+ soundEngine->playSound("life_change");
+
QString str;
if (isFemale(player))
str = tr("%1 sets counter %2 to %3 (%4%5).", "female");
@@ -799,17 +816,17 @@ void MessageLogWidget::logSetActivePhase(int phase)
{
QString phaseName;
switch (phase) {
- case 0: phaseName = tr("untap step"); break;
- case 1: phaseName = tr("upkeep step"); break;
- case 2: phaseName = tr("draw step"); break;
- case 3: phaseName = tr("first main phase"); break;
- case 4: phaseName = tr("beginning of combat step"); break;
- case 5: phaseName = tr("declare attackers step"); soundEngine->attack(); break;
- case 6: phaseName = tr("declare blockers step"); break;
- case 7: phaseName = tr("combat damage step"); break;
- case 8: phaseName = tr("end of combat step"); break;
- case 9: phaseName = tr("second main phase"); break;
- case 10: phaseName = tr("ending phase"); soundEngine->endStep(); break;
+ case 0: phaseName = tr("untap step"); soundEngine->playSound("untap_step"); break;
+ case 1: phaseName = tr("upkeep step"); soundEngine->playSound("upkeep_step"); break;
+ case 2: phaseName = tr("draw step"); soundEngine->playSound("draw_step"); break;
+ case 3: phaseName = tr("first main phase"); soundEngine->playSound("main_1"); break;
+ case 4: phaseName = tr("beginning of combat step"); soundEngine->playSound("start_combat"); break;
+ case 5: phaseName = tr("declare attackers step"); soundEngine->playSound("attack_step"); break;
+ case 6: phaseName = tr("declare blockers step"); soundEngine->playSound("block_step"); break;
+ case 7: phaseName = tr("combat damage step"); soundEngine->playSound("damage_step"); break;
+ case 8: phaseName = tr("end of combat step"); soundEngine->playSound("end_combat"); break;
+ case 9: phaseName = tr("second main phase"); soundEngine->playSound("main_2"); break;
+ case 10: phaseName = tr("ending phase"); soundEngine->playSound("end_step"); break;
}
appendHtml("" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") + tr("It is now the %1.").arg(phaseName) + "");
}
diff --git a/cockatrice/src/soundengine.cpp b/cockatrice/src/soundengine.cpp
index e3192726..3f966a7e 100644
--- a/cockatrice/src/soundengine.cpp
+++ b/cockatrice/src/soundengine.cpp
@@ -4,48 +4,76 @@
#include
#include
#include
+#include
+#if QT_VERSION > 0x050000
+ #include
+ #include
+#endif
SoundEngine::SoundEngine(QObject *parent)
- : QObject(parent), audio(0)
+: QObject(parent), audio(0)
{
+ enabled = false;
inputBuffer = new QBuffer(this);
connect(settingsCache, SIGNAL(soundPathChanged()), this, SLOT(cacheData()));
connect(settingsCache, SIGNAL(soundEnabledChanged()), this, SLOT(soundEnabledChanged()));
cacheData();
soundEnabledChanged();
-
- lastTapPlayed = QDateTime::currentDateTime();
- lastEndStepPlayed = QDateTime::currentDateTime();
- lastAttackStepPlayed = QDateTime::currentDateTime();
}
void SoundEngine::cacheData()
{
- static const QStringList fileNames = QStringList()
- << "end_step" << "tap" << "player_joined" << "attack";
- for (int i = 0; i < fileNames.size(); ++i) {
- QFile file(settingsCache->getSoundPath() + "/" + fileNames[i] + ".raw");
- if(!file.exists())
- continue;
- file.open(QIODevice::ReadOnly);
- audioData.insert(fileNames[i], file.readAll());
- file.close();
- }
+ fileNames = QStringList()
+ /*Phases*/
+ << "untap_step" << "upkeep_step" << "draw_step" << "main_1"
+ << "start_combat" << "attack_step" << "block_step" << "damage_step" << "end_combat"
+ << "main_2" << "end_step"
+ /*Game Actions*/
+ << "draw_card" << "play_card" << "tap_card" << "untap_card"
+ << "shuffle" << "roll_dice" << "life_change"
+ /*Player*/
+ << "player_join" << "player_leave" << "player_disconnect" << "player_reconnect" << "player_concede"
+ /*Spectator*/
+ << "spectator_join" << "spectator_leave"
+ /*Chat & UI*/
+ << "chat_mention" << "all_mention" << "private_message";
+
+ #if QT_VERSION < 0x050000 //QT4
+ for (int i = 0; i < fileNames.size(); ++i) {
+ QFile file(settingsCache->getSoundPath() + "/" + fileNames[i] + ".wav");
+ if(!file.exists())
+ continue;
+ file.open(QIODevice::ReadOnly);
+ file.seek(44);
+ audioCache.insert(fileNames[i], file.readAll());
+ file.close();
+ }
+ #else //QT5
+ QStringList ext = QStringList() << ".mp4" << ".mp3" << ".wav";
+ for (int i = 0; i < fileNames.size(); ++i) {
+ for (int j = 0; j < ext.size(); ++j) {
+ QString filepath = settingsCache->getSoundPath() + "/" + fileNames[i] + ext[j];
+ QFile file(filepath);
+ if (file.exists()){
+ QMediaPlayer *player = new QMediaPlayer;
+ player->setMedia(QUrl::fromLocalFile(filepath));
+ audioData.insert(fileNames[i], player);
+ break;
+ }
+ }
+ }
+ #endif
}
void SoundEngine::soundEnabledChanged()
{
+#if QT_VERSION < 0x050000 //QT4
if (settingsCache->getSoundEnabled()) {
qDebug("SoundEngine: enabling sound");
QAudioFormat format;
-#if QT_VERSION < 0x050000
- format.setFrequency(44100);
- format.setChannels(1);
-#else
format.setSampleRate(44100);
format.setChannelCount(1);
-#endif
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
@@ -57,46 +85,41 @@ void SoundEngine::soundEnabledChanged()
audio->deleteLater();
audio = 0;
}
+#else //QT5
+ if (settingsCache->getSoundEnabled()) {
+ qDebug("SoundEngine: enabling sound");
+ enabled = true;
+ }else{
+ qDebug("SoundEngine: disabling sound");
+ enabled = false;
+ for (int i = 0; i < fileNames.size(); ++i) {
+ if (audioData.contains(fileNames[i]) &&
+ audioData[fileNames[i]]->state() != QMediaPlayer::StoppedState)
+ audioData[fileNames[i]]->stop();
+ }
+ }
+#endif
}
-void SoundEngine::playSound(const QString &fileName)
+void SoundEngine::playSound(QString fileName)
{
- if (!audio)
+#if QT_VERSION < 0x050000 //QT4
+ if (!fileNames.contains(fileName) || !audio)
return;
audio->stop();
inputBuffer->close();
- inputBuffer->setData(audioData[fileName]);
+ inputBuffer->setData(audioCache[fileName]);
inputBuffer->open(QIODevice::ReadOnly);
-#if QT_VERSION >= 0x050000
- audio->setVolume(settingsCache->getMasterVolume() / 100.0);
-#endif
audio->start(inputBuffer);
-
-}
+#else //QT5
+ if (!audioData.contains(fileName) || !enabled){
+ return;
+ }
-void SoundEngine::endStep()
-{
- if (lastEndStepPlayed.secsTo(QDateTime::currentDateTime()) >= 1)
- playSound("end_step");
- lastEndStepPlayed = QDateTime::currentDateTime();
-}
-
-void SoundEngine::tap()
-{
- if (lastTapPlayed.secsTo(QDateTime::currentDateTime()) >= 1)
- playSound("tap");
- lastTapPlayed = QDateTime::currentDateTime();
-}
-
-void SoundEngine::playerJoined()
-{
- playSound("player_joined");
-}
-
-
-void SoundEngine::attack() {
- if (lastAttackStepPlayed.secsTo(QDateTime::currentDateTime()) >= 1)
- playSound("attack");
- lastAttackStepPlayed = QDateTime::currentDateTime();
-}
+ audioData[fileName]->setVolume(settingsCache->getMasterVolume());
+ audioData[fileName]->stop();
+ audioData[fileName]->setPosition(0);
+ audioData[fileName]->play();
+#endif
+}
\ No newline at end of file
diff --git a/cockatrice/src/soundengine.h b/cockatrice/src/soundengine.h
index fb1cbd73..29d91db2 100644
--- a/cockatrice/src/soundengine.h
+++ b/cockatrice/src/soundengine.h
@@ -4,6 +4,10 @@
#include
#include
#include
+#include
+#if QT_VERSION > 0x050000
+ #include
+#endif
class QAudioOutput;
class QBuffer;
@@ -11,25 +15,22 @@ class QBuffer;
class SoundEngine : public QObject {
Q_OBJECT
private:
- void playSound(const QString &fileName);
- QMap audioData;
+ QMap audioCache;
QBuffer *inputBuffer;
QAudioOutput *audio;
- QDateTime lastTapPlayed;
- QDateTime lastEndStepPlayed;
- QDateTime lastAttackStepPlayed;
+ bool enabled;
+ QStringList fileNames;
+
+ #if QT_VERSION > 0x050000
+ QMap audioData;
+ #endif
private slots:
void cacheData();
void soundEnabledChanged();
public:
SoundEngine(QObject *parent = 0);
-public slots:
- void endStep();
- void tap();
- void playerJoined();
- void attack();
+ void playSound(QString fileName);
};
extern SoundEngine *soundEngine;
-
#endif
diff --git a/cockatrice/src/tab_message.cpp b/cockatrice/src/tab_message.cpp
index 4bc20ed0..61a23fc6 100644
--- a/cockatrice/src/tab_message.cpp
+++ b/cockatrice/src/tab_message.cpp
@@ -3,13 +3,14 @@
#include
#include
#include
+#include
+#include
#include "tab_message.h"
#include "abstractclient.h"
#include "chatview.h"
#include "main.h"
#include "settingscache.h"
-#include
-#include
+#include "soundengine.h"
#include "pending_command.h"
#include "pb/session_commands.pb.h"
@@ -111,6 +112,8 @@ void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
{
const UserLevelFlags userLevel(event.sender_name() == otherUserInfo->name() ? otherUserInfo->user_level() : ownUserInfo->user_level());
chatView->appendMessage(QString::fromStdString(event.message()), QString::fromStdString(event.sender_name()), userLevel, true);
+ if (tabSupervisor->currentIndex() != tabSupervisor->indexOf(this))
+ soundEngine->playSound("private_message");
if (settingsCache->getShowMessagePopup() && shouldShowSystemPopup(event))
showSystemPopup(event);
diff --git a/sounds/CMakeLists.txt b/sounds/CMakeLists.txt
index cd9f6c33..7712abb9 100644
--- a/sounds/CMakeLists.txt
+++ b/sounds/CMakeLists.txt
@@ -2,7 +2,7 @@
#
# Installs default sound files
-FILE(GLOB sounds "${CMAKE_CURRENT_SOURCE_DIR}/*.raw")
+FILE(GLOB sounds "${CMAKE_CURRENT_SOURCE_DIR}/*.wav")
if(UNIX)
if(APPLE)
diff --git a/sounds/attack.raw b/sounds/attack.raw
deleted file mode 100644
index d9edd2a2..00000000
Binary files a/sounds/attack.raw and /dev/null differ
diff --git a/sounds/attack.wav b/sounds/attack.wav
new file mode 100644
index 00000000..e604155d
Binary files /dev/null and b/sounds/attack.wav differ
diff --git a/sounds/end_step.raw b/sounds/end_step.raw
deleted file mode 100644
index 7ae52545..00000000
Binary files a/sounds/end_step.raw and /dev/null differ
diff --git a/sounds/end_step.wav b/sounds/end_step.wav
new file mode 100644
index 00000000..eb58dffb
Binary files /dev/null and b/sounds/end_step.wav differ
diff --git a/sounds/player_joined.raw b/sounds/player_joined.raw
deleted file mode 100644
index d3294958..00000000
Binary files a/sounds/player_joined.raw and /dev/null differ
diff --git a/sounds/player_joined.wav b/sounds/player_joined.wav
new file mode 100644
index 00000000..3289155e
Binary files /dev/null and b/sounds/player_joined.wav differ
diff --git a/sounds/start_combat.raw b/sounds/start_combat.raw
deleted file mode 100644
index d9edd2a2..00000000
Binary files a/sounds/start_combat.raw and /dev/null differ
diff --git a/sounds/start_combat.wav b/sounds/start_combat.wav
new file mode 100644
index 00000000..e604155d
Binary files /dev/null and b/sounds/start_combat.wav differ
diff --git a/sounds/tap.raw b/sounds/tap.raw
deleted file mode 100644
index 179f0cf0..00000000
Binary files a/sounds/tap.raw and /dev/null differ
diff --git a/sounds/tap.wav b/sounds/tap.wav
new file mode 100644
index 00000000..62f56a8c
Binary files /dev/null and b/sounds/tap.wav differ