# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

async_file_manager_sound.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "stdsound.h"
00027 #include "async_file_manager_sound.h"
00028 #include "nel/misc/async_file_manager.h"
00029 #include "driver/sound_driver.h"
00030 
00031 using namespace NLMISC;
00032 
00033 namespace NLSOUND
00034 {
00035 
00036 CAsyncFileManagerSound  *CAsyncFileManagerSound::_Singleton;
00037 
00038 
00039 CAsyncFileManagerSound &CAsyncFileManagerSound::getInstance()
00040 {
00041         if (_Singleton == NULL)
00042         {
00043                 _Singleton = new CAsyncFileManagerSound();
00044         }
00045         return *_Singleton;
00046 }
00047 
00048 
00049 void    CAsyncFileManagerSound::terminate()
00050 {
00051         if (_Singleton != NULL)
00052         {
00053                 delete &getInstance();
00054                 _Singleton = NULL;
00055         }
00056 }
00057 
00058 void    CAsyncFileManagerSound::loadWavFile(IBuffer *pdestBuffer, const std::string &filename)
00059 {
00060         CAsyncFileManager::getInstance().addLoadTask(new CLoadWavFile(pdestBuffer, filename));
00061 }
00062 
00063 
00064 class CCancelLoadWavFile : public CAsyncFileManager::ICancelCallback
00065 {
00066         std::string     _Filename;
00067 
00068         bool callback(const NLMISC::IRunnable *prunnable) const
00069         {
00070                 const CAsyncFileManagerSound::CLoadWavFile *pLWF = dynamic_cast<const CAsyncFileManagerSound::CLoadWavFile*>(prunnable);
00071 
00072                 if (pLWF != NULL)
00073                 {
00074                         if (pLWF->_Filename == _Filename)
00075                                 return true;
00076                 }
00077                 return false;
00078         }
00079 
00080 public:
00081         CCancelLoadWavFile (const std::string &filename)
00082                 : _Filename (filename)
00083         {}
00084 };
00085 
00086 void    CAsyncFileManagerSound::cancelLoadWaveFile(const std::string &filename)
00087 {
00088 //      CAsyncFileManager::getInstance().cancelLoadTask(CCancelLoadWavFile(filename));
00089 }
00090 
00091 
00092 // Do not use these methods with the bigfile manager
00093 void CAsyncFileManagerSound::loadFile (const std::string &fileName, uint8 **pPtr)
00094 {
00095         CAsyncFileManager::getInstance().loadFile(fileName, pPtr);
00096 }
00097 
00098 void CAsyncFileManagerSound::loadFiles (const std::vector<std::string> &vFileNames, const std::vector<uint8**> &vPtrs)
00099 {
00100         CAsyncFileManager::getInstance().loadFiles(vFileNames, vPtrs);
00101 }
00102 
00103 void CAsyncFileManagerSound::signal (bool *pSgn)
00104 {
00105         CAsyncFileManager::getInstance().signal(pSgn);
00106 }
00107 
00108 void CAsyncFileManagerSound::cancelSignal (bool *pSgn)
00109 {
00110         CAsyncFileManager::getInstance().cancelSignal(pSgn);
00111 }
00112 
00113 
00114 // Load task.
00115 CAsyncFileManagerSound::CLoadWavFile::CLoadWavFile (IBuffer *pdestBuffer, const std::string &filename)
00116 :_Filename(filename), _pDestbuffer(pdestBuffer)
00117 {}
00118 
00119 void CAsyncFileManagerSound::CLoadWavFile::run (void)
00120 {
00121         nldebug("Loading sample %s...", _Filename.c_str());
00122 //      nlSleep(500);
00123         CAudioMixerUser::instance()->getSoundDriver()->loadWavFile(_pDestbuffer, _Filename.c_str());
00124 }
00125         
00126 
00127 
00128 } // NLSOUND