/*
 * Land Sea Air -- an interactive music game
 * demonstrating the "secret yanni" techique, with key changes
 * design, animation, audio, and code by peter "pdx" drescher
 * twittering machine
 * 
 */
package com.twittering.landseaair;

import android.os.Handler;
import android.os.Message;

public class FMODaudio {

    public static final int DAYTIME        = 0;
	public static final int TRANS_TO_NIGHT = 1;
	public static final int NIGHTTIME      = 2;
	public static final int TRANS_TO_DAY   = 3;
	private int currentMode = 0;
	
	private Handler mUpdateHandler = new Handler()
	{
		public void handleMessage(Message msg)
		{	
			// call system update every 75ms
			cUpdate();
			removeMessages(0);
		    sendMessageDelayed(obtainMessage(0), 75);
		}
	};
	
/*** INITIALIZATION AND SHUTDOWN ROUTINES ***/
	
    public void initFMOD() //onStart
    {
       	cInitFMOD();
    	mUpdateHandler.sendMessageDelayed(mUpdateHandler.obtainMessage(0), 0);
    }
    
    public void initAirAudio(String mediaPath) //onStart
    {
       	cInitAirAudio(mediaPath);
    }
    
    public void initSeaAudio(String mediaPath) //onStart
    {
       	cInitSeaAudio(mediaPath);
    }
    
    public void initLandAudio(String mediaPath) //onStart
    {
       	cInitLandAudio(mediaPath);
    }
    
    public void releaseFMOD() //Menu onStop
    {
    	mUpdateHandler.removeMessages(0);
		cReleaseFMOD();		
    }
    
    public void stopAirAudio() //onStop
    {
    	mUpdateHandler.removeMessages(0);
		cStopAirAudio();  //unload fev
    }
    
    public void stopSeaAudio() //onStop
    {
    	mUpdateHandler.removeMessages(0);
    	cStopSeaAudio();
    }
    
    public void stopLandAudio() //onStop
    {
    	mUpdateHandler.removeMessages(0);
    	cStopLandAudio();
    }
    
/***  AIR LEVEL CALLS   ***/
    
    public void changeKey(float keyChange)
    {
	    cChangeKey(keyChange);
    }	
    public int checkAirKey()
    {
    	return cCheckAirKey();
    }	
    public void playBonusSound()
    {
	    cPlayBonusSound();
    }	
    public void playBFSound()
    {
	    cPlayBFSound();
    }
    public void setMode(int mode)
    {
    	if (mode != currentMode) {
		    switch (mode) {
		    case DAYTIME:
		    	cDaytime();
		    	break;
		    case TRANS_TO_NIGHT:
		    	cTransToNight();
		    	break;
		    case NIGHTTIME:
		    	cNighttime();
		    	break;
		    case TRANS_TO_DAY:
		    	cTransToDay();
		    	break;  	
		    }
		    currentMode = mode;
    	}
    }	

/***  SEA LEVEL CALLS ***/
    
    public void playPlanktonSound()
    {
	    cPlayPlanktonSound();
    }
    public int checkSeaKey()
    {
    	return cCheckSeaKey();
    }

/***  LAND LEVEL CALLS ***/
    
    public void playRatSound()
    {
	    cPlayRatSound();
    }
    public void playFrogSound()
    {
	    cPlayFrogSound();
    }
    public boolean checkBGflag()
    {
    	boolean BGflag = cCheckBGflag();
    	return BGflag;
    }

/*** LOAD LIBRARTIES AND NATIVE PROTOTYPES ***/
    
    static 
    {
    	System.loadLibrary("fmodex");
    	System.loadLibrary("fmodevent");
        System.loadLibrary("main");
    }
   
	public native void cInitFMOD();
	public native void cReleaseFMOD();
	public native void cUpdate();
	public native void cInitAirAudio(String mediaPath);
	public native void cInitSeaAudio(String mediaPath);
	public native void cInitLandAudio(String mediaPath);
	public native void cStopAirAudio();
	public native void cStopSeaAudio();
	public native void cStopLandAudio();
	public native void cChangeKey(float keyChange);
	public native void cPlayBonusSound();
	public native void cPlayBFSound();
	public native void cDaytime();
	public native void cTransToNight();
	public native void cNighttime();
	public native void cTransToDay();
	public native void cPlayPlanktonSound();
	public native void cPlayRatSound();
	public native void cPlayFrogSound();
	public native boolean cCheckBGflag();
	public native int cCheckAirKey();
	public native int cCheckSeaKey();
}