Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sonix.cpp

Go to the documentation of this file.
00001 /****************** <SNX heading BEGIN do not edit this line> *****************
00002  *
00003  * sonix
00004  *
00005  * Original Authors:
00006  *   Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: sonix.cpp,v $
00010  * Date modified: $Date: 2003/11/29 03:32:22 $
00011  * Version:       $Revision: 1.9 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <SNX heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #include <snx/snxConfig.h>
00043 
00044 #include <stdlib.h>
00045 #include <gmtl/Math.h>
00046 #include <gmtl/Vec.h>
00047 #include <gmtl/MatrixOps.h>
00048 #include <gmtl/VecOps.h>
00049 #include <gmtl/Xforms.h>
00050 
00051 #include <vpr/Util/Assert.h>
00052 #include <vpr/Util/Debug.h>
00053 #include <snx/Util/Debug.h>
00054 #include <snx/SoundFactory.h>
00055 #include <snx/sonix.h>
00056 
00057 
00058 vprSingletonImp(sonix);
00059 
00060 //:  destructor
00061 sonix::~sonix()
00062 {
00063    // release the implementation
00064    if (mImplementation != NULL)
00065    {
00066       // unload all sound data
00067       mImplementation->unbindAll();
00068       
00069       // shutdown old api if exists
00070       mImplementation->shutdownAPI();
00071       delete mImplementation;
00072       mImplementation = NULL;
00073    }
00074 }
00075 
00083 void sonix::trigger( const std::string& alias, const int& repeat )
00084 {
00085    this->impl().trigger( alias, repeat );
00086 }
00087 
00091 bool sonix::isPlaying( const std::string& alias )
00092 {
00093    return this->impl().isPlaying( alias );
00094 }  
00095 
00096 /*
00097  * when sound is already playing then you call trigger,
00098  * does the sound restart from beginning?
00099  */
00100 void sonix::setRetriggerable( const std::string& alias, bool onOff )
00101 {
00102    this->impl().setRetriggerable( alias, onOff );
00103 }
00104 
00108 bool sonix::isRetriggerable( const std::string& alias )
00109 {
00110    return this->impl().isRetriggerable( alias );
00111 }
00112 
00117 void sonix::stop( const std::string& alias )
00118 {
00119    this->impl().stop( alias );
00120 }
00121 
00125 void sonix::pause( const std::string& alias )
00126 {
00127    this->impl().pause( alias );
00128 }
00129 
00133  void sonix::unpause( const std::string& alias )
00134 {
00135    this->impl().unpause( alias );
00136 }
00137 
00139  bool sonix::isPaused( const std::string& alias )
00140 {
00141    return this->impl().isPaused( alias );
00142 } 
00143 
00150  void sonix::setAmbient( const std::string& alias, bool setting )
00151 {
00152    this->impl().setAmbient( alias, setting );
00153 }
00154 
00156  bool sonix::isAmbient( const std::string& alias )
00157 {
00158    return this->impl().isAmbient( alias );
00159 }
00160 
00166  void sonix::setPitchBend( const std::string& alias, float amount )
00167 {
00168    this->impl().setPitchBend( alias, amount );
00169 }
00170 
00172  void sonix::setVolume( const std::string& alias, float amount )
00173 {
00174    this->impl().setVolume( alias, amount );
00175 }
00176 
00180  void sonix::setCutoff( const std::string& alias, float amount )
00181 {
00182    this->impl().setCutoff( alias, amount );
00183 }
00184 
00189  void sonix::setPosition( const std::string& alias, const float& x, const float& y, const float& z )
00190 {
00191    this->impl().setPosition( alias, x, y, z );
00192 }
00193 
00199  void sonix::getPosition( const std::string& alias, float& x, float& y, float& z )
00200 {
00201    this->impl().getPosition( alias, x, y, z );
00202 }
00203 
00207  void sonix::setListenerPosition( const gmtl::Matrix44f& mat )
00208 {
00209    this->impl().setListenerPosition( mat );
00210 }
00211 
00215  void sonix::getListenerPosition( gmtl::Matrix44f& mat )
00216 {
00217    this->impl().getListenerPosition( mat );
00218 }
00219 
00220 
00230  void sonix::changeAPI( const std::string& apiName )
00231 {
00232    snx::ISoundImplementation& oldImpl = this->impl();
00233    vprASSERT( &oldImpl != NULL && "this->impl() should ensure that oldImpl is non-NULL" );
00234    
00235    // change the current api to the newly requested one.
00236    snx::SoundFactory::instance()->createImplementation( apiName, mImplementation );
00237 
00238    vprDEBUG(snxDBG, vprDBG_CRITICAL_LVL) << "Changing sound API from '"
00239                                          << oldImpl.name() << "' to '"
00240                                          << mImplementation->name() << "'\n"
00241                                          << vprDEBUG_FLUSH;
00242    
00243    // copy sound state from old to current (doesn't do binding yet)
00244    snx::SoundImplementation* si = dynamic_cast<snx::SoundImplementation*>( mImplementation );
00245    vprASSERT( NULL != si && "implementation is not of type SoundImplementation, cast fails" );
00246    snx::SoundImplementation& old_si = dynamic_cast<snx::SoundImplementation&>( oldImpl );
00247    vprASSERT( NULL != &old_si && "implementation is not of type SoundImplementation, cast fails" );
00248    si->copy( old_si );
00249 
00250       // unload all sound data
00251       oldImpl.unbindAll();
00252 
00253       // shutdown old api if exists
00254       oldImpl.shutdownAPI();
00255 
00256       // delete old api, we're done with it...
00257       delete &oldImpl;
00258 
00259    // startup the new API
00260    if(!mImplementation->startAPI()) // if it fails to start then we revert back to stub
00261    {
00262       vprDEBUG(snxDBG, vprDBG_CRITICAL_LVL)
00263          << clrOutBOLD(clrRED, "ERROR:") << " Failed to start new API--"
00264          << "changing back to Stub\n" << vprDEBUG_FLUSH;
00265       changeAPI("stub");
00266    }
00267 
00268    // load all sound data
00269    mImplementation->bindAll();
00270 }
00271 
00272 /*
00273  * configure the sound API global settings
00274  */
00275  void sonix::configure( const snx::SoundAPIInfo& sai )
00276 {
00277    this->impl().configure( sai );
00278 }   
00279 
00288  void sonix::configure( const std::string& alias, const snx::SoundInfo& description )
00289 {
00290    this->impl().configure( alias, description );
00291 }   
00292 
00297  void sonix::remove( const std::string alias )
00298 {
00299    this->impl().remove( alias );
00300 }   
00301 
00306  void sonix::step( const float& timeElapsed )
00307 {
00308    this->impl().step( timeElapsed );
00309 }
00310 
00311 snx::ISoundImplementation& sonix::impl()
00312 {
00313    if (mImplementation == NULL)
00314    {
00315       snx::SoundFactory::instance()->createImplementation( "stub", mImplementation );
00316       mImplementation->startAPI();
00317       mImplementation->bindAll();
00318    }
00319    return *mImplementation;
00320 }

Generated on Sun May 2 14:39:26 2004 for Juggler Sonix by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002