khanat-opennel-code/code/nel/src/sound/sound_bank.h
acemtp@users.sourceforge.net d5c601ffa5 initial version
2010-05-06 02:08:41 +02:00

122 lines
3.4 KiB
C++

// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NL_SOUND_BANK_H
#define NL_SOUND_BANK_H
#include "nel/misc/types_nl.h"
#include "nel/misc/string_mapper.h"
#include "audio_mixer_user.h"
#include <string>
namespace NLSOUND {
class CSound;
class CSimpleSound;
/**
* A set of sounds.
* \author Peter Hanappe
* \author Boris Boucher
* \author Nevrax France
* \date 2001
*/
class CSoundBank
{
public:
void registerBufferAssoc(CSimpleSound *sound, IBuffer *buffer);
void unregisterBufferAssoc(CSimpleSound *sound, IBuffer *buffer);
/** Called by CSampleBank when a sample(buffer) is unloaded.
* Remove link from CSound to unloaded IBuffer.
*/
void bufferUnloaded(const NLMISC::TStringId &bufferName);
/** Called by CSampleBank when a sample(buffer) is loaded.
* Regenerate link between CSound and IBuffer.
*/
void bufferLoaded(const NLMISC::TStringId &bufferName, IBuffer *buffer);
/// Constructor
CSoundBank() : _Loaded(false) { }
/// Destructor
virtual ~CSoundBank();
/// Load all the sounds.
void load(const std::string &packedSheetDir, bool packedSheetUpdate);
/// Remove all the sounds in this bank.
void unload();
/// Returns true if the sounds in this bank have been loaded.
bool isLoaded();
/// Return a sound corresponding to a name.
CSound *getSound(const NLMISC::TStringId &name);
/// Return the names of the sounds
void getNames( std::vector<NLMISC::TStringId> &names );
/// Return the number of sounds in this bank.
uint countSounds();
void addSound(CSound *sound);
void removeSound(const NLMISC::TStringId &name);
private:
/// CSoundBank singleton instance.
//static CSoundBank *_Instance;
typedef CHashSet<class CSimpleSound*, THashPtr<CSimpleSound*> > TSimpleSoundContainer;
// typedef std::hash_map<std::string, TSimpleSoundContainer > TBufferAssocContainer;
typedef CHashMap<NLMISC::TStringId, TSimpleSoundContainer, NLMISC::CStringIdHashMapTraits> TBufferAssocContainer;
/// Sound names hash map
// typedef std::hash_map<std::string, CSound*> TSoundTable;
typedef CHashMap<NLMISC::TStringId, CSound*, NLMISC::CStringIdHashMapTraits> TSoundTable;
/// Assoc from buffer to sound. Used for sound unloading.
TBufferAssocContainer _BufferAssoc;
// Buffer
TSoundTable _Sounds;
// Did we load the buffers.
bool _Loaded;
};
/**
* ESoundFileNotFound
*/
class ESoundBankNotFound : public NLMISC::Exception
{
public:
ESoundBankNotFound( const std::string filename ) :
NLMISC::Exception( (std::string("Sound bank not found: ")+filename).c_str() ) {}
};
} // NLSOUND
#endif // NL_SOUND_BANK_H
/* End of sound.h */