2009-04-16 14:14:13 +03:00
|
|
|
#ifndef __CMUSICHANDLER_H__
|
|
|
|
#define __CMUSICHANDLER_H__
|
|
|
|
|
2009-05-01 02:25:17 +03:00
|
|
|
#include <boost/thread/mutex.hpp>
|
|
|
|
|
2009-04-22 21:48:56 +03:00
|
|
|
#include "CSoundBase.h"
|
2009-05-01 02:25:17 +03:00
|
|
|
#include "CMusicBase.h"
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CMusicHandler.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
|
|
|
|
2009-04-22 21:48:56 +03:00
|
|
|
class CSndHandler;
|
2009-05-14 07:49:04 +03:00
|
|
|
class CSpell;
|
2009-05-01 02:25:17 +03:00
|
|
|
struct _Mix_Music;
|
|
|
|
typedef struct _Mix_Music Mix_Music;
|
|
|
|
struct Mix_Chunk;
|
2009-04-22 21:48:56 +03:00
|
|
|
|
2009-05-06 05:32:36 +03:00
|
|
|
class CSoundHandler
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2009-04-22 21:48:56 +03:00
|
|
|
private:
|
2009-04-16 14:14:13 +03:00
|
|
|
CSndHandler *sndh;
|
2009-04-30 13:53:06 +03:00
|
|
|
soundBase::soundID getSoundID(std::string &fileName);
|
2009-04-22 21:48:56 +03:00
|
|
|
|
2009-04-30 13:53:06 +03:00
|
|
|
std::map<soundBase::soundID, Mix_Chunk *> soundChunks;
|
2009-04-22 21:48:56 +03:00
|
|
|
|
2009-04-30 13:53:06 +03:00
|
|
|
Mix_Chunk *GetSoundChunk(soundBase::soundID soundID);
|
2009-05-06 06:13:46 +03:00
|
|
|
int volume; // from 0 (mute) to 100
|
2009-04-22 21:48:56 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2009-05-06 06:13:46 +03:00
|
|
|
CSoundHandler(): sndh(NULL), volume(0) {};
|
2009-05-01 02:25:17 +03:00
|
|
|
|
2009-05-06 05:32:36 +03:00
|
|
|
void initSounds();
|
|
|
|
void freeSounds();
|
2009-04-26 02:31:39 +03:00
|
|
|
void initCreaturesSounds(std::vector<CCreature> &creatures);
|
2009-05-14 07:49:04 +03:00
|
|
|
void initSpellsSounds(std::vector<CSpell> &spells);
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-04-22 21:48:56 +03:00
|
|
|
// Sounds
|
2009-04-30 13:53:06 +03:00
|
|
|
int playSound(soundBase::soundID soundID, int repeats=0);
|
|
|
|
int playSoundFromSet(std::vector<soundBase::soundID> &sound_vec);
|
2009-04-24 00:09:10 +03:00
|
|
|
void stopSound(int handler);
|
2009-05-06 06:13:46 +03:00
|
|
|
void setSoundVolume(unsigned int percent);
|
|
|
|
unsigned int getSoundVolume();
|
2009-04-22 21:50:22 +03:00
|
|
|
|
|
|
|
// Sets
|
2009-05-06 05:39:03 +03:00
|
|
|
std::vector<soundBase::soundID> pickupSounds;
|
2009-04-30 13:53:06 +03:00
|
|
|
std::vector<soundBase::soundID> horseSounds;
|
2009-05-06 05:32:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CMusicHandler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// Because we use the SDL music callback, our music variables must
|
|
|
|
// be protected
|
|
|
|
boost::mutex musicMutex;
|
|
|
|
Mix_Music *currentMusic;
|
|
|
|
Mix_Music *nextMusic;
|
|
|
|
int nextMusicLoop;
|
2009-05-06 06:13:46 +03:00
|
|
|
int volume; // from 0 (mute) to 100
|
2009-05-06 05:32:36 +03:00
|
|
|
|
|
|
|
public:
|
2009-05-06 06:13:46 +03:00
|
|
|
CMusicHandler(): currentMusic(NULL), nextMusic(NULL), volume(0) {};
|
2009-05-06 05:32:36 +03:00
|
|
|
|
|
|
|
void initMusics();
|
|
|
|
void freeMusics();
|
2009-05-01 02:25:17 +03:00
|
|
|
|
|
|
|
// Musics
|
|
|
|
std::map<musicBase::musicID, std::string> musics;
|
|
|
|
std::vector<musicBase::musicID> battleMusics;
|
|
|
|
|
|
|
|
void playMusic(musicBase::musicID musicID, int loop=1);
|
|
|
|
void playMusicFromSet(std::vector<musicBase::musicID> &music_vec, int loop=1);
|
|
|
|
void stopMusic(int fade_ms=1000);
|
2009-05-06 06:13:46 +03:00
|
|
|
void setMusicVolume(unsigned int percent);
|
|
|
|
unsigned int getMusicVolume();
|
2009-05-01 02:25:17 +03:00
|
|
|
void musicFinishedCallback(void);
|
2009-04-22 21:48:56 +03:00
|
|
|
};
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-05-06 05:32:36 +03:00
|
|
|
class CAudioHandler: public CSoundHandler, public CMusicHandler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
bool audioInitialized;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CAudioHandler(): audioInitialized(false) {};
|
|
|
|
~CAudioHandler();
|
|
|
|
|
2009-05-06 06:13:46 +03:00
|
|
|
void initAudio(unsigned int volume = 90);
|
2009-05-06 05:32:36 +03:00
|
|
|
};
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
#endif // __CMUSICHANDLER_H__
|