package net.phatcode.rel.utils;

import java.net.URL;
import java.util.HashMap;


import kuusisto.tinysound.Music;
import kuusisto.tinysound.Sound;
import kuusisto.tinysound.TinySound;

public class Sonics
{
	private static Sonics instance = new Sonics();

	private HashMap<String, Sound> effects = new HashMap<>();
	private HashMap<String, Music> musics = new HashMap<>();

	int numSfxs = 0;
	int numBgms = 0;
	
	
	private Sonics()
	{
		TinySound.init();
	}
	
	public static Sonics getInstance()
	{
		return instance;
	}
	
	public void shutDown()
	{
		TinySound.shutdown();
	}
	
	public void addMusic( String filename )
	{
	
		URL url = this.getClass().getClassLoader().getResource(filename);
		musics.put( filename, TinySound.loadMusic( url ));
		numBgms++;
		
	}
	
	public void addEffect( String filename )
	{
	
		URL url = this.getClass().getClassLoader().getResource(filename);
		effects.put( filename, TinySound.loadSound( url ));
		numSfxs++;
		
	}

	public void playMusic( String filename, boolean loop )
	{
		musics.get(filename).play(loop);
	}
	
	public void playEffect( String filename )
	{
		effects.get(filename).play();
	}
	
	public void playMusic( String filename, boolean loop, double volume )
	{
		musics.get(filename).play(loop, volume);
	}
	
	public void playEffect( String filename, double volume )
	{
		effects.get(filename).play(volume);
	}
	
	public void setMusicVolume( String filename, double volume )
	{
		musics.get(filename).setVolume(volume);
	}
	
	public void pauseMusic( String filename )
	{
		musics.get(filename).pause();
	}
	
	public void resumeMusic( String filename )
	{
		musics.get(filename).resume();
	}
	
	public boolean isMusicPlaying( String filename )
	{
		return musics.get(filename).playing();
	}
	
	public void stopMusic( String filename )
	{
		musics.get(filename).stop();
	}
	
}
