#include "music.h"

/* Initializes music. */
bool
music_init(Music* self, const char* path)
{
	self->chunk = Mix_LoadMUS(path);

	if (!self->chunk)
		return false;

	self->isInit = true;
	
	return true;
}

/* Frees music. */
void
music_free(Music* self)
{
	if (self->isInit)
	{
		Mix_FreeMusic(self->chunk);
		self->isInit = false;
	}
}

/* Plays music, specifying if it loops. */
void
music_play(Music* self, bool isLoop)
{
	if (isLoop)
		Mix_PlayMusic(self->chunk, -1);
	else
		Mix_PlayMusic(self->chunk, 0);
}

/* Resumes music, if it was paused before. */
void
music_resume(void)
{
	Mix_ResumeMusic();
}

/* Pauses music. */
void
music_pause(void)
{
	Mix_PauseMusic();
}

/* Stops music. */
void
music_stop(void)
{
	Mix_HaltMusic();
}

/* Is music playing? */
bool
music_is_playing(void)
{
	return Mix_PlayingMusic();
}
