#ifndef _SNDVIRT_H_
#define _SNDVIRT_H_
 
#include "sndlst2.h"
 
/*handle to functions*/
typedef long (SND_CALL *td_pfn_lPlaySxd)(tduRefRes,SoundParam*,long,SND_td_pfn_vSoundCallback,long);
typedef void (SND_CALL *td_pfn_vPauseSxd)(long);
typedef void (SND_CALL *td_pfn_vResumeSxd)(long);
typedef SndBool (SND_CALL *td_pfn_bSetParamSxd)(long,SoundParam*);
typedef void (SND_CALL *td_pfn_vStopSxd)(long);
typedef SndReal (SND_CALL *td_pfn_rGetPosSxd)(long);
typedef SndReal (SND_CALL *td_pfn_rGetLengthSxd)(long);
typedef void (SND_CALL *td_pfn_vRemoveCallbackSxd)(long);
typedef SndBool (SND_CALL *td_pfn_bTestIsPlayingSxd)(long);
 
 
/*typedefs*/
SNDLST2_M_DynamicUseListOf(SND_tdhVirtualModule);
 
typedef struct _virtual_voice *p_virtual_voice;
 
SNDLST2_M_DynamicUseListOf(p_virtual_voice);
 
typedef struct _audible_voice *p_audible_voice;
 
SNDLST2_M_DynamicUseListOf(p_audible_voice);
 
typedef struct _dead_voice *p_dead_voice;
 
SNDLST2_M_DynamicUseListOf(p_dead_voice);
 
typedef struct _virtual_voice_list *p_virtual_voice_list;
 
typedef struct _virtual_voice{
        long    lVoice;         /*retour du PlaySxdWave;C_PLAY_FAILED si pas de Stop necessaire*/
        SndReal rNorme;         /*norme permettant le classement des voies (+/- distance au micro)*/
        long    lPrio;          /*priority level*/
        long    lInstance;      /*instace (+/- ordre d'arrivee)*/
        SND_td_pfn_vSoundCallback pfnCallback;/*fonction de callback haut-niveau (passee à SND_fn_lPlayVirt)*/
        long    lParamCallback;
        tduRefRes       tduRes;         /*ressource virtuellement associee à l voie (passee à SND_fn_lPlayVirt)*/
        long            lSizeParam;     /*taille du suivant*/
        SoundParam*     pstParam;       /*copy du dernier SetParam*/
        SndBool_field_decl(bHardCallback);  /*TRUE if Callback called by hard-leve, FALSE if called by SNDVIRT*/
        SndBool_field_decl(bUsed);          /*FALSE si aucune reference n'a encore ete rendue publique = destrction immediate toleree*/
        SndBool_field_decl(bPaused);        /*TRUE si en pause*/
        /*---*/
        p_audible_voice audible;        /*!=NULL si voie audible*/
        p_dead_voice    dead;   /*!=NULL si voie audible*/
    SNDLST2_M_DynamicElementDeclaration(p_virtual_voice)
} virtual_voice;
 
typedef struct _virtual_voice_list{
    SNDLST2_M_DynamicAnchorDeclaration(p_virtual_voice) pList;
} virtual_voice_list;
 
/*liste des audibles*/
typedef struct _audible_voice{
        p_virtual_voice         voice;
        SndBool                         bCheck;
    SNDLST2_M_DynamicElementDeclaration(p_audible_voice)
} audible_voice;
 
typedef struct _audible_voice_list{
    SNDLST2_M_DynamicAnchorDeclaration(p_audible_voice) pList;
} audible_voice_list;
 
/*liste des voies tuees (à desallouee ou à reutiliser pour une nouvelle voie*/
typedef struct _dead_voice{
        p_virtual_voice         voice;
    SNDLST2_M_DynamicElementDeclaration(p_dead_voice)
} dead_voice;
 
typedef struct _dead_voice_list{
    SNDLST2_M_DynamicAnchorDeclaration(p_dead_voice) pList;
} dead_voice_list;
 
typedef struct _ptr_virtualfunction
{
        td_pfn_lPlaySxd pfn_lPlaySxd;
        td_pfn_vStopSxd pfn_vStopSxd;
        td_pfn_bSetParamSxd pfn_bSetParamSxd;
        td_pfn_vPauseSxd pfn_vPauseSxd;
        td_pfn_vResumeSxd pfn_vResumeSxd;
        td_pfn_rGetPosSxd pfn_rGetPosSxd;
        td_pfn_rGetLengthSxd pfn_rGetLengthSxd;
        td_pfn_vRemoveCallbackSxd pfn_vRemoveCallbackSxd;
        td_pfn_bTestIsPlayingSxd pfn_bTestIsPlayingSxd;
} ptr_virtualfunction;
 
/*liste des module Virtual*/
typedef struct _virtual_module{
        /*liste des voies virtuelles = id retournes par PlayVitual*/
        virtual_voice_list virtual_voices;
        /*liste des voies physique = id retournes par PlaySnd*/
        audible_voice_list audible_voices;
        /*liste des voies desallouees*/
        dead_voice_list dead_voices;
        long g_lInstance;
        long g_lNbSxdAudible;
        ptr_virtualfunction stPtrFunctions;
    SNDLST2_M_DynamicElementDeclaration(SND_tdhVirtualModule)
} virtual_module;
 
typedef struct _virtual_module_list{
    SNDLST2_M_DynamicAnchorDeclaration(SND_tdhVirtualModule) pList;
} virtual_module_list;
 
 
/*functions*/
long SND_fn_lPlaySxdVirtual(SND_tdhVirtualModule module,tduRefRes res,SoundParam *par,long prio,SND_td_pfn_vSoundCallback fn_callback,long par_callback);
void SND_fn_vRemoveCallbackSxdVirtual(SND_tdhVirtualModule module,long voice);
SndBool SND_fn_bSetParamSxdVirtual(SND_tdhVirtualModule module,long voice,SoundParam *par);
SndBool SND_fn_bTestIsPlayingSxdVirtual(SND_tdhVirtualModule module,long voice);
void SND_fn_vStopSxdVirtual(SND_tdhVirtualModule module,long voice);
void SND_fn_vPauseSxdVirtual(SND_tdhVirtualModule module,long voice);
void SND_fn_vResumeSxdVirtual(SND_tdhVirtualModule module,long voice);
void SND_fn_vSynchroSxdVirtual(SND_tdhVirtualModule module);
 
SndReal SND_fn_rGetPosSxdVirtual(SND_tdhVirtualModule module,long voice);
SndReal SND_fn_rGetLengthSxdVirtual(SND_tdhVirtualModule module,long voice);
 
SND_tdhVirtualModule SND_fn_lInitSxdVirtual(long nb_audible,ptr_virtualfunction* functions);
SndBool SND_fn_bTestInitSxdVirtual(SND_tdhVirtualModule module);
void SND_fn_vDesInitSxdVirtual(SND_tdhVirtualModule module);
void SND_fn_vChangeNbVoiceWishedSxdVirtual(SND_tdhVirtualModule module,long nb_audible);
 
#endif /*_SNDVIRT_H_*/
