AaronCameron.net
No ads. No Profit. No Master, But Truth.
Not a Member? - Login or Create an Account
Wednesday the 23rd of May 2012 @ 10:17am
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cGuiSound.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2002  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #include "gui/cGuiSound.h"
00026 
00027 #include "n2l/audio.h"
00028 #include "n2l/dynVars.h"
00029 #include "n2l/resourceManagement.h"
00030 
00031 
00032 namespace n2l
00033 {
00034     /**************************************************************************/
00035     cGuiSound::cGuiSound()
00036     {
00037         init();
00038     }
00039 
00040     /**************************************************************************/
00041     cGuiSound::cGuiSound( const cVfsNodeInterface & iNode )
00042     {
00043         init();
00044         load( iNode );
00045     }
00046 
00047     /**************************************************************************/
00048     cGuiSound::cGuiSound( const cDynVar &iDef )
00049     {
00050         init();
00051         load( iDef );
00052     }
00053 
00054     /**************************************************************************/
00055     cGuiSound::~cGuiSound()
00056     {
00057     }
00058 
00059     /**************************************************************************/
00060     void cGuiSound::load( const cVfsNodeInterface &iNode )
00061     {
00062         const tUint DataOffset =
00063             vfsNodeFileWithHeader( iNode, "n2l::cGuiSound");
00064 
00065         cDynVar def;
00066         def.unserialize( iNode.buffer().c_str()+DataOffset );
00067         load( def );
00068     }
00069 
00070     /**************************************************************************/
00071     void cGuiSound::load( const cDynVar &iDef )
00072     {
00073         
00074         if (iDef.keyExists("sound")) 
00075             sound( cResourceManager::get<cAudioChunk>(iDef["sound"]) );
00076 
00077         volume( iDef.keyValueOr("volume", volume()) );
00078 
00079         lrBias( iDef.keyValueOr("lrBias", lrBias()) );
00080     }
00081 
00082     /**************************************************************************/
00083     void cGuiSound::lrBias( const tFloat &iVal )
00084     {
00085         mLRBias = n2lMin( 1.0f, n2lMax( iVal, -1.0f ) );
00086     }
00087 
00088     /**************************************************************************/
00089     const tFloat &cGuiSound::lrBias() const
00090     {
00091         return mLRBias;
00092     }
00093 
00094     /**************************************************************************/
00095     void cGuiSound::volume( const tFloat &iVal )
00096     {
00097         mVolume = n2lMin( 1.0f, n2lMax( iVal, 0.0f ) );
00098     }
00099 
00100     /**************************************************************************/
00101     const tFloat &cGuiSound::volume() const
00102     {
00103         return mVolume;
00104     }
00105 
00106     /**************************************************************************/
00107     void cGuiSound::sound( const cAutoPtr<const cAudioChunk> &iSound )
00108     {
00109         mSound = iSound;
00110     }
00111 
00112     /**************************************************************************/
00113     const cAutoPtr<const cAudioChunk> &cGuiSound::sound() const
00114     {
00115         return mSound;
00116     }
00117 
00118     /**************************************************************************/
00119     void cGuiSound::prop( const tString &iName, const cDynVar &iVal )
00120     {
00121         if (iName == "sound") {
00122             if (!iVal) sound(0);
00123             else sound( cResourceManager::get<cAudioChunk>(iVal) );
00124 
00125         } else if (iName == "volume")
00126             volume( iVal );
00127 
00128         else if (iName == "lrBias")
00129             lrBias( iVal );
00130 
00131     }
00132 
00133     /**************************************************************************/
00134     const cDynVar cGuiSound::prop( const tString &iName ) const
00135     {
00136         cDynVar oVal = cDynVar::Null;
00137         return oVal;
00138     }
00139 
00140     /**************************************************************************/
00141     void cGuiSound::play() const
00142     {
00143         if (!mSound.isSet()) return;
00144         mSound->play( mLRBias, mVolume );
00145     }
00146 
00147     /**************************************************************************/
00148     void cGuiSound::init()
00149     {
00150         mLRBias = .0f;
00151         mVolume = 1.0f;
00152     }
00153 
00154 } // namespace n2l
00155 
©2012 Aaron Cameron