module gedo.audio.music;



private import gedo.file.path;
private import gedo.text.parser;
private import gedo.audio.gal;



public class Music
{
public:
	this(string path, double loopPosition)
	{
		_music = GAL_createMusic(.gedo.file.path.toStringz(path), loopPosition);
	}


	this(string path)
	{
		auto text = cast(string).gedo.file.path.read(path);

		auto parser = new Parser(text);

		auto loopPosition = parser.getf();

		auto musicFileName = parser.gets();

		auto musicPath = .gedo.file.path.join(.gedo.file.path.dirname(path), musicFileName);

		this(musicPath, loopPosition);
	}


	~this()
	{
		GAL_releaseMusic(_music);
	}


	bool isPlayable()
	{
		return (_music !is null);
	}


	void play()
	{
		if(_music)
		{
			GAL_playMusic(_music);
		}
	}


	static void stop()
	{
		GAL_stopMusic();
	}


	static void mute()
	{
		GAL_muteMusic(1);
	}


	static void unmute()
	{
		GAL_muteMusic(0);
	}


private:
	GAL_Music* _music;

	static float _bgm;
	static float _se;
}
