Merge pull request #1498 from ctrlaltca/sound_whatever

Reworked SoundEngine overhaul
This commit is contained in:
Zach
2015-09-12 00:35:20 -04:00
19 changed files with 100 additions and 129 deletions
+4 -12
View File
@@ -137,22 +137,14 @@ set(COCKATRICE_LIBS)
# Qt4 stuff # Qt4 stuff
if(Qt4_FOUND) if(Qt4_FOUND)
if (NOT QT_QTMULTIMEDIA_FOUND)
FIND_PACKAGE(QtMobility REQUIRED)
endif()
SET(QT_USE_QTNETWORK TRUE) SET(QT_USE_QTNETWORK TRUE)
SET(QT_USE_QTMULTIMEDIA TRUE)
SET(QT_USE_QTSVG TRUE) SET(QT_USE_QTSVG TRUE)
# Include directories # Include directories
INCLUDE(${QT_USE_FILE}) INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${QT_INCLUDES}) INCLUDE_DIRECTORIES(${QT_INCLUDES})
INCLUDE_DIRECTORIES(${QT_MOBILITY_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${QT_MOBILITY_MULTIMEDIAKIT_INCLUDE_DIR})
LIST(APPEND COCKATRICE_LIBS ${QT_LIBRARIES}) LIST(APPEND COCKATRICE_LIBS ${QT_LIBRARIES})
LIST(APPEND COCKATRICE_LIBS ${QT_QTMAIN_LIBRARY}) LIST(APPEND COCKATRICE_LIBS ${QT_QTMAIN_LIBRARY})
LIST(APPEND COCKATRICE_LIBS ${QT_MOBILITY_MULTIMEDIAKIT_LIBRARY})
# Let cmake chew Qt4's translations and resource files # Let cmake chew Qt4's translations and resource files
# Note: header files are MOC-ed automatically by cmake # Note: header files are MOC-ed automatically by cmake
@@ -281,11 +273,11 @@ if(APPLE)
set(plugin_dest_dir cockatrice.app/Contents/Plugins) set(plugin_dest_dir cockatrice.app/Contents/Plugins)
set(qtconf_dest_dir cockatrice.app/Contents/Resources) set(qtconf_dest_dir cockatrice.app/Contents/Resources)
# qt4: codecs, iconengines, imageformats, phonon_backend # qt4: codecs, iconengines, imageformats
# qt5: audio, iconengines, imageformats, platforms, printsupport # qt5: audio, iconengines, imageformats, platforms, printsupport
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
FILES_MATCHING REGEX "(audio|codecs|iconengines|imageformats|phonon_backend|platforms|printsupport)/.*\\.dylib" FILES_MATCHING REGEX "(audio|codecs|iconengines|imageformats|platforms|printsupport)/.*\\.dylib"
REGEX ".*_debug\\.dylib" EXCLUDE) REGEX ".*_debug\\.dylib" EXCLUDE)
install(CODE " install(CODE "
@@ -309,11 +301,11 @@ if(WIN32)
set(plugin_dest_dir Plugins) set(plugin_dest_dir Plugins)
set(qtconf_dest_dir .) set(qtconf_dest_dir .)
# qt4: codecs, iconengines, imageformats, phonon_backend # qt4: codecs, iconengines, imageformats
# qt5: audio, iconengines, imageformats, platforms, printsupport # qt5: audio, iconengines, imageformats, platforms, printsupport
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
FILES_MATCHING REGEX "(audio|codecs|iconengines|imageformats|phonon_backend|platforms|printsupport)/.*[^d]\\.dll") FILES_MATCHING REGEX "(audio|codecs|iconengines|imageformats|platforms|printsupport)/.*[^d]\\.dll")
install(CODE " install(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths] file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
+3
View File
@@ -11,6 +11,7 @@
#include "pixmapgenerator.h" #include "pixmapgenerator.h"
#include "settingscache.h" #include "settingscache.h"
#include "tab_userlists.h" #include "tab_userlists.h"
#include "soundengine.h"
const QColor DEFAULT_MENTION_COLOR = QColor(194, 31, 47); const QColor DEFAULT_MENTION_COLOR = QColor(194, 31, 47);
const QColor OTHER_USER_COLOR = QColor(0, 65, 255); // dark blue 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? if (userName.toLower() == fullMentionUpToSpaceOrEnd.toLower()) // Is this user you?
{ {
// You have received a valid mention!! // You have received a valid mention!!
soundEngine->playSound("chat_mention");
mentionFormat.setBackground(QBrush(getCustomMentionColor())); mentionFormat.setBackground(QBrush(getCustomMentionColor()));
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black)); mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
cursor.insertText(mention, mentionFormat); cursor.insertText(mention, mentionFormat);
@@ -301,6 +303,7 @@ void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &send
if (isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd)) { if (isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd)) {
// Moderator Sending Global Message // Moderator Sending Global Message
soundEngine->playSound("all_mention");
mentionFormat.setBackground(QBrush(getCustomMentionColor())); mentionFormat.setBackground(QBrush(getCustomMentionColor()));
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black)); mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
cursor.insertText("@" + fullMentionUpToSpaceOrEnd, mentionFormat); cursor.insertText("@" + fullMentionUpToSpaceOrEnd, mentionFormat);
+2 -2
View File
@@ -646,7 +646,7 @@ SoundSettingsPage::SoundSettingsPage()
connect(soundPathClearButton, SIGNAL(clicked()), this, SLOT(soundPathClearButtonClicked())); connect(soundPathClearButton, SIGNAL(clicked()), this, SLOT(soundPathClearButtonClicked()));
QPushButton *soundPathButton = new QPushButton("..."); QPushButton *soundPathButton = new QPushButton("...");
connect(soundPathButton, SIGNAL(clicked()), this, SLOT(soundPathButtonClicked())); connect(soundPathButton, SIGNAL(clicked()), this, SLOT(soundPathButtonClicked()));
connect(&soundTestButton, SIGNAL(clicked()), soundEngine, SLOT(playerJoined())); connect(&soundTestButton, SIGNAL(clicked()), soundEngine, SLOT(testSound()));
masterVolumeSlider = new QSlider(Qt::Horizontal); masterVolumeSlider = new QSlider(Qt::Horizontal);
masterVolumeSlider->setMinimum(0); masterVolumeSlider->setMinimum(0);
@@ -654,7 +654,7 @@ SoundSettingsPage::SoundSettingsPage()
masterVolumeSlider->setValue(settingsCache->getMasterVolume()); masterVolumeSlider->setValue(settingsCache->getMasterVolume());
masterVolumeSlider->setToolTip(QString::number(settingsCache->getMasterVolume())); masterVolumeSlider->setToolTip(QString::number(settingsCache->getMasterVolume()));
connect(settingsCache, SIGNAL(masterVolumeChanged(int)), this, SLOT(masterVolumeChanged(int))); connect(settingsCache, SIGNAL(masterVolumeChanged(int)), this, SLOT(masterVolumeChanged(int)));
connect(masterVolumeSlider, SIGNAL(sliderReleased()), soundEngine, SLOT(playerJoined())); connect(masterVolumeSlider, SIGNAL(sliderReleased()), soundEngine, SLOT(testSound()));
connect(masterVolumeSlider, SIGNAL(valueChanged(int)), settingsCache, SLOT(setMasterVolume(int))); connect(masterVolumeSlider, SIGNAL(valueChanged(int)), settingsCache, SLOT(setMasterVolume(int)));
+31 -14
View File
@@ -37,7 +37,7 @@ bool MessageLogWidget::userIsFemale() const
void MessageLogWidget::logGameJoined(int gameId) void MessageLogWidget::logGameJoined(int gameId)
{ {
soundEngine->playerJoined(); soundEngine->playSound("player_join");
if (userIsFemale()) if (userIsFemale())
appendHtmlServerMessage(tr("You have joined game #%1.", "female").arg("<font color=\"blue\">"+ QString::number(gameId) + "</font>")); appendHtmlServerMessage(tr("You have joined game #%1.", "female").arg("<font color=\"blue\">"+ QString::number(gameId) + "</font>"));
else else
@@ -54,7 +54,7 @@ void MessageLogWidget::logReplayStarted(int gameId)
void MessageLogWidget::logJoin(Player *player) void MessageLogWidget::logJoin(Player *player)
{ {
soundEngine->playerJoined(); soundEngine->playSound("player_join");
if (isFemale(player)) if (isFemale(player))
appendHtmlServerMessage(tr("%1 has joined the game.", "female").arg(sanitizeHtml(player->getName()))); appendHtmlServerMessage(tr("%1 has joined the game.", "female").arg(sanitizeHtml(player->getName())));
else else
@@ -63,6 +63,7 @@ void MessageLogWidget::logJoin(Player *player)
void MessageLogWidget::logLeave(Player *player) void MessageLogWidget::logLeave(Player *player)
{ {
soundEngine->playSound("player_leave");
if (isFemale(player)) if (isFemale(player))
appendHtmlServerMessage(tr("%1 has left the game.", "female").arg(sanitizeHtml(player->getName()))); appendHtmlServerMessage(tr("%1 has left the game.", "female").arg(sanitizeHtml(player->getName())));
else else
@@ -81,11 +82,13 @@ void MessageLogWidget::logKicked()
void MessageLogWidget::logJoinSpectator(QString name) void MessageLogWidget::logJoinSpectator(QString name)
{ {
soundEngine->playSound("spectator_join");
appendHtmlServerMessage(tr("%1 is now watching the game.").arg(sanitizeHtml(name))); appendHtmlServerMessage(tr("%1 is now watching the game.").arg(sanitizeHtml(name)));
} }
void MessageLogWidget::logLeaveSpectator(QString name) void MessageLogWidget::logLeaveSpectator(QString name)
{ {
soundEngine->playSound("spectator_leave");
appendHtmlServerMessage(tr("%1 is not watching the game any more.").arg(sanitizeHtml(name))); 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) void MessageLogWidget::logConcede(Player *player)
{ {
soundEngine->playSound("player_concede");
if (isFemale(player)) if (isFemale(player))
appendHtmlServerMessage(tr("%1 has conceded the game.", "female").arg(sanitizeHtml(player->getName()))); appendHtmlServerMessage(tr("%1 has conceded the game.", "female").arg(sanitizeHtml(player->getName())));
else else
@@ -148,11 +152,13 @@ void MessageLogWidget::logGameStart()
void MessageLogWidget::logConnectionStateChanged(Player *player, bool connectionState) void MessageLogWidget::logConnectionStateChanged(Player *player, bool connectionState)
{ {
if (connectionState) { if (connectionState) {
soundEngine->playSound("player_reconnect");
if (isFemale(player)) if (isFemale(player))
appendHtmlServerMessage(tr("%1 has restored connection to the game.", "female").arg(sanitizeHtml(player->getName()))); appendHtmlServerMessage(tr("%1 has restored connection to the game.", "female").arg(sanitizeHtml(player->getName())));
else else
appendHtmlServerMessage(tr("%1 has restored connection to the game.", "male").arg(sanitizeHtml(player->getName()))); appendHtmlServerMessage(tr("%1 has restored connection to the game.", "male").arg(sanitizeHtml(player->getName())));
} else { } else {
soundEngine->playSound("player_disconnect");
if (isFemale(player)) if (isFemale(player))
appendHtmlServerMessage(tr("%1 has lost connection to the game.", "female").arg(sanitizeHtml(player->getName()))); appendHtmlServerMessage(tr("%1 has lost connection to the game.", "female").arg(sanitizeHtml(player->getName())));
else else
@@ -172,6 +178,7 @@ void MessageLogWidget::logSpectatorSay(QString spectatorName, UserLevelFlags spe
void MessageLogWidget::logShuffle(Player *player, CardZone *zone) void MessageLogWidget::logShuffle(Player *player, CardZone *zone)
{ {
soundEngine->playSound("shuffle");
if (currentContext != MessageContext_Mulligan) { if (currentContext != MessageContext_Mulligan) {
appendHtmlServerMessage((isFemale(player) appendHtmlServerMessage((isFemale(player)
? tr("%1 shuffles %2.", "female") ? 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) void MessageLogWidget::logRollDie(Player *player, int sides, int roll)
{ {
soundEngine->playSound("roll_dice");
if (isFemale(player)) if (isFemale(player))
appendHtmlServerMessage(tr("%1 rolls a %2 with a %3-sided die.", "female").arg(sanitizeHtml(player->getName())).arg("<font color=\"blue\">" + QString::number(roll) + "</font>").arg("<font color=\"blue\">" + QString::number(sides) + "</font>")); appendHtmlServerMessage(tr("%1 rolls a %2 with a %3-sided die.", "female").arg(sanitizeHtml(player->getName())).arg("<font color=\"blue\">" + QString::number(roll) + "</font>").arg("<font color=\"blue\">" + QString::number(sides) + "</font>"));
else else
@@ -194,6 +202,7 @@ void MessageLogWidget::logDrawCards(Player *player, int number)
if (currentContext == MessageContext_Mulligan) if (currentContext == MessageContext_Mulligan)
mulliganPlayer = player; mulliganPlayer = player;
else { else {
soundEngine->playSound("draw_card");
if (isFemale(player)) if (isFemale(player))
appendHtmlServerMessage(tr("%1 draws %2 card(s).", "female").arg(sanitizeHtml(player->getName())).arg("<font color=\"blue\">" + QString::number(number) + "</font>")); appendHtmlServerMessage(tr("%1 draws %2 card(s).", "female").arg(sanitizeHtml(player->getName())).arg("<font color=\"blue\">" + QString::number(number) + "</font>"));
else else
@@ -296,6 +305,7 @@ void MessageLogWidget::doMoveCard(LogMoveCard &attributes)
QString finalStr; QString finalStr;
if (targetName == "table") { if (targetName == "table") {
soundEngine->playSound("play_card");
if (moveCardTapped.value(attributes.card)) if (moveCardTapped.value(attributes.card))
finalStr = tr("%1 puts %2 into play tapped%3."); finalStr = tr("%1 puts %2 into play tapped%3.");
else else
@@ -318,6 +328,7 @@ void MessageLogWidget::doMoveCard(LogMoveCard &attributes)
} else if (targetName == "sb") } else if (targetName == "sb")
finalStr = tr("%1 moves %2%3 to sideboard."); finalStr = tr("%1 moves %2%3 to sideboard.");
else if (targetName == "stack") { else if (targetName == "stack") {
soundEngine->playSound("play_card");
finalStr = tr("%1 plays %2%3."); 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) 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) if (currentContext == MessageContext_MoveCard)
moveCardTapped.insert(card, tapped); 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) void MessageLogWidget::logSetCounter(Player *player, QString counterName, int value, int oldValue)
{ {
if (counterName == "life")
soundEngine->playSound("life_change");
QString str; QString str;
if (isFemale(player)) if (isFemale(player))
str = tr("%1 sets counter %2 to %3 (%4%5).", "female"); str = tr("%1 sets counter %2 to %3 (%4%5).", "female");
@@ -799,17 +816,17 @@ void MessageLogWidget::logSetActivePhase(int phase)
{ {
QString phaseName; QString phaseName;
switch (phase) { switch (phase) {
case 0: phaseName = tr("untap step"); break; case 0: phaseName = tr("untap step"); soundEngine->playSound("untap_step"); break;
case 1: phaseName = tr("upkeep step"); break; case 1: phaseName = tr("upkeep step"); soundEngine->playSound("upkeep_step"); break;
case 2: phaseName = tr("draw step"); break; case 2: phaseName = tr("draw step"); soundEngine->playSound("draw_step"); break;
case 3: phaseName = tr("first main phase"); break; case 3: phaseName = tr("first main phase"); soundEngine->playSound("main_1"); break;
case 4: phaseName = tr("beginning of combat step"); break; case 4: phaseName = tr("beginning of combat step"); soundEngine->playSound("start_combat"); break;
case 5: phaseName = tr("declare attackers step"); soundEngine->attack(); break; case 5: phaseName = tr("declare attackers step"); soundEngine->playSound("attack_step"); break;
case 6: phaseName = tr("declare blockers step"); break; case 6: phaseName = tr("declare blockers step"); soundEngine->playSound("block_step"); break;
case 7: phaseName = tr("combat damage step"); break; case 7: phaseName = tr("combat damage step"); soundEngine->playSound("damage_step"); break;
case 8: phaseName = tr("end of combat step"); break; case 8: phaseName = tr("end of combat step"); soundEngine->playSound("end_combat"); break;
case 9: phaseName = tr("second main phase"); break; case 9: phaseName = tr("second main phase"); soundEngine->playSound("main_2"); break;
case 10: phaseName = tr("ending phase"); soundEngine->endStep(); break; case 10: phaseName = tr("ending phase"); soundEngine->playSound("end_step"); break;
} }
appendHtml("<font color=\"green\"><b>" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") + tr("It is now the %1.").arg(phaseName) + "</b></font>"); appendHtml("<font color=\"green\"><b>" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") + tr("It is now the %1.").arg(phaseName) + "</b></font>");
} }
+46 -75
View File
@@ -1,102 +1,73 @@
#include "soundengine.h" #include "soundengine.h"
#include "settingscache.h" #include "settingscache.h"
#include <QAudioOutput>
#include <QAudioFormat> #include <QFileInfo>
#include <QFile> #include <QSound>
#include <QBuffer>
/*
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";
*/
#define TEST_SOUND_FILENAME "player_join"
SoundEngine::SoundEngine(QObject *parent) SoundEngine::SoundEngine(QObject *parent)
: QObject(parent), audio(0) : QObject(parent), enabled(false)
{ {
inputBuffer = new QBuffer(this);
connect(settingsCache, SIGNAL(soundPathChanged()), this, SLOT(cacheData()));
connect(settingsCache, SIGNAL(soundEnabledChanged()), this, SLOT(soundEnabledChanged())); connect(settingsCache, SIGNAL(soundEnabledChanged()), this, SLOT(soundEnabledChanged()));
cacheData();
soundEnabledChanged(); 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();
}
} }
void SoundEngine::soundEnabledChanged() void SoundEngine::soundEnabledChanged()
{ {
if (settingsCache->getSoundEnabled()) { if (settingsCache->getSoundEnabled()) {
#if QT_VERSION < 0x050000 //QT4
if(QSound::isAvailable())
{
qDebug("SoundEngine: enabling sound"); qDebug("SoundEngine: enabling sound");
QAudioFormat format; enabled = true;
#if QT_VERSION < 0x050000 } else {
format.setFrequency(44100); qDebug("SoundEngine: sound not available");
format.setChannels(1); enabled = false;
}
#else #else
format.setSampleRate(44100); qDebug("SoundEngine: enabling sound");
format.setChannelCount(1); enabled = true;
#endif #endif
format.setSampleSize(16); } else {
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
audio = new QAudioOutput(format, this);
} else if (audio) {
qDebug("SoundEngine: disabling sound"); qDebug("SoundEngine: disabling sound");
audio->stop(); enabled = false;
audio->deleteLater();
audio = 0;
} }
} }
void SoundEngine::playSound(const QString &fileName) #include <QDebug>
void SoundEngine::playSound(QString fileName)
{ {
if (!audio) if(!enabled)
return; return;
audio->stop(); QFileInfo fi(settingsCache->getSoundPath() + "/" + fileName + ".wav");
inputBuffer->close(); qDebug() << "playing" << fi.absoluteFilePath();
inputBuffer->setData(audioData[fileName]); if(!fi.exists())
inputBuffer->open(QIODevice::ReadOnly); return;
#if QT_VERSION >= 0x050000
audio->setVolume(settingsCache->getMasterVolume() / 100.0);
#endif
audio->start(inputBuffer);
QSound::play(fi.absoluteFilePath());
} }
void SoundEngine::endStep() void SoundEngine::testSound()
{ {
if (lastEndStepPlayed.secsTo(QDateTime::currentDateTime()) >= 1) playSound(TEST_SOUND_FILENAME);
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();
} }
+3 -18
View File
@@ -2,34 +2,19 @@
#define SOUNDENGINE_H #define SOUNDENGINE_H
#include <QObject> #include <QObject>
#include <QMap>
#include <QDateTime>
class QAudioOutput;
class QBuffer;
class SoundEngine : public QObject { class SoundEngine : public QObject {
Q_OBJECT Q_OBJECT
private: private:
void playSound(const QString &fileName); bool enabled;
QMap<QString, QByteArray> audioData;
QBuffer *inputBuffer;
QAudioOutput *audio;
QDateTime lastTapPlayed;
QDateTime lastEndStepPlayed;
QDateTime lastAttackStepPlayed;
private slots: private slots:
void cacheData();
void soundEnabledChanged(); void soundEnabledChanged();
public: public:
SoundEngine(QObject *parent = 0); SoundEngine(QObject *parent = 0);
void playSound(QString fileName);
public slots: public slots:
void endStep(); void testSound();
void tap();
void playerJoined();
void attack();
}; };
extern SoundEngine *soundEngine; extern SoundEngine *soundEngine;
#endif #endif
+5 -2
View File
@@ -3,13 +3,14 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include <QSystemTrayIcon>
#include <QApplication>
#include "tab_message.h" #include "tab_message.h"
#include "abstractclient.h" #include "abstractclient.h"
#include "chatview.h" #include "chatview.h"
#include "main.h" #include "main.h"
#include "settingscache.h" #include "settingscache.h"
#include <QSystemTrayIcon> #include "soundengine.h"
#include <QApplication>
#include "pending_command.h" #include "pending_command.h"
#include "pb/session_commands.pb.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()); 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); 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)) if (settingsCache->getShowMessagePopup() && shouldShowSystemPopup(event))
showSystemPopup(event); showSystemPopup(event);
+1 -1
View File
@@ -2,7 +2,7 @@
# #
# Installs default sound files # Installs default sound files
FILE(GLOB sounds "${CMAKE_CURRENT_SOURCE_DIR}/*.raw") FILE(GLOB sounds "${CMAKE_CURRENT_SOURCE_DIR}/*.wav")
if(UNIX) if(UNIX)
if(APPLE) if(APPLE)
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -10,7 +10,7 @@ if [[ $TRAVIS_OS_NAME == "osx" ]] ; then
else else
if (( QT4 )); then if (( QT4 )); then
sudo apt-get update -qq sudo apt-get update -qq
sudo apt-get install -y qtmobility-dev libprotobuf-dev protobuf-compiler libqt4-dev sudo apt-get install -y libprotobuf-dev protobuf-compiler libqt4-dev
else else
sudo add-apt-repository -y ppa:beineri/opt-qt521 sudo add-apt-repository -y ppa:beineri/opt-qt521
sudo add-apt-repository -y ppa:kalakris/cmake sudo add-apt-repository -y ppa:kalakris/cmake