
#ifndef ABLAUDIO_HPP
#define ABLAUDIO_HPP

#pragma warning(push)
#include <stlport\set>
#include <stlport\map>
#pragma warning(pop)
#include <Stuff\Chain.hpp>
#include <Stuff\Scalar.hpp>
#include <Adept\Entity.hpp>



namespace Adept
{
	class AudioCommand;
};

namespace ABL
{
	class AudioManager
	{
	  public:
		AudioManager();
		~AudioManager();

		bool GetVOPlayed(int hash)
		{
			return (m_PlayedVoiceOvers.find(hash) != m_PlayedVoiceOvers.end());
		}

		void SetVOPlayed(int hash);

		typedef int vo_id;

		static AudioManager* GetInstance()
		{
			return (m_Instance);
		}

		static void IncrementRefCount();
		static void DecrementRefCount();

		void Load(MemoryStream *stream);
		void Save(MemoryStream *stream);

		void AddCommand(AudioCommand* command,int talker_id);
		void DeleteAllCommands();

		void AddMusicCommand(AudioCommand* command, Scalar old_timeout, Scalar new_timein, Scalar new_volume);

		void Update();

		bool IsVoiceOverPlaying();
		bool IsMusicPlaying();

		void MapTalker(int talker, Adept::ObjectID object_id);
		Adept::ObjectID TalkerObjectID(int talker);

	  private:
		static AudioManager* m_Instance;
		static int m_RefCount;

		Stuff::Scalar GetFadeVolume() const;

		std::set<vo_id> m_PlayedVoiceOvers;

		typedef std::pair<const int, Adept::ObjectID> talker_pair;
		typedef std::map<const int, Adept::ObjectID> talker_mapping;

		std::map<AudioCommand *,int> m_WhoIsTalking;

		talker_mapping m_TalkerMappings;

		Stuff::ChainOf<AudioCommand*> m_AudioCommands;
		Stuff::ChainOf<AudioCommand*> m_MusicCommands;

		Stuff::Scalar m_OldVolume;
		Stuff::Scalar m_OldTimeout;
		Stuff::Scalar m_NewVolume;
		Stuff::Scalar m_TransitionBegin;
		Stuff::Scalar m_TransitionEnd;
	};
};


#endif // ABLAUDIO_HPP