PixelLightAPI  .
SNSound.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SNSound.h                                      *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLSOUND_SCENENODES_SNSOUND_H__
00024 #define __PLSOUND_SCENENODES_SNSOUND_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLScene/Scene/SceneNode.h>
00032 #include "PLSound/PLSound.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLSound {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Forward declarations                                  ]
00043 //[-------------------------------------------------------]
00044 class Source;
00045 class SCSound;
00046 class ResourceHandler;
00047 
00048 
00049 //[-------------------------------------------------------]
00050 //[ Classes                                               ]
00051 //[-------------------------------------------------------]
00052 /**
00053 *  @brief
00054 *    Scene node which is able to playback a sound
00055 *
00056 *  @note
00057 *    - For sources with 3D spatialization, do only use one channel buffers because not each sound backend may be capable to use 3D spatialization for buffers with multiple channels
00058 */
00059 class SNSound : public PLScene::SceneNode {
00060 
00061 
00062     //[-------------------------------------------------------]
00063     //[ Public definitions                                    ]
00064     //[-------------------------------------------------------]
00065     public:
00066         /**
00067         *  @brief
00068         *    Scene node flags (SceneNode flags extension)
00069         */
00070         enum EFlags {
00071             Stream          = 1<<10,    /**< Stream the file (recommended for large files!) */
00072             No3D            = 1<<11,    /**< No 3D sound */
00073             NoLoop          = 1<<12,    /**< Do not loop the sound playback */
00074             NoStartPlayback = 1<<13     /**< Do not start sound playback after scene node initialization */
00075         };
00076         pl_enum(EFlags)
00077             pl_enum_base(PLScene::SceneNode::EFlags)
00078             pl_enum_value(Stream,           "Stream the file (recommended for large files!)")
00079             pl_enum_value(No3D,             "No 3D sound")
00080             pl_enum_value(NoLoop,           "Do not loop the sound playback")
00081             pl_enum_value(NoStartPlayback,  "Do not start sound playback after scene node initialization")
00082         pl_enum_end
00083 
00084 
00085     //[-------------------------------------------------------]
00086     //[ RTTI interface                                        ]
00087     //[-------------------------------------------------------]
00088     pl_class(PLSOUND_RTTI_EXPORT, SNSound, "PLSound", PLScene::SceneNode, "Scene node which is able to playback a sound")
00089         // Properties
00090         pl_properties
00091             pl_property("Icon", "Data/Textures/IconSound.dds")
00092         pl_properties_end
00093         // Attributes
00094         pl_attribute(Sound,             PLCore::String,         "",         ReadWrite,  GetSet, "Filename of the sound which should be played (full path, supported file formats are API dependent). For 3D spatialization, do only use one channel buffers for best compatibility.",   "Ext='mp3 ogg wav mid midi it mod s3m xm'")
00095         pl_attribute(Volume,            float,                  1.0f,       ReadWrite,  GetSet, "Volume (value from 0.0-1.0 -> 0.0 = silence, 1.0 = full volume)",                                                                                                                      "Min='0.0' Max='1.0'")
00096         pl_attribute(Pitch,             float,                  1.0f,       ReadWrite,  GetSet, "Pitch multiplier (pitch<1.0=slower/pitch=1.0=normal/pitch>1.0=faster)",                                                                                                                "Min='0.0'")
00097         pl_attribute(ReferenceDistance, float,                  1.0f,       ReadWrite,  GetSet, "Used to increase or decrease the range of a source by decreasing or increasing the attenuation, respectively",                                                                         "Min='0.0'")
00098         pl_attribute(MaxDistance,       float,                  10000.0f,   ReadWrite,  GetSet, "Defines a distance beyond which the source will not be further attenuated by distance",                                                                                                "Min='0.0'")
00099         pl_attribute(RolloffFactor,     float,                  1.0f,       ReadWrite,  GetSet, "This will scale the distance attenuation over the applicable range",                                                                                                                   "Min='0.0'")
00100             // Overwritten PLScene::SceneNode attributes
00101         pl_attribute(Flags,             pl_flag_type(EFlags),   0,          ReadWrite,  GetSet, "Flags",                                                                                                                                                                                "")
00102         // Constructors
00103         pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00104         // Slots
00105         pl_slot_0(OnPosition,   "Called when the scene node position changed",  "")
00106     pl_class_end
00107 
00108 
00109     //[-------------------------------------------------------]
00110     //[ Public RTTI get/set functions                         ]
00111     //[-------------------------------------------------------]
00112     public:
00113         PLSOUND_API PLCore::String GetSound() const;
00114         PLSOUND_API void SetSound(const PLCore::String &sValue);
00115         PLSOUND_API float GetVolume() const;
00116         PLSOUND_API void SetVolume(float fValue);
00117         PLSOUND_API float GetPitch() const;
00118         PLSOUND_API void SetPitch(float fValue);
00119         PLSOUND_API float GetReferenceDistance() const;
00120         PLSOUND_API void SetReferenceDistance(float fValue);
00121         PLSOUND_API float GetMaxDistance() const;
00122         PLSOUND_API void SetMaxDistance(float fValue);
00123         PLSOUND_API float GetRolloffFactor() const;
00124         PLSOUND_API void SetRolloffFactor(float fValue);
00125         PLSOUND_API virtual void SetFlags(PLCore::uint32 nValue) override;  // From PLScene::SceneNode
00126 
00127 
00128     //[-------------------------------------------------------]
00129     //[ Public functions                                      ]
00130     //[-------------------------------------------------------]
00131     public:
00132         /**
00133         *  @brief
00134         *    Default constructor
00135         */
00136         PLSOUND_API SNSound();
00137 
00138         /**
00139         *  @brief
00140         *    Destructor
00141         */
00142         PLSOUND_API virtual ~SNSound();
00143 
00144         /**
00145         *  @brief
00146         *    Returns the sound source
00147         *
00148         *  @return
00149         *    The sound source, can be a null pointer
00150         */
00151         PLSOUND_API Source *GetSoundSource() const;
00152 
00153 
00154     //[-------------------------------------------------------]
00155     //[ Protected data                                        ]
00156     //[-------------------------------------------------------]
00157     protected:
00158         PLCore::String m_sSound;                /**< Filename of the sound which should be played (full path, supported file formats are API dependent) */
00159         float          m_fVolume;               /**< Volume (value from 0.0-1.0 -> 0.0 = silence, 1.0 = full volume) */
00160         float          m_fPitch;                /**< Pitch multiplier (pitch<1.0=slower/pitch=1.0=normal/pitch>1.0=faster) */
00161         float          m_fReferenceDistance;    /**< Used to increase or decrease the range of a source by decreasing or increasing the attenuation, respectively */
00162         float          m_fMaxDistance;          /**< Defines a distance beyond which the source will not be further attenuated by distance */
00163         float          m_fRolloffFactor;        /**< This will scale the distance attenuation over the applicable range */
00164 
00165 
00166     //[-------------------------------------------------------]
00167     //[ Private functions                                     ]
00168     //[-------------------------------------------------------]
00169     private:
00170         /**
00171         *  @brief
00172         *    Returns the sound container this sound is in
00173         *
00174         *  @return
00175         *    The sound container this sound is in, a null pointer on error
00176         */
00177         SCSound *GetSoundContainer() const;
00178 
00179         /**
00180         *  @brief
00181         *    Loads/reloads the sound
00182         */
00183         void Load();
00184 
00185         /**
00186         *  @brief
00187         *    Called when the scene node position changed
00188         */
00189         void OnPosition();
00190 
00191 
00192     //[-------------------------------------------------------]
00193     //[ Private data                                          ]
00194     //[-------------------------------------------------------]
00195     private:
00196         ResourceHandler *m_pSoundSourceHandler; /**< Sound source handler (always valid!) */
00197 
00198 
00199     //[-------------------------------------------------------]
00200     //[ Protected virtual PLScene::SceneNode functions        ]
00201     //[-------------------------------------------------------]
00202     protected:
00203         PLSOUND_API virtual void InitFunction() override;
00204 
00205 };
00206 
00207 
00208 //[-------------------------------------------------------]
00209 //[ Namespace                                             ]
00210 //[-------------------------------------------------------]
00211 } // PLSound
00212 
00213 
00214 #endif // __PLSOUND_SCENENODES_SNSOUND_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:03
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported