#pragma once

#include "fmod.hpp"
#include "..\Utilities\util.h"
#include "..\Utilities\list.h"
#include "..\Utilities\xstring.h"

bool DXFUNCTIONS_API CheckFMODError(const FMOD_RESULT result);

class SoundRessource;

class DXFUNCTIONS_API SoundDevice
{
	FMOD::System *m_pSystem;
	LList<SoundRessource> m_Sounds;

public :
	SoundDevice(void);
	~SoundDevice(void);
	
	FMOD::System* GetSystem(void) const { return m_pSystem; }

	void Init(unsigned voices, unsigned flags);

	SoundRessource* CreateRessource(const XString& filename, const bool stream, const FMOD_MODE  mode);

	void ReleaseRessource(SoundRessource* const ressource);
};

class DXFUNCTIONS_API SoundRessource : public Ressource
{
	SoundDevice* m_pDevice;

	XString m_strFilename;
	bool m_bStream;
	FMOD_MODE m_Mode;

	FMOD::Sound* m_pSound;

protected:
	friend SoundDevice;
	friend LList<SoundRessource>;
	friend ListElement<SoundRessource>;

	SoundRessource(SoundDevice* const device, const XString& filename, const bool stream, const FMOD_MODE  mode);
	~SoundRessource(void);

public:

	SoundDevice* GetDeivce(void) const { return m_pDevice; }
	const XString& GetFilename(void) const { return m_strFilename; }
	bool IsStream(void) const { return m_bStream; }
	FMOD_MODE GetMode(void) const { return m_Mode; }
	FMOD::Sound* GetSound(void) const { return m_pSound; }

	unsigned GetLength(void) const;
	FMOD::Channel* Play(const bool paused) const;
};