//gestion du menu ED (module MNU) pour 
// target MW

//!!!! aucune fonction en peut être appelée
//seuls les prototypes sont exploités

#include "cpa_std.h"
#include "acp_base.h"
#include "hdl.h"
#include "mth.h"
#include "pos.h"
#include "geo.h"
#include "gli.h"
#include "gld.h"
#include "fon.h"
#include "mnu.h"

#include "SND.h"

#include "mnusnd.h"

//!!!!!!! les conventions d'appel ne sont pas les mêmes pour toutes les fonctions
//		définir DLLCALL avec la valeur adéquat avant d'utiliser SND_DefinePointerx
//definitions des fct MNU
#define DLLCALL
SND_DefinePointer_void2(MNU_fn_vAddCallback,void,MNU_tdpfn_Callback,char*);
SND_DefinePointer1(MNU_fn_lGetValue,long,MNU_tdxHandleOfSlider);
SND_DefinePointer2(MNU_fn_bSetValue,BOOL,MNU_tdxHandleOfSlider,short);
//defintions des fct SND
SND_DefinePointer0(SND_fn_bGetReverseStereoSound,SndBool);
SND_DefinePointer_void1(SND_fn_vSetReverseStereoSound,void,SndBool);
#undef DLLCALL
#define DLLCALL WINAPI
SND_DefinePointer0(SND_fn_bGetDolbySample,SndBool);
SND_DefinePointer_void1(SND_fn_vSetDolbySample,void,SndBool);
SND_DefinePointer0(SND_fn_vGetHModuleWav,HMODULE);


void fn_vMenuSon_InitStereo(struct MNU_stMenuItem_ *hMenuItem,char *szText[])
{
	SndBool stereo;

	stereo=SND_fn_bGetReverseStereoSound();
	MNU_fn_bSetValue(hMenuItem->uItem.hSlider,(short)(stereo ? 2 : 1));
}

void fn_vMenuSon_ChangeStereo(struct MNU_stMenuItem_ *hMenuItem,char *szText[])
{
	long stereo;

	stereo=MNU_fn_lGetValue(hMenuItem->uItem.hSlider);
	SND_fn_vSetReverseStereoSound((stereo==2) ? TRUE : FALSE);
}

void fn_vMenuSon_InitDolby(struct MNU_stMenuItem_ *hMenuItem,char *szText[])
{
	SndBool dolby;

	dolby=SND_fn_bGetDolbySample();
	MNU_fn_bSetValue(hMenuItem->uItem.hSlider,(short)(dolby ? 2 : 1));
}

void fn_vMenuSon_ChangeDolby(struct MNU_stMenuItem_ *hMenuItem,char *szText[])
{
	long dolby;

	dolby=MNU_fn_lGetValue(hMenuItem->uItem.hSlider);
	SND_fn_vSetDolbySample((dolby==2) ? TRUE : FALSE);
}

//Init géné
__declspec(dllexport) void SNDMNUInit(HINSTANCE hinst)
{
	HMODULE hWavModule;

	//init des pointeurs de fonctions MNU
	DLLpfn_MNU_fn_vAddCallback=(DLLtdpfn_MNU_fn_vAddCallback)GetProcAddress(hinst,"MNU_fn_vAddCallback");
	DLLpfn_MNU_fn_lGetValue=(DLLtdpfn_MNU_fn_lGetValue)GetProcAddress(hinst,"MNU_fn_lGetValue");
	DLLpfn_MNU_fn_bSetValue=(DLLtdpfn_MNU_fn_bSetValue)GetProcAddress(hinst,"MNU_fn_bSetValue");
	//init des pointeurs de fonctions SND
	DLL_M_GetProcAddress(SND_fn_bGetReverseStereoSound,hinst);
	DLL_M_GetProcAddress(SND_fn_vSetReverseStereoSound,hinst);
	
	DLL_M_GetProcAddressDecored(SND_fn_vGetHModuleWav,hinst);
	hWavModule=SND_fn_vGetHModuleWav();

	DLL_M_GetProcAddressDecored(SND_fn_bGetDolbySample,hWavModule);
	DLL_M_GetProcAddressDecored(SND_fn_vSetDolbySample,hWavModule);

	//init des callback MNU
	MNU_fn_vAddCallback(fn_vMenuSon_InitStereo,"InitStereo");
	MNU_fn_vAddCallback(fn_vMenuSon_ChangeStereo,"ChangeStereo");
	MNU_fn_vAddCallback(fn_vMenuSon_InitDolby,"InitDolby");
	MNU_fn_vAddCallback(fn_vMenuSon_ChangeDolby,"ChangeDolby");
}

