#include "KGF.h"

GSound *ActualMusic;

ALLEGRO_SAMPLE_INSTANCE *ActualMusicInstance=NULL;

void ChangeMusic(std::string name) {
  ActualMusic = GetSound(name);
  if (ActualMusicInstance) al_destroy_sample_instance(ActualMusicInstance);
  ActualMusicInstance = al_create_sample_instance(ActualMusic->GetSample());

  al_attach_sample_to_mixer(ActualMusicInstance, Mixer);

  al_set_sample_instance_playmode(ActualMusicInstance, ALLEGRO_PLAYMODE_LOOP);
  al_play_sample_instance(ActualMusicInstance);
}


void ChangeMusicVolume(float v) {
  if (ActualMusicInstance != NULL) al_set_sample_instance_gain(ActualMusicInstance, v);
}


void ClearMusic() {
  if (ActualMusicInstance != NULL) al_destroy_sample_instance(ActualMusicInstance);
}
