#ifndef SE_DSOUND_H
#define SE_DSOUND_H

#pragma warning(disable:4995)

#pragma comment (lib, "winmm.lib")
#pragma comment (lib, "dsound.lib")
#pragma comment (lib, "strmiids.lib")
#pragma comment (lib, "dinput8.lib")
#pragma comment (lib, "dxguid.lib")

#include <objbase.h>
#include <initguid.h>
#include <commdlg.h>
#include <mmreg.h>
#include <dshow.h>
#include <dsound.h>
#include <string>
#include <set>
#include "wav_read.h"

#include "se_iface.h"

using namespace std;

namespace se
{
	#define MAX_MUSIC 4
	#define MAX_SOUND 32

	class ZSoundEngineDSound;

	class ZSound : public XSound
	{
		friend class ZSoundEngineDSound;
		IDirectSoundBuffer * _buf;
	protected:
		ZSound(IDirectSoundBuffer * _buf);
		~ZSound();
	public:
		void kill();
		void set_volume(float volume);
	};

	class ZSoundEngineDSound : public XSoundEngine
	{
		IGraphBuilder*			g_pGraph;
		IMediaControl*			g_pControl;
		IMediaEvent*			g_pEvent;
		IMediaPosition*			g_pPosition;
		IBasicAudio *			g_pBA;

		IDirectSound *			g_pDS;
		IDirectSoundBuffer *	g_pDSBuffer[MAX_SOUND];
		
		set<ZSound *> cur_sounds;

		LPCWSTR	musics[MAX_MUSIC];
		//string	sounds[MAX_SOUND];
		int		cur_music;
		int		want_music;

		int		want_volume;
	public:
		ZSoundEngineDSound(HWND hWnd);
		~ZSoundEngineDSound();

		bool	load_music(int num, const char * path);
		bool	load_sound(int num, const char * path);

		void	run_music(int num=-1, float volume=1.f, bool sudo=false);
		XSound * play_sound(int num, float volume=1.f, bool loop=false);
		void	stop_all_sounds();
		void	check_time();
	};

}

#endif