From 20afba1adc84dd0e859605250c5a44a111045c2b Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sat, 18 Feb 2012 22:47:30 +0100 Subject: Added notification sound on receiving whisper One of the sound channels is reserved for notification sounds, of which the volume can be configured separately. Currently, the only notification sound that is played is for receiving whispers. That can be extended later. The newmessage.ogg sound used currently is the one for receiving a message with the Psi instant messenger. Parts of this patch are based on the new message notification in ManaPlus. Reviewed-by: Erik Schilling --- src/sound.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/sound.cpp') diff --git a/src/sound.cpp b/src/sound.cpp index e8348a40..1af1f136 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -31,6 +31,10 @@ #include "resources/resourcemanager.h" #include "resources/soundeffect.h" +enum { + CHANNEL_NOTIFICATIONS = 0 +}; + /** * This will be set to true, when a music can be freed after a fade out * Currently used by fadeOutCallBack() @@ -49,6 +53,7 @@ static void fadeOutCallBack() Sound::Sound(): mInstalled(false), mSfxVolume(100), + mNotificationsVolume(100), mMusicVolume(60), mMusic(NULL) { @@ -90,8 +95,10 @@ void Sound::init() } Mix_AllocateChannels(16); + Mix_ReserveChannels(1); // reserve one channel for notification sounds Mix_VolumeMusic(mMusicVolume); Mix_Volume(-1, mSfxVolume); + Mix_Volume(CHANNEL_NOTIFICATIONS, mNotificationsVolume); info(); @@ -154,7 +161,18 @@ void Sound::setSfxVolume(int volume) mSfxVolume = volume; if (mInstalled) + { Mix_Volume(-1, mSfxVolume); + Mix_Volume(CHANNEL_NOTIFICATIONS, mNotificationsVolume); + } +} + +void Sound::setNotificationsVolume(int volume) +{ + mNotificationsVolume = volume; + + if (mInstalled) + Mix_Volume(CHANNEL_NOTIFICATIONS, mNotificationsVolume); } static Music *loadMusic(const std::string &fileName) @@ -281,6 +299,17 @@ void Sound::playSfx(const std::string &path, int x, int y) } } +void Sound::playNotification(const std::string &path) +{ + const std::string fullPath = paths.getValue("sfx", "sfx/") + path; + + ResourceManager *resman = ResourceManager::getInstance(); + if (SoundEffect *sample = resman->getSoundEffect(fullPath)) + { + sample->play(0, 128, CHANNEL_NOTIFICATIONS); + } +} + void Sound::close() { if (!mInstalled) -- cgit v1.2.3-70-g09d2