PixelLightAPI  .
SNMSound.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SNMSound.h                                     *
00003  *
00004  *  Copyright (C) 2002-2012 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_SCENENODEMODIFIERS_SNMSOUND_H__
00024 #define __PLSOUND_SCENENODEMODIFIERS_SNMSOUND_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLScene/Scene/SceneNodeModifier.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 modifier 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 SNMSound : public PLScene::SceneNodeModifier {
00060 
00061 
00062     //[-------------------------------------------------------]
00063     //[ Public definitions                                    ]
00064     //[-------------------------------------------------------]
00065     public:
00066         /**
00067         *  @brief
00068         *    Scene node modifier flags (SceneNodeModifier flags extension)
00069         */
00070         enum EFlags {
00071             Stream          = 1<<2, /**< Stream the file (recommended for large files!) */
00072             No3D            = 1<<3, /**< No 3D sound */
00073             NoLoop          = 1<<4, /**< Do not loop the sound playback */
00074             NoStartPlayback = 1<<5  /**< Do not start sound playback after scene node initialization */
00075         };
00076         pl_enum(EFlags)
00077             pl_enum_base(PLScene::SceneNodeModifier::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, SNMSound, "PLSound", PLScene::SceneNodeModifier, "Scene node modifier which is able to playback a sound")
00089         // Attributes
00090         pl_attribute(Sound,             PLCore::String,         "",         ReadWrite,  GetSet, "Name 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'")
00091         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'")
00092         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'")
00093         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'")
00094         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'")
00095         pl_attribute(RolloffFactor,     float,                  1.0f,       ReadWrite,  GetSet, "This will scale the distance attenuation over the applicable range",                                                                                                               "Min='0.0'")
00096             // Overwritten PLScene::SceneNodeModifier attributes
00097         pl_attribute(Flags,             pl_flag_type(EFlags),   0,          ReadWrite,  GetSet, "Flags",                                                                                                                                                                            "")
00098         // Constructors
00099         pl_constructor_1(ParameterConstructor,  PLScene::SceneNode&,    "Parameter constructor",    "")
00100         // Slots
00101         pl_slot_0(OnPosition,   "Called when the scene node position changed",  "")
00102     pl_class_end
00103 
00104 
00105     //[-------------------------------------------------------]
00106     //[ Public RTTI get/set functions                         ]
00107     //[-------------------------------------------------------]
00108     public:
00109         PLSOUND_API PLCore::String GetSound() const;
00110         PLSOUND_API void SetSound(const PLCore::String &sValue);
00111         PLSOUND_API float GetVolume() const;
00112         PLSOUND_API void SetVolume(float fValue);
00113         PLSOUND_API float GetPitch() const;
00114         PLSOUND_API void SetPitch(float fValue);
00115         PLSOUND_API float GetReferenceDistance() const;
00116         PLSOUND_API void SetReferenceDistance(float fValue);
00117         PLSOUND_API float GetMaxDistance() const;
00118         PLSOUND_API void SetMaxDistance(float fValue);
00119         PLSOUND_API float GetRolloffFactor() const;
00120         PLSOUND_API void SetRolloffFactor(float fValue);
00121         PLSOUND_API virtual void SetFlags(PLCore::uint32 nValue) override;  // From PLScene::SceneNodeModifier
00122 
00123 
00124     //[-------------------------------------------------------]
00125     //[ Public functions                                      ]
00126     //[-------------------------------------------------------]
00127     public:
00128         /**
00129         *  @brief
00130         *    Constructor
00131         *
00132         *  @param[in] cSceneNode
00133         *    Owner scene node
00134         */
00135         PLSOUND_API SNMSound(PLScene::SceneNode &cSceneNode);
00136 
00137         /**
00138         *  @brief
00139         *    Destructor
00140         */
00141         PLSOUND_API virtual ~SNMSound();
00142 
00143         /**
00144         *  @brief
00145         *    Returns the sound source
00146         *
00147         *  @return
00148         *    The sound source, can be a null pointer
00149         */
00150         PLSOUND_API Source *GetSoundSource() const;
00151 
00152 
00153     //[-------------------------------------------------------]
00154     //[ Protected virtual PLScene::SceneNodeModifier functions ]
00155     //[-------------------------------------------------------]
00156     protected:
00157         PLSOUND_API virtual void OnActivate(bool bActivate) override;
00158 
00159 
00160     //[-------------------------------------------------------]
00161     //[ Protected data                                        ]
00162     //[-------------------------------------------------------]
00163     protected:
00164         PLCore::String m_sSound;                /**< Name of the sound which should be played (full path, supported file formats are API dependent) */
00165         float          m_fVolume;               /**< Volume (value from 0.0-1.0 -> 0.0 = silence, 1.0 = full volume) */
00166         float          m_fPitch;                /**< Pitch multiplier (pitch<1.0=slower/pitch=1.0=normal/pitch>1.0=faster) */
00167         float          m_fReferenceDistance;    /**< Used to increase or decrease the range of a source by decreasing or increasing the attenuation, respectively */
00168         float          m_fMaxDistance;          /**< Defines a distance beyond which the source will not be further attenuated by distance */
00169         float          m_fRolloffFactor;        /**< This will scale the distance attenuation over the applicable range */
00170 
00171 
00172     //[-------------------------------------------------------]
00173     //[ Private functions                                     ]
00174     //[-------------------------------------------------------]
00175     private:
00176         /**
00177         *  @brief
00178         *    Returns the sound container this sound is in
00179         *
00180         *  @return
00181         *    The sound container this sound is in, a null pointer on error
00182         */
00183         SCSound *GetSoundContainer() const;
00184 
00185         /**
00186         *  @brief
00187         *    Called when the scene node position changed
00188         */
00189         void OnPosition();
00190 
00191         /**
00192         *  @brief
00193         *    Loads/reloads the sound
00194         */
00195         void Load();
00196 
00197 
00198     //[-------------------------------------------------------]
00199     //[ Private data                                          ]
00200     //[-------------------------------------------------------]
00201     private:
00202         ResourceHandler *m_pSoundSourceHandler; /**< Sound source handler (always valid!) */
00203 
00204 
00205 };
00206 
00207 
00208 //[-------------------------------------------------------]
00209 //[ Namespace                                             ]
00210 //[-------------------------------------------------------]
00211 } // PLSound
00212 
00213 
00214 #endif // __PLSOUND_SCENENODEMODIFIERS_SNMSOUND_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:00
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported