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-22 07:14:59 +03:00
|
|
|
class CAudioBase {
|
|
|
|
protected:
|
|
|
|
bool initialized;
|
|
|
|
int volume; // from 0 (mute) to 100
|
|
|
|
|
|
|
|
public:
|
|
|
|
CAudioBase(): initialized(false), volume(0) {};
|
|
|
|
virtual void init() = 0;
|
|
|
|
virtual void release() = 0;
|
|
|
|
|
|
|
|
virtual void setVolume(unsigned int percent);
|
|
|
|
unsigned int getVolume() { return volume; };
|
|
|
|
};
|
|
|
|
|
|
|
|
class CSoundHandler: public CAudioBase
|
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-04-22 21:48:56 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2009-05-22 07:14:59 +03:00
|
|
|
CSoundHandler();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
void release();
|
2009-05-01 02:25:17 +03:00
|
|
|
|
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-05-22 07:14:59 +03:00
|
|
|
void setVolume(unsigned int percent);
|
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-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
|
|
|
};
|
|
|
|
|
2009-05-22 07:14:59 +03:00
|
|
|
class CMusicHandler: public CAudioBase
|
2009-05-06 05:32:36 +03:00
|
|
|
{
|
|
|
|
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-06-10 22:44:09 +03:00
|
|
|
Mix_Music * LoadMUS(const char *file); //calls Mix_LoadMUS and checks for errors
|
|
|
|
int PlayMusic(Mix_Music *music, int loops); //calls Mix_PlayMusic and checks for errors
|
2009-05-06 05:32:36 +03:00
|
|
|
public:
|
2009-05-22 07:14:59 +03:00
|
|
|
CMusicHandler();
|
2009-05-06 05:32:36 +03:00
|
|
|
|
2009-05-22 07:14:59 +03:00
|
|
|
void init();
|
|
|
|
void release();
|
|
|
|
void setVolume(unsigned int percent);
|
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);
|
|
|
|
void musicFinishedCallback(void);
|
2009-04-22 21:48:56 +03:00
|
|
|
};
|
2009-04-16 14:14:13 +03:00
|
|
|
|
|
|
|
#endif // __CMUSICHANDLER_H__
|