added helper functions for setting and getting music and sfx volume

main
Martin Felis (berta) 2010-11-15 00:27:08 +01:00
parent 94ce6cbdb9
commit e981f68a9c
2 changed files with 35 additions and 0 deletions

View File

@ -1,3 +1,5 @@
#include <cmath>
#include "SoundBase.h" #include "SoundBase.h"
#include "SoundBaseGlobal.h" #include "SoundBaseGlobal.h"
@ -172,7 +174,25 @@ void SoundBase::HaltMusic () {
mCurrentMusic = NULL; mCurrentMusic = NULL;
} }
void SoundBase::SetMusicVolume(const float &music_volume) {
int mix_volume = static_cast<int> (fabsf(music_volume) * MIX_MAX_VOLUME);
Mix_VolumeMusic(mix_volume);
}
float SoundBase::GetMusicVolume() {
return static_cast<float>(Mix_VolumeMusic(-1)) / static_cast<float>(MIX_MAX_VOLUME);
}
void SoundBase::SetEffectsVolume(const float &effects_volume) {
int mix_volume = static_cast<int> (fabsf(effects_volume) * MIX_MAX_VOLUME);
Mix_Volume(-1, mix_volume);
}
float SoundBase::GetEffectsVolume() {
return static_cast<float>(Mix_Volume(-1, -1)) / static_cast<float>(MIX_MAX_VOLUME);
}
/* /*
* Global Functions * Global Functions
*/ */

View File

@ -39,6 +39,21 @@ class SoundBase : public Module {
void PlayMusic (const std::string &music_name); void PlayMusic (const std::string &music_name);
void HaltMusic (); void HaltMusic ();
/** \brief Sets the volume of the music channel to the given value
*
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
*/
void SetMusicVolume (const float &music_volume);
/** \brief Returns the value of the music (0. - 1.) */
float GetMusicVolume ();
/** \brief Sets the volume of the music channel to the given value
*
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
*/
void SetEffectsVolume (const float &effects_volume);
/** \brief Returns the value of the effects (0. - 1.) */
float GetEffectsVolume ();
protected: protected:
/** \brief Initializes the system */ /** \brief Initializes the system */
virtual int OnInit (int argc, char* argv[]); virtual int OnInit (int argc, char* argv[]);