00001 //© Copyright 2010 - 2011 BlackTopp Studios Inc. 00002 /* This file is part of The Mezzanine Engine. 00003 00004 The Mezzanine Engine is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 The Mezzanine Engine is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 /* The original authors have included a copy of the license specified above in the 00018 'Docs' folder. See 'gpl.txt' 00019 */ 00020 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to 00021 Build professional software and charge for their product. 00022 00023 However there are some practical restrictions, so if your project involves 00024 any of the following you should contact us and we will try to work something 00025 out: 00026 - DRM or Copy Protection of any kind(except Copyrights) 00027 - Software Patents You Do Not Wish to Freely License 00028 - Any Kind of Linking to Non-GPL licensed Works 00029 - Are Currently In Violation of Another Copyright Holder's GPL License 00030 - If You want to change our code and not add a few hundred MB of stuff to 00031 your distribution 00032 00033 These and other limitations could cause serious legal problems if you ignore 00034 them, so it is best to simply contact us or the Free Software Foundation, if 00035 you have any questions. 00036 00037 Joseph Toppi - toppij@gmail.com 00038 John Blackwood - makoenergy02@gmail.com 00039 */ 00040 #ifndef _audiomanager_h 00041 #define _audiomanager_h 00042 00043 #include "crossplatformexport.h" 00044 #include "datatypes.h" 00045 #include "managerbase.h" 00046 #include "singleton.h" 00047 00048 namespace cAudio 00049 { 00050 class IAudioManager; 00051 class IAudioSource; 00052 class IListener; 00053 } 00054 00055 namespace Mezzanine 00056 { 00057 namespace Audio 00058 { 00059 class Sound; 00060 class Listener; 00061 class SoundSet; 00062 class MusicPlayer; 00063 } 00064 00065 // Used by the scripting language binder to help create bindgings for this class. SWIG does know to creation template instances 00066 #ifdef SWIG 00067 %template(SingletonAudioManager) Singleton<AudioManager>; 00068 #endif 00069 00070 /////////////////////////////////////////////////////////////////////////////// 00071 /// @class AudioManager 00072 /// @headerfile audiomanager.h 00073 /// @brief This is simply a place for storing all the Sound utilities and functions. 00074 /// @details This is a place for loading, storing, and running sound files as 00075 /// necessary in a given game. 00076 /////////////////////////////////////////////////////////////////////////////// 00077 class MEZZ_LIB AudioManager : public ManagerBase, public Singleton<AudioManager> 00078 { 00079 protected: 00080 cAudio::IAudioManager* cAudioManager; 00081 std::map< String, Audio::SoundSet* > SoundSets; 00082 std::map< String, Audio::Sound* > Sounds; 00083 std::vector< Audio::Sound* > AmbientSounds; 00084 std::vector< Audio::Sound* > DialogSounds; 00085 std::vector< Audio::Sound* > EffectSounds; 00086 std::vector< Audio::Sound* > MusicSounds; 00087 Real AmbientVolume; 00088 Real DialogVolume; 00089 Real EffectVolume; 00090 Real MusicVolume; 00091 Real MasterVolume; 00092 Real MuteStandby; 00093 bool Muted; 00094 Audio::Listener* Listener; 00095 Audio::MusicPlayer* MusicPlayer; 00096 public: 00097 /// @brief Class Constructor 00098 /// @details This is the class constructor. It gives you the option to start up the manager 00099 /// with default values if you choose. If not then you'll need to setup and initialize the 00100 /// manager yourself after it is constructed. 00101 /// @param DefaultSettings Whether or not to load default settings and initialize the manager immediately. 00102 AudioManager(bool DefaultSettings=true); 00103 /// @brief Class Destructor 00104 /// @details The class destructor. 00105 virtual ~AudioManager(); 00106 00107 /////////////////////////////////////////////////////////////////////////////// 00108 // Sound Management 00109 00110 /// @brief Creates an ambient sound instance from a file that can be used to play sounds. 00111 /// @param SoundName The name of the Sound instance. 00112 /// @param FileName The name of the file. 00113 /// @param Group The resource group in which the file resides. 00114 /// @return Returns a pointer to the Sound Instance that was created. 00115 virtual Audio::Sound* CreateAmbientSound(ConstString& SoundName, ConstString& FileName, ConstString& Group); 00116 /// @brief Creates an dialog sound instance from a file that can be used to play sounds. 00117 /// @param SoundName The name of the Sound instance. 00118 /// @param FileName The name of the file. 00119 /// @param Group The resource group in which the file resides. 00120 /// @return Returns a pointer to the Sound Instance that was created. 00121 virtual Audio::Sound* CreateDialogSound(ConstString& SoundName, ConstString& FileName, ConstString& Group); 00122 /// @brief Creates an effect sound instance from a file that can be used to play sounds. 00123 /// @param SoundName The name of the Sound instance. 00124 /// @param FileName The name of the file. 00125 /// @param Group The resource group in which the file resides. 00126 /// @return Returns a pointer to the Sound Instance that was created. 00127 virtual Audio::Sound* CreateEffectSound(ConstString& SoundName, ConstString& FileName, ConstString& Group); 00128 /// @brief Creates an music sound instance from a file that can be used to play sounds. 00129 /// @param SoundName The name of the Sound instance. 00130 /// @param FileName The name of the file. 00131 /// @param Group The resource group in which the file resides. 00132 /// @return Returns a pointer to the Sound Instance that was created. 00133 virtual Audio::Sound* CreateMusicSound(ConstString& SoundName, ConstString& FileName, ConstString& Group); 00134 /// @brief Gets a sound by it's name. 00135 /// @return Returns a pointer to the specified sound. 00136 virtual Audio::Sound* GetSoundByName(const String& SoundName) const; 00137 /// @brief Deletes a Sound. 00138 /// @param SoundName A pointer to the Sound you want deleted. 00139 virtual void DestroySound(Audio::Sound* ToBeDestroyed); 00140 /// @brief Deletes all stored sounds. 00141 virtual void DestroyAllSounds(); 00142 00143 /////////////////////////////////////////////////////////////////////////////// 00144 // SoundSet Management 00145 00146 /// @brief Creates a sound set. 00147 /// @details This function will create a sound set vector you can use to store similiar sound instances. 00148 /// @param SoundSetName The name you wish the sound set to have. 00149 /// @return Returns a pointer to the created Vector. 00150 virtual Audio::SoundSet* CreateSoundSet(const String& SoundSetName); 00151 /// @brief Gets an existing sound set. 00152 /// @details This function will find the specified sound set and return a pointer to it. 00153 /// @param SoundSetName The name of the sound set to retrieve. 00154 /// @return Returns a pointer to the named Vector. 00155 virtual Audio::SoundSet* GetSoundSet(const String& SoundSetName) const; 00156 /// @brief Add's a sound to the defined set. 00157 /// @details This function will add a sound instance to a created sound set. 00158 /// @param SoundName The sound instance to be added. 00159 virtual void AddSoundToSoundSet(const String& SoundSetName, Audio::Sound* SoundInst); 00160 00161 /////////////////////////////////////////////////////////////////////////////// 00162 // Volume Management 00163 00164 /// @brief Sets the volume for all stored Ambient sounds. 00165 /// @param Ambient The volume to apply to all Ambient sounds. 00166 virtual void SetAmbientVolume(const Real& Ambient); 00167 /// @brief Gets the currently set Ambient volume. 00168 /// @return Returns a Real representing the current Ambient volume. 00169 virtual Real GetAmbientVolume() const; 00170 /// @brief Sets the volume for all stored Dialog sounds. 00171 /// @param Dialog The volume to apply to all Dialog sounds. 00172 virtual void SetDialogVolume(const Real& Dialog); 00173 /// @brief Gets the currently set Dialog volume. 00174 /// @return Returns a Real representing the current Dialog volume. 00175 virtual Real GetDialogVolume() const; 00176 /// @brief Sets the volume for all stored Effect sounds. 00177 /// @param Effect The volume to apply to all Effect sounds. 00178 virtual void SetEffectVolume(const Real& Effect); 00179 /// @brief Gets the currently set Effect volume. 00180 /// @return Returns a Real representing the current Effect volume. 00181 virtual Real GetEffectVolume() const; 00182 /// @brief Sets the volume for all stored Music sounds. 00183 /// @param Music The volume to apply to all Music sounds. 00184 virtual void SetMusicVolume(const Real& Music); 00185 /// @brief Gets the currently set Music volume. 00186 /// @return Returns a Real representing the current Music volume. 00187 virtual Real GetMusicVolume() const; 00188 /// @brief Sets the volume for all stored sounds. 00189 /// @param Music The volume to apply to all sounds. 00190 virtual void SetMasterVolume(const Real& Master); 00191 /// @brief Gets the currently set Master volume. 00192 /// @return Returns a Real representing the current Master volume. 00193 virtual Real GetMasterVolume() const; 00194 /// @brief Sets whether or not to mute all Audio. 00195 /// @param Enable Whether or not all sounds should be muted. 00196 virtual void Mute(bool Enable); 00197 /// @brief Gets whether or not the Audio subsystem is muted. 00198 /// @return Returns a bool indicating whether or not the Audio subsystem is currently muted. 00199 virtual bool IsMuted() const; 00200 /// @brief Calls on all sounds stored in this manager to update their volume after a settings change. 00201 /// @note You shouldn't need to call this manually as it is automatically called every time a setting is changed. 00202 virtual void UpdateAllVolumes(); 00203 00204 /////////////////////////////////////////////////////////////////////////////// 00205 // Audio Device 00206 00207 /// @brief Gets the name of an available device. 00208 /// @details This function will retrieve the name of a device by it's index on the sound managers device list. 00209 /// @param Index The position on the device list you wish to access the name of. 00210 /// @return Returns the name of the device. 00211 virtual String GetAvailableDeviceNameByIndex(const Whole& Index) const; 00212 /// @brief Gets the name of the default device. 00213 /// @details This function will return the name of the system default device. 00214 /// @return Returns the name of the default device. 00215 virtual String GetDefaultDeviceName() const; 00216 /// @brief Gets the number of available devices. 00217 /// @details This function will return the total number of available devices, including the default. 00218 /// @return Returns the number of available devices. 00219 virtual Whole GetAvailableDeviceCount() const; 00220 00221 /////////////////////////////////////////////////////////////////////////////// 00222 // Logging 00223 00224 /// @brief This gets the logs that the audio subystem creates 00225 /// @details Internally the Mezzanine engine currently uses cAudio to process 3d sound. It has it's own 00226 /// logging system that we have customized to work with our logger. 00227 /// @return This gets the log of what actions the audio system has performed 00228 virtual std::stringstream* GetLogs() const; 00229 /// @brief This empties logs that the audio subystem creates 00230 /// @details Internally the Mezzanine engine currently uses cAudio to process 3d sound. It has it's own 00231 /// logging system that we have customized to work with our logger. This clears that data allow us to 00232 /// work with it as we need 00233 virtual void ClearLogs(); 00234 00235 /////////////////////////////////////////////////////////////////////////////// 00236 // Utility 00237 00238 /// @brief Initializes the Manager. 00239 /// @details This function will initialize the manager using the device and parameters provided. 00240 /// You need to call this function if you passed false into the sound manager constructor before 00241 /// you can use the manager. 00242 /// @param DeviceName The name of the device you wish to have this manager interface with/use. 00243 /// @param OutputFrequency Frequency of the output audio, -1 for the devices default. 00244 /// @param EAXEffectSlots The number of effects per sound allowed to be applied. 00245 virtual void InitializeManager(ConstString &DeviceName, int OutputFrequency=-1, int EAXEffectSlots=4); 00246 /// @brief Retrieve's the listener for this sound manager. 00247 /// @details This function will return the listener for this manager which can be used to help create 3D sound. 00248 /// @return Returns a pointer to the managers Sound Listener. 00249 virtual Audio::Listener* GetListener() const; 00250 /// @brief Gets the Music Player for this sound manager. 00251 /// @return Returns a pointer to the managers Music Player. 00252 virtual Audio::MusicPlayer* GetMusicPlayer() const; 00253 /// @brief Gets the internal cAudioManager this manager is based on. 00254 /// @return Returns a pointer to the internal cAudio manager. 00255 virtual cAudio::IAudioManager* GetcAudioManager() const; 00256 00257 /////////////////////////////////////////////////////////////////////////////// 00258 // Inherited from Managerbase 00259 00260 /// @copydoc Mezzanine::ManagerBase::Initialize() 00261 virtual void Initialize(); 00262 00263 /// @copydoc Mezzanine::ManagerBase::DoMainLoopItems() 00264 virtual void DoMainLoopItems(); 00265 00266 /// @copydoc Mezzanine::ManagerBase::GetType() 00267 virtual ManagerBase::ManagerTypeName GetType() const; 00268 };// audio manager 00269 }//Mezzanine 00270 00271 #endif
1.7.3