Skip to content

Commit

Permalink
Merge branch 'sound'
Browse files Browse the repository at this point in the history
  • Loading branch information
t3kt committed Dec 26, 2014
2 parents 5c94990 + 73516ff commit c4c782e
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 10 deletions.
6 changes: 6 additions & 0 deletions bleepout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
3205CA361A412FDC0030EE68 /* SetupController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3205CA341A412FDC0030EE68 /* SetupController.cpp */; };
32269B7B1A4A861400EF6DE4 /* RoundComponent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32269B791A4A861400EF6DE4 /* RoundComponent.cpp */; };
32269B9B1A4CA55A00EF6DE4 /* PlayerController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32269B991A4CA55A00EF6DE4 /* PlayerController.cpp */; };
32269BA11A4DD18200EF6DE4 /* AudioManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32269B9F1A4DD18200EF6DE4 /* AudioManager.cpp */; };
322D59D91A454BCF00150050 /* RendererUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 322D59D71A454BCF00150050 /* RendererUtil.cpp */; };
325750E61A4792A500CC375A /* Round1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 325750E51A4792A500CC375A /* Round1.cpp */; };
325750E91A4792E200CC375A /* Round2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 325750E81A4792E200CC375A /* Round2.cpp */; };
Expand Down Expand Up @@ -189,6 +190,8 @@
32269B7A1A4A861400EF6DE4 /* RoundComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoundComponent.h; sourceTree = "<group>"; };
32269B991A4CA55A00EF6DE4 /* PlayerController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlayerController.cpp; sourceTree = "<group>"; };
32269B9A1A4CA55A00EF6DE4 /* PlayerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlayerController.h; sourceTree = "<group>"; };
32269B9F1A4DD18200EF6DE4 /* AudioManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioManager.cpp; sourceTree = "<group>"; };
32269BA01A4DD18200EF6DE4 /* AudioManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioManager.h; sourceTree = "<group>"; };
322D59D71A454BCF00150050 /* RendererUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RendererUtil.cpp; sourceTree = "<group>"; };
322D59D81A454BCF00150050 /* RendererUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RendererUtil.h; sourceTree = "<group>"; };
325750E51A4792A500CC375A /* Round1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Round1.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -922,6 +925,8 @@
325751901A48F83B00CC375A /* AdminController.h */,
32269B791A4A861400EF6DE4 /* RoundComponent.cpp */,
32269B7A1A4A861400EF6DE4 /* RoundComponent.h */,
32269B9F1A4DD18200EF6DE4 /* AudioManager.cpp */,
32269BA01A4DD18200EF6DE4 /* AudioManager.h */,
);
path = core;
sourceTree = "<group>";
Expand Down Expand Up @@ -1284,6 +1289,7 @@
5BB4E5F61A400F500047F957 /* PhysicsWorld.cpp in Sources */,
5B0E83491A369EC30091AB99 /* ofxBulletCustomShape.cpp in Sources */,
5B0DD9091A3C497600E8BBD1 /* ofxSyphonClient.mm in Sources */,
32269BA11A4DD18200EF6DE4 /* AudioManager.cpp in Sources */,
5BB4E5EE1A400F500047F957 /* GameObject.cpp in Sources */,
325751791A48F63C00CC375A /* ofxUIScrollableCanvas.cpp in Sources */,
5BB4E5F71A400F500047F957 /* Animations.cpp in Sources */,
Expand Down
15 changes: 14 additions & 1 deletion src/config/BleepoutConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ BleepoutConfig* BleepoutConfig::createConfig() {
BleepoutConfig* config = new BleepoutConfig();
config->_syphonServerName = "Composition";
config->_syphonAppName = "Arena";

config->roundStartedSound = "";
config->roundEndedSound = "";
config->brickDestroyedSound = "";
config->collisionSound = "";
config->modifierAppliedSound = "";
config->modifierRemovedSound = "";
config->ballDestroyedSound = "";
config->playerLivesChangedSound = "";
config->playerLostSound = "";
config->countdownTimerTickSound = "";

config->_roundConfigs.push_back(ofPtr<RoundConfig>(RoundConfig::createRoundConfig1()));
config->_roundConfigs.push_back(ofPtr<RoundConfig>(RoundConfig::createRoundConfig2()));
config->_roundConfigs.push_back(ofPtr<RoundConfig>(RoundConfig::createRoundConfig3()));
Expand Down Expand Up @@ -68,7 +80,8 @@ _modifierFadeTime(0.2f),
_domeRadius(150.0f),
_domeMargin(20.0f),
_name(name),
_startDelay(0) { }
_startDelay(0),
countdownTimerPeriod(10) { }

void RoundConfig::loadJsonFile(std::string path) {
Json::Value obj;
Expand Down
13 changes: 13 additions & 0 deletions src/config/BleepoutConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class RoundConfig {
const GameRules& rules() const { return _rules; }
GameRules& rules() { return _rules; }

float countdownTimerPeriod;

Json::Value toJsonVal() const;
private:
std::string _name;
Expand Down Expand Up @@ -193,6 +195,17 @@ class BleepoutConfig {

ofPtr<RoundConfig> getRound(const std::string& name);

std::string roundStartedSound;
std::string roundEndedSound;
std::string brickDestroyedSound;
std::string collisionSound;
std::string modifierAppliedSound;
std::string modifierRemovedSound;
std::string ballDestroyedSound;
std::string playerLivesChangedSound;
std::string playerLostSound;
std::string countdownTimerTickSound;

Json::Value toJsonVal() const;
private:
int _fps;
Expand Down
3 changes: 2 additions & 1 deletion src/config/BleepoutParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ BleepoutParameters::BleepoutParameters(BleepoutConfig& appConfig)
, ballsToAdd(0)
, enableSyphon(true)
, syphonAppName(appConfig.syphonAppName())
, syphonServerName(appConfig.syphonServerName()) {
, syphonServerName(appConfig.syphonServerName())
, audioVolume(.5) {
for (const auto& round : _appConfig.roundConfigs()) {
_queuedRoundNames.push_back(round->name());
}
Expand Down
1 change: 1 addition & 0 deletions src/config/BleepoutParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BleepoutParameters {
bool enableSyphon;
std::string syphonAppName;
std::string syphonServerName;
float audioVolume;
private:
ofParameterGroup _params;
BleepoutConfig& _appConfig;
Expand Down
2 changes: 2 additions & 0 deletions src/core/AdminController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct AdminUIControls {
ofxUIButton* startRound;
ofxUIButton* endRound;
ofxUILabel* remainingTime;
ofxUISlider* audioVolume;

~AdminUIControls() {
for (auto& slot : roundQueueSlots)
Expand Down Expand Up @@ -163,6 +164,7 @@ void AdminController::setup() {
_controls->syphonAppName->setTriggerType(OFX_UI_TEXTINPUT_ON_UNFOCUS);
_controls->syphonServerName = _gui->addTextInput("Syphon Server", _appParams.syphonServerName);
_controls->syphonServerName->setTriggerType(OFX_UI_TEXTINPUT_ON_UNFOCUS);
_controls->audioVolume = _gui->addSlider("Audio Volume", 0, 1, &_appParams.audioVolume);

ofAddListener(_gui->newGUIEvent, this,
&AdminController::onUIEvent);
Expand Down
143 changes: 143 additions & 0 deletions src/core/AudioManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//
// AudioManager.cpp
// bleepout
//
// Created by tekt on 12/26/14.
//
//

#include "AudioManager.h"
#include "GameEvents.h"
#include "RoundManager.h"
#include "BleepoutApp.h"
#include "BleepoutParameters.h"

AudioManager::AudioManager(const BleepoutParameters& appParams)
: _appParams(appParams) { }


static inline void loadSoundSafe(ofSoundPlayer& sound,
const std::string& file) {
if (!file.empty())
sound.loadSound(file);
}

void AudioManager::setup() {
const BleepoutConfig& config = _appParams.appConfig();
loadSoundSafe(_roundStartedSound, config.roundStartedSound);
loadSoundSafe(_roundEndedSound, config.roundEndedSound);
loadSoundSafe(_brickDestroyedSound, config.brickDestroyedSound);
loadSoundSafe(_collisionSound, config.collisionSound);
loadSoundSafe(_modifierAppliedSound, config.modifierAppliedSound);
loadSoundSafe(_modifierRemovedSound, config.modifierRemovedSound);
loadSoundSafe(_ballDestroyedSound, config.ballDestroyedSound);
loadSoundSafe(_playerLivesChangedSound, config.playerLivesChangedSound);
loadSoundSafe(_playerLostSound, config.playerLostSound);
loadSoundSafe(_countdownTimerTickSound, config.countdownTimerTickSound);
}

void AudioManager::update() {
_roundStartedSound.setVolume(_appParams.audioVolume);
_roundEndedSound.setVolume(_appParams.audioVolume);
_brickDestroyedSound.setVolume(_appParams.audioVolume);
_collisionSound.setVolume(_appParams.audioVolume);
_modifierAppliedSound.setVolume(_appParams.audioVolume);
_modifierRemovedSound.setVolume(_appParams.audioVolume);
_ballDestroyedSound.setVolume(_appParams.audioVolume);
_brickDestroyedSound.setVolume(_appParams.audioVolume);
_playerLivesChangedSound.setVolume(_appParams.audioVolume);
_playerLostSound.setVolume(_appParams.audioVolume);
_countdownTimerTickSound.setVolume(_appParams.audioVolume);
}

void AudioManager::attachTo(BleepoutApp &app) {
ofAddListener(app.roundStartedEvent,
this, &AudioManager::onRoundStarted);
ofAddListener(app.roundEndedEvent,
this, &AudioManager::onRoundEnded);
}

void AudioManager::detachFrom(BleepoutApp &app) {
ofRemoveListener(app.roundStartedEvent,
this, &AudioManager::onRoundStarted);
ofRemoveListener(app.roundEndedEvent,
this, &AudioManager::onRoundEnded);
}

void AudioManager::attachTo(RoundController &roundController) {
ofAddListener(roundController.logicController().brickDestroyedEvent,
this, &AudioManager::onBrickDestroyed);
ofAddListener(roundController.spaceController().collisionEvent,
this, &AudioManager::onCollision);
ofAddListener(roundController.logicController().modifierAppliedEvent,
this, &AudioManager::onModifierApplied);
ofAddListener(roundController.logicController().modifierRemovedEvent,
this, &AudioManager::onModifierRemoved);
ofAddListener(roundController.logicController().ballDestroyedEvent,
this, &AudioManager::onBallDestroyed);
ofAddListener(roundController.logicController().playerLivesChangedEvent,
this, &AudioManager::onPlayerLivesChanged);
ofAddListener(roundController.logicController().playerLostEvent,
this, &AudioManager::onPlayerLost);
ofAddListener(roundController.logicController().countdownTickEvent,
this, &AudioManager::onCountdownTick);
}

void AudioManager::detachFrom(RoundController &roundController) {
ofRemoveListener(roundController.logicController().brickDestroyedEvent,
this, &AudioManager::onBrickDestroyed);
ofRemoveListener(roundController.spaceController().collisionEvent,
this, &AudioManager::onCollision);
ofRemoveListener(roundController.logicController().modifierAppliedEvent,
this, &AudioManager::onModifierApplied);
ofRemoveListener(roundController.logicController().modifierRemovedEvent,
this, &AudioManager::onModifierRemoved);
ofRemoveListener(roundController.logicController().ballDestroyedEvent,
this, &AudioManager::onBallDestroyed);
ofRemoveListener(roundController.logicController().playerLivesChangedEvent,
this, &AudioManager::onPlayerLivesChanged);
ofRemoveListener(roundController.logicController().playerLostEvent,
this, &AudioManager::onPlayerLost);
ofRemoveListener(roundController.logicController().countdownTickEvent,
this, &AudioManager::onCountdownTick);
}

void AudioManager::onRoundStarted(RoundStateEventArgs &e) {
_roundStartedSound.play();
}

void AudioManager::onRoundEnded(EmptyEventArgs &e) {
_roundEndedSound.play();
}

void AudioManager::onBrickDestroyed(BrickDestroyedEventArgs &e) {
_brickDestroyedSound.play();
}

void AudioManager::onCollision(CollisionEventArgs &e) {
_collisionSound.play();
}

void AudioManager::onModifierApplied(ModifierEventArgs &e) {
_modifierAppliedSound.play();
}

void AudioManager::onModifierRemoved(ModifierRemovedEventArgs &e) {
_modifierRemovedSound.play();
}

void AudioManager::onBallDestroyed(BallStateEventArgs &e) {
_ballDestroyedSound.play();
}

void AudioManager::onPlayerLivesChanged(PlayerStateEventArgs &e) {
_playerLivesChangedSound.play();
}

void AudioManager::onPlayerLost(PlayerStateEventArgs &e) {
_playerLostSound.play();
}

void AudioManager::onCountdownTick(TimerEventArgs &e) {
_countdownTimerTickSound.play();
}
53 changes: 53 additions & 0 deletions src/core/AudioManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// AudioManager.h
// bleepout
//
// Created by tekt on 12/26/14.
//
//

#ifndef __bleepout__AudioManager__
#define __bleepout__AudioManager__

#include <ofSoundPlayer.h>
#include "GameEvents.h"

class BleepoutParameters;
class BleepoutApp;
class RoundController;

class AudioManager {
public:
AudioManager(const BleepoutParameters& appParams);
void setup();
void update();
void attachTo(BleepoutApp& app);
void detachFrom(BleepoutApp& app);
void attachTo(RoundController& roundController);
void detachFrom(RoundController& roundController);
private:
void onRoundStarted(RoundStateEventArgs& e);
void onRoundEnded(EmptyEventArgs& e);
void onBrickDestroyed(BrickDestroyedEventArgs& e);
void onCollision(CollisionEventArgs& e);
void onModifierApplied(ModifierEventArgs& e);
void onModifierRemoved(ModifierRemovedEventArgs& e);
void onBallDestroyed(BallStateEventArgs& e);
void onPlayerLivesChanged(PlayerStateEventArgs& e);
void onPlayerLost(PlayerStateEventArgs& e);
void onCountdownTick(TimerEventArgs& e);

const BleepoutParameters& _appParams;
ofSoundPlayer _roundStartedSound;
ofSoundPlayer _roundEndedSound;
ofSoundPlayer _brickDestroyedSound;
ofSoundPlayer _collisionSound;
ofSoundPlayer _modifierAppliedSound;
ofSoundPlayer _modifierRemovedSound;
ofSoundPlayer _ballDestroyedSound;
ofSoundPlayer _playerLivesChangedSound;
ofSoundPlayer _playerLostSound;
ofSoundPlayer _countdownTimerTickSound;
};

#endif /* defined(__bleepout__AudioManager__) */
11 changes: 8 additions & 3 deletions src/core/BleepoutApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ void BleepoutApp::setup() {
_adminController->attachTo(*this);
ofAddListener(_adminController->tryStartRoundEvent, this, &BleepoutApp::onTryStartRound);
ofAddListener(_adminController->tryEndRoundEvent, this, &BleepoutApp::onTryEndRound);

_audioManager.reset(new AudioManager(*_appParams));
_audioManager->setup();
_audioManager->attachTo(*this);

_playerController.reset(new PlayerController());

Expand Down Expand Up @@ -61,6 +65,7 @@ void BleepoutApp::update() {
_syphonEnabled = _appParams->enableSyphon;
#endif
_adminController->update();
_audioManager->update();
if (_roundController) {
_roundController->update();
} else if (_setupController) {
Expand Down Expand Up @@ -91,8 +96,6 @@ void BleepoutApp::onTryStartRound(StartRoundEventArgs &e) {
return;
}
if (_roundController) {
ofRemoveListener(_roundController->tryEndRoundEvent, this,
&BleepoutApp::onTryEndRound);
ofLogError() << "Round has already been started";
return;
}
Expand All @@ -107,6 +110,7 @@ void BleepoutApp::onTryStartRound(StartRoundEventArgs &e) {
&BleepoutApp::onTryEndRound);
ofAddListener(_roundController->roundQueueEvent, _playerController.get(),
&PlayerController::onRoundQueue);
_audioManager->attachTo(*_roundController);
e.markHandled();
notifyRoundStarted(_roundController->state());
}
Expand All @@ -122,8 +126,9 @@ void BleepoutApp::onTryEndRound(EndRoundEventArgs &e) {

void BleepoutApp::endRound() {
_playerManager->setIsInRound(false);
_audioManager->detachFrom(*_roundController);
_roundController.reset();
_endingRound = true;
_endingRound = false;
notifyRoundEnded();
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/BleepoutApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "SetupController.h"
#include "GameEvents.h"
#include "AdminController.h"
#include "AudioManager.h"

#ifdef ENABLE_SYPHON
#include <ofxSyphonClient.h>
Expand Down Expand Up @@ -60,6 +61,7 @@ class BleepoutApp : public ofBaseApp, public EventSource {
ofPtr<SetupController> _setupController;
ofPtr<RoundController> _roundController;
ofPtr<AdminController> _adminController;
ofPtr<AudioManager> _audioManager;
#ifdef ENABLE_SYPHON
ofxSyphonClient _syphonClient;
#endif // ENABLE_SYPHON
Expand Down
7 changes: 7 additions & 0 deletions src/core/GameEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ void ModifierRemovedEventArgs::output(std::ostream &os) const {
os << ")";
}

void TimerEventArgs::output(std::ostream& os) const {
os << "(";
os << "current:" << _currentTime << ", ";
os << "remaining:" << _remainingTime;
os << ")";
}

void EventSource::logEvent(const char *name,
const Outputable &event) const {
if (loggingEnabled()) {
Expand Down
Loading

0 comments on commit c4c782e

Please sign in to comment.