#include "SNDinc.h"
#include "sndevent.h"
#include "sndres.h"
#include "sndldscn.h"
#include "sndplay.h"
//#include "sndldbin.h"

#ifdef _DLL_COMPILATION_MODE
#include "snddll.h"
#endif


#ifndef NO_ACP_SOUND


//***************************************************************************
//***************************************************************************
//* File:	sndldscn.c 
//***************************************************************************
//* Project/Module: CPA project, SND module, Script version 
//***************************************************************************
//* Description: Functions specific to the script version of the SND module
//*
//***************************************************************************
//* Version                      1.0
//* Creation date        09/08/96
//* Revision date
//*
//*				 (c) Ubi Sound Studio 1998
//***************************************************************************
//***************************************************************************



#include "sndld_sh.cxx"



//***************************************************************************
//***************************************************************************
//*																			*
//*																			*
//*						MISCELLANEOUS FUNCTIONS								*
//*																			*
//*																			*
//***************************************************************************
//***************************************************************************






//-----------------------------------------------------------------------------
//  Name : SND_fn_pCreateXXX/SND_fn_vCopyXXX/SND_fn_vDestroyXXX
//-----------------------------------------------------------------------------
//  Description :   Functions for creation, copy, and destruction of 
//					various data structures
//-----------------------------------------------------------------------------
//  Input :  XXX       
//  Output : void       
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//-----------------------------------------------------------------------------


// resource tout type
tdstBlockResourceMem* SND_fn_pCreateResM(void)
{
    tdstBlockResourceMem* tmp;

    tmp=(tdstBlockResourceMem*)GlobalAlloc(GPTR,sizeof(tdstBlockResourceMem));
   SNDLST2_M_StaticInitElement(tmp);
    tmp->eType=TYPE_INVALID;
    
    return tmp;
}

void SND_fn_vCopyResM(tdstBlockResourceMem*_pDest,tdstBlockResourceMem* _pSrc)
{	// Copy everything except the list pointers:
	_pDest->Id=_pSrc->Id;
	_pDest->eType=_pSrc->eType;
	_pDest->eStorage=_pSrc->eStorage;
	_pDest->ucVolume=_pSrc->ucVolume;
	_pDest->bIsLoaded=_pSrc->bIsLoaded;
	memcpy(&_pDest->uRes,&_pSrc->uRes,sizeof(tduResMem));
}

void SND_fn_vDestroyResM(tdstBlockResourceMem* _pObj)
{
    SNDLST2_M_StaticIsolate( _pObj);
    GlobalFree(_pObj);

}

tdstSndPolyResource* SND_fn_pCreatePolyResM(void)
{
    tdstSndPolyResource* tmp;
    tmp=(tdstSndPolyResource*)GlobalAlloc(GPTR,sizeof(tdstSndPolyResource));
   SNDLST2_M_StaticInitAnchor(tmp); 
    return tmp;
}
void SND_fn_vCopyPolyResM(tdstSndPolyResource*_pDest,tdstSndPolyResource* _pSrc)
{
	memcpy(_pDest,_pSrc,sizeof(tdstSndPolyResource));
}

void SND_fn_vDestroyPolyResM(tdstSndPolyResource* _pObj)
{
    GlobalFree(_pObj);
}


// event
SND_tdstBlockEvent* SND_fn_pCreateEventM(void)
{
    SND_tdstBlockEvent* tmp;

    tmp=(SND_tdstBlockEvent*)GlobalAlloc(GPTR,sizeof(SND_tdstBlockEvent));
	memset(tmp,0,sizeof(SND_tdstBlockEvent));//VERY IMPORTANT!! NEVER FORGET TO PRESET WITH 0
    SNDLST2_M_StaticInitElement(tmp); 
    tmp->eType=EVT_INVALID;

    return tmp;
}


void SND_fn_vCopyEventM(SND_tdstBlockEvent*_pDest,SND_tdstBlockEvent* _pSrc)
{
	_pDest->Id=_pSrc->Id;
	_pDest->eType=_pSrc->eType;
	_pDest->bStopable=_pSrc->bStopable;
	_pDest->bDynamic=_pSrc->bDynamic;
	
	memcpy(&_pDest->uParams,&_pSrc->uParams,sizeof(tduEvtParams));
}

void SND_fn_vDestroyEventM(SND_tdstBlockEvent* _pObj)
{
    SNDLST2_M_StaticIsolate( _pObj);
    GlobalFree(_pObj);
}

//liste d'event
tdstSndPolyEvent* SND_fn_pCreatePolyEventM(void)
{
    tdstSndPolyEvent* tmp;
    
    tmp=(tdstSndPolyEvent*)GlobalAlloc(GPTR,sizeof(tdstSndPolyEvent));
    SNDLST2_M_StaticInitAnchor(tmp);

    return tmp;
}
void SND_fn_vCopyPolyEventM(tdstSndPolyEvent*_pDest,tdstSndPolyEvent* _pSrc)
        {       memcpy(_pDest,_pSrc,sizeof(tdstSndPolyEvent));}
void SND_fn_vDestroyPolyEventM(tdstSndPolyEvent* _pObj)
{
    GlobalFree(_pObj);
}

// track:
tdstInfoTrackMem* SND_fn_pCreateTrackM(void)
{
    tdstInfoTrackMem* tmp;

    tmp=(tdstInfoTrackMem*)GlobalAlloc(GPTR,sizeof(tdstInfoTrackMem));
    SNDLST2_M_StaticInitElement(tmp); 
    
    return tmp;
}
void SND_fn_vCopyTrackM(tdstInfoTrackMem*_pDest,tdstInfoTrackMem* _pSrc)
{
	memcpy(_pDest,_pSrc,sizeof(tdstInfoTrackMem));
	SNDLST2_M_StaticInitElement(_pDest);
}
void SND_fn_vDestroyTrackM(tdstInfoTrackMem* _pObj)
{
    SNDLST2_M_StaticIsolate( _pObj);
    GlobalFree(_pObj);
}

// liste de track
tdstInfoTrackList* SND_fn_pCreatePolyTrackM(void)
{
    tdstInfoTrackList* tmp;

    tmp=(tdstInfoTrackList*)GlobalAlloc(GPTR,sizeof(tdstInfoTrackList));
    SNDLST2_M_StaticInitAnchor(tmp);
    return tmp;
}
void SND_fn_vCopyPolyTrackM(tdstInfoTrackList*_pDest,tdstInfoTrackList* _pSrc)
        {       memcpy(_pDest,_pSrc,sizeof(tdstInfoTrackList));}
void SND_fn_vDestroyPolyTrackM(tdstInfoTrackList* _pObj)
{
    GlobalFree(_pObj);
}


//list de range-plage de split
tdstRangeSplitListMem* SND_fn_pCreatePolyRangeM(void)
{
    tdstRangeSplitListMem* tmp;

//    tmp=(tdstRangeSplitListMem*)SND_fn_pvMallocSnd(sizeof(tdstRangeSplitListMem));
    tmp=(tdstRangeSplitListMem*)GlobalAlloc(GPTR,sizeof(tdstRangeSplitListMem));
    SNDLST2_M_StaticInitAnchor(tmp);
    return tmp;
}
void SND_fn_vCopyPolyRangeM(tdstRangeSplitListMem*_pDest,tdstRangeSplitListMem* _pSrc)
        {       memcpy(_pDest,_pSrc,sizeof(tdstRangeSplitListMem));}
void SND_fn_vDestroyPolyRangeM(tdstRangeSplitListMem* _pObj)
{
    GlobalFree(_pObj);
}

//range-plage de split
tdstRangeSplitMem* SND_fn_pCreateRangeM(void)
{
    tdstRangeSplitMem* tmp;

    tmp=(tdstRangeSplitMem*)GlobalAlloc(GPTR,sizeof(tdstRangeSplitMem));
    SNDLST2_M_StaticInitElement(tmp);
    return tmp;
}
void SND_fn_vCopyRangeM(tdstRangeSplitMem*_pDest,tdstRangeSplitMem* _pSrc)
{
	memcpy(_pDest,_pSrc,sizeof(tdstRangeSplitMem));
	SNDLST2_M_StaticInitElement(_pDest);
}
void SND_fn_vDestroyRangeM(tdstRangeSplitMem* _pObj)
{
    GlobalFree(_pObj);
}

//liste pour switch
tdstTypeSwitchMem* SND_fn_pCreateSwitchListM(void)
{
    tdstTypeSwitchMem* tmp;

    tmp=(tdstTypeSwitchMem*)GlobalAlloc(GPTR,sizeof(tdstTypeSwitchMem));
    SNDLST2_M_StaticInitAnchor(tmp);
	tmp->bMaintainIfSwitched=FALSE;
    return tmp;
}
void SND_fn_vCopySwitchListM(tdstTypeSwitchMem*_pDest,tdstTypeSwitchMem* _pSrc)
        {       memcpy(_pDest,_pSrc,sizeof(tdstTypeSwitchMem));}
void SND_fn_vDestroySwitchListM(tdstTypeSwitchMem* _pObj)
{
    GlobalFree(_pObj);
}

//element liste pour switch
tdstSwitchElement* SND_fn_pCreateSwitchElementM(void)
{
    tdstSwitchElement* tmp;

    tmp=(tdstSwitchElement*)GlobalAlloc(GPTR,sizeof(tdstSwitchElement));
    SNDLST2_M_StaticInitElement(tmp);
    return tmp;
}
void SND_fn_vCopySwitchElementM(tdstSwitchElement*_pDest,tdstSwitchElement* _pSrc)
{
	memcpy(_pDest,_pSrc,sizeof(tdstSwitchElement));
	SNDLST2_M_StaticInitElement(_pDest);
}
void SND_fn_vDestroySwitchElementM(tdstSwitchElement* _pObj)
{
    SNDLST2_M_StaticIsolate( _pObj);
    GlobalFree(_pObj);
}

//liste pour random
tdstTypeRandomMem* SND_fn_pCreateRandomListM(void)
{
    tdstTypeRandomMem* tmp;

    tmp=(tdstTypeRandomMem*)GlobalAlloc(GPTR,sizeof(tdstTypeRandomMem));
    SNDLST2_M_StaticInitAnchor(tmp);
	tmp->rProbNothing=0;
	tmp->bNothingCanBeChosenTwice=TRUE;

    return tmp;
}
void SND_fn_vCopyRandomListM(tdstTypeRandomMem*_pDest,tdstTypeRandomMem* _pSrc)
        {       memcpy(_pDest,_pSrc,sizeof(tdstTypeRandomMem));}
void SND_fn_vDestroyRandomListM(tdstTypeRandomMem* _pObj)
{
    GlobalFree(_pObj);
}

//element liste pour random
tdstRandomElement* SND_fn_pCreateRandomElementM(void)
{
    tdstRandomElement* tmp;

    tmp=(tdstRandomElement*)GlobalAlloc(GPTR,sizeof(tdstRandomElement));
    SNDLST2_M_StaticInitElement(tmp);
	tmp->rProb=0;
	tmp->bCanBeChosenTwice=TRUE;
    return tmp;
}
void SND_fn_vCopyRandomElementM(tdstRandomElement*_pDest,tdstRandomElement* _pSrc)
{
	memcpy(_pDest,_pSrc,sizeof(tdstRandomElement));
	SNDLST2_M_StaticInitElement(_pDest);
}
void SND_fn_vDestroyRandomElementM(tdstRandomElement* _pObj)
{
    SNDLST2_M_StaticIsolate( _pObj);
    GlobalFree(_pObj);
}

// theme
//
tdstThemePart* SND_fn_pCreateThemePart(void)
{
    tdstThemePart* tmp;

    tmp=(tdstThemePart*)GlobalAlloc(GPTR,sizeof(tdstThemePart));
    SNDLST2_M_StaticInitElement(tmp);
    tmp->uRes.pstPtr=SND_C_RES_FANTOME_PTR;
	tmp->bLoopStart=FALSE;
	tmp->bLoopEnd=FALSE;
	tmp->eTransition=TRANSITION_CROSSFADE;
	tmp->lNbLoops=C_THEME_PART_PLAY_ONCE;
	tmp->rFadeDuration=DEFAULT_FADEDURATION;

    return tmp;
};
void SND_fn_vCopyThemePart(tdstThemePart*_pDest,tdstThemePart* _pSrc)
        {       memcpy(_pDest,_pSrc,sizeof(tdstThemePart));}
void SND_fn_vDestroyThemePart(tdstThemePart* _pObj)
{
    SNDLST2_M_StaticIsolate( _pObj);
    GlobalFree(_pObj);
}

tdstThemePartOutro* SND_fn_pCreateThemePartOutro(void)
{
    tdstThemePartOutro* tmp;

    tmp=(tdstThemePartOutro*)GlobalAlloc(GPTR,sizeof(tdstThemePartOutro));
    tmp->uRes.pstPtr=SND_C_RES_FANTOME_PTR;
	tmp->eTransition=TRANSITION_CROSSFADE;
	tmp->rFadeDuration=DEFAULT_FADEDURATION;

    return tmp;
};
void SND_fn_vCopyThemePartOutro(tdstThemePartOutro*_pDest,tdstThemePartOutro* _pSrc)
        {       memcpy(_pDest,_pSrc,sizeof(tdstThemePartOutro));}
void SND_fn_vDestroyThemePartOutro(tdstThemePartOutro* _pObj)
{
    GlobalFree(_pObj);
}
//
tdstTypeThemeMem* SND_fn_pCreateTheme(void)
{
    tdstTypeThemeMem* tmp;

    tmp=(tdstTypeThemeMem*)GlobalAlloc(GPTR,sizeof(tdstTypeThemeMem));
    SNDLST2_M_StaticInitAnchor(tmp);
    tmp->ulStartLoop=0;      //indice du point de rebouclage
    tmp->ulNbParts=0;        //nb de parts
	tmp->rFadeDuration=DEFAULT_FADEDURATION;
	tmp->ulNbLoops=C_THEME_MAINLOOP_INFINITE;

    return tmp;
};
void SND_fn_vCopyTheme(tdstTypeThemeMem*_pDest,tdstTypeThemeMem* _pSrc)
{
	memcpy(_pDest,_pSrc,sizeof(tdstTypeThemeMem));
}

void SND_fn_vDestroyTheme(tdstTypeThemeMem* _pObj)
{
    GlobalFree(_pObj);
}









//***************************************************************************
//***************************************************************************
//*																			*
//*																			*
//*						SCRIPT CALLBACKS : RESOURCES						*
//*																			*
//*																			*
//***************************************************************************
//***************************************************************************


//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadResDisk
//-----------------------------------------------------------------------------
//  Description :   Script Callback for creation of tdstBlockResourceDisk 
//					from SndResourceDisk_<n>(<ResType>)
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/


SCR_tde_Anl_ReturnValue SND_fn_eLoadResDisk(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
    tdstBlockResourceDisk *pResDisk;
	unsigned long ulResId;
    switch (cType)
    {
	case SCR_EA_Anl_BeginSection:// Creation of resource :
		// Create resource:
		pResDisk=(tdstBlockResourceDisk*)GlobalAlloc(GPTR,sizeof(tdstBlockResourceDisk));

		SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pResDisk);

		// Set Engine structure data :

		ulResId=atoi(szAction);
		pResDisk->Id=ulResId;

		// Get resource type:
		pResDisk->eType=SND_fn_eGetResTypeFromString(szParams[0]);

		// Set default data for the other fields, according to res type:
		pResDisk->eStorage=TYPE_EXTERNAL;
		pResDisk->ulDataSize=0;
		pResDisk->ulDataOffset=0;
		pResDisk->ucVolume=0;
		pResDisk->eStorage=SAMPLE_PCM;

		switch (pResDisk->eType)
        {
            case TYPE_SAMPLE:
                pResDisk->uRes.stSample=c_stDefaultSample;
                break;
            case TYPE_MIDI:
                pResDisk->uRes.stMidi=c_stDefaultMidi;
                break;
            case TYPE_SEQUENCE:
                pResDisk->uRes.stSequence=c_stDefaultSequence;
                break;
            case TYPE_SWITCH:
//                SNDLST2_M_StaticInitAnchor(&pResDisk->uRes.stSwitch);
				pResDisk->uRes.stSwitch.bDynamic=UNINITIALIZED_VALUE;
                break;
            case TYPE_SPLIT:
                pResDisk->uRes.stSplit=c_stDefaultSplit;
                break;
            case TYPE_THEME:
				pResDisk->uRes.stTheme=c_stDefaultTheme;
				break;
            case TYPE_RANDOM:
//                SNDLST2_M_StaticInitAnchor(&pResDisk->uRes.stRandom);
                break;
		}
		break; // end case SCR_EA_Anl_BeginSection

	case SCR_EA_Anl_Entry:
		SCR_M_RdL0_GetSectionLong(0,0,tdstBlockResourceDisk *,pResDisk);

		SND_fn_vAnalyseScriptEntryForResType(pResDisk->eType,szAction,szParams,pResDisk);

		break ; // end case SCR_EA_Anl_Entry
	}
	return  SCR_ERV_Anl_NormalReturn;
}






//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadResM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndResourceM section 
//					
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/


// Callback for creation of tdstBlockResourceDisk from SndResourceDisk_<n>(<ResType>)
SCR_tde_Anl_ReturnValue SND_fn_eLoadResM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	tdstBlockResourceDisk *pResDisk;
	tdstBlockResourceMem *pResMem;
	unsigned long ulResId;
  
	switch (cType)
	{
	case SCR_EA_Anl_BeginSection:// Creation of resource :
		// Create resource:
		pResMem=SND_fn_pCreateResM();
		SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pResMem);

		ulResId=atoi(szAction);
		pResMem->Id=ulResId;
		SCR_M_RdL0_SetSectionLong(0,1,ulResId);
		break;
	case SCR_EA_Anl_EndSubSection:
		//  We just finished analysing a subsection: 
		//		if it's the BRDisk, there are inits to be done:
		SCR_M_RdL0_GetSectionLong(0,0,tdstBlockResourceMem *,pResMem);
		if (strcmp(szParams[0],"SndResourceDisk")==0)
		{
			SCR_M_RdL0_GetSectionLong(1,0,tdstBlockResourceDisk *,pResDisk);
			
			// Initialize list parents for complex resources:
			switch (pResDisk->eType)
			{
				case TYPE_SAMPLE:
				case TYPE_MIDI:
				case TYPE_CDAUDIO:
					break;
				case TYPE_SEQUENCE:
					SNDLST2_M_StaticInitAnchor(&(pResMem->uRes.stSequence.stResList));									
					break;
				case TYPE_SPLIT:
					SNDLST2_M_StaticInitAnchor(&(pResMem->uRes.stSplit.stRangeList));									
					break;
				case TYPE_SWITCH:
					SNDLST2_M_StaticInitAnchor(&(pResMem->uRes.stSwitch));									
					break;
				case TYPE_THEME:
					SNDLST2_M_StaticInitAnchor(&(pResMem->uRes.stTheme));									
					break;
				case TYPE_RANDOM:
					SNDLST2_M_StaticInitAnchor(&(pResMem->uRes.stRandom));									
					break;
				case TYPE_INVALID:// Problem!
				default:
					SND_fn_vDisplayError(E_uwSndInvalidTypeOfResource,"");
			}

			//stop any instance of resource before unload it
			SND_fn_vStopBeforeUnLoadResSnd(pResMem);

			// Initializes the BRMem as unloaded ?:
			SND_fn_vUnLoadResSnd(pResMem);

			// Free the disk struct:
		//    SND_fn_vFreeSnd(pResDisk);
			GlobalFree(pResDisk);
		};
		break;
	}  // end       switch (cType)
	return  SCR_ERV_Anl_NormalReturn;
}                               






//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadPolyTrackM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndPolyTrackM section 
//					
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/


SCR_tde_Anl_ReturnValue SND_fn_eLoadPolyTrackM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
        tdstBlockResourceMem *pResMem;
        tdstInfoTrackList *pTrackList;
        tdstInfoTrackMem *pTrack;

        switch (cType)
        {
                case SCR_EA_Anl_BeginSection:
                        // Not ACP_Compliant, but works: get TrackList* from Anchor BRMem:
                        SCR_M_RdL0_GetSectionLong(-1,0,tdstBlockResourceMem *,pResMem);
						pTrackList=&(pResMem->uRes.stSequence.stResList);
                        SNDLST2_M_StaticInitAnchor(pTrackList);
                        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pTrackList);
						break;
                case SCR_EA_Anl_EndSubSection:
                        // We have loaded a track:
						SCR_M_RdL0_GetSectionLong(0,0,tdstInfoTrackList *,pTrackList);
                        SCR_M_RdL0_GetSectionLong(1,0,tdstInfoTrackMem *,pTrack);
                        // register track in list:
                        SNDLST2_M_StaticAddTail( pTrackList, pTrack);
                        break;
        }
        return  SCR_ERV_Anl_NormalReturn;
}

//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadTrackM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndTrackM section (sequence)
//					Fills a track struct with its data from script
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/

SCR_tde_Anl_ReturnValue SND_fn_eLoadTrackM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
        tdstInfoTrackMem *pTrack;
        tdstBlockResourceMem *pResMem;
		SCR_tdst_Cxt_Values* pScriptContext;

        switch (cType)
        {
                case SCR_EA_Anl_BeginSection:
                        pTrack=SND_fn_pCreateTrackM();
						SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pTrack);

						break;
                case SCR_EA_Anl_Entry:
                    SCR_M_RdL0_GetSectionLong(0,0,tdstInfoTrackMem *,pTrack);
					if (strcmp(szAction,"SetXIOFades")==0)
                    {
                            pTrack->ulCrossFade=*((unsigned long*)szParams[0]);
                            pTrack->ulFadeIn=*((unsigned long*)szParams[1]);
                            pTrack->ulFadeOut=*((unsigned long*)szParams[2]);
                    }
                    if (strcmp(szAction,"LoadResource")==0)
                    {
                        // get pointer to referenced resource: 
						if (SCR_fn_uc_RdL0_GetNumberOfParameters(szParams)==1) // A VIRER
							pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0],SCR_CDF_uw_Anl_Normal);
						else pScriptContext=((SCR_tdst_Cxt_Values**)szParams[1])[0];
                        pResMem=(tdstBlockResourceMem*)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext, 0);
						// register pointer in track:
                        pTrack->uRes.pstPtr=pResMem;
                    }
        }
        return  SCR_ERV_Anl_NormalReturn;
}

//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadPolyRangeM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndPolyRangeM section (split)
//					
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/

SCR_tde_Anl_ReturnValue SND_fn_eLoadPolyRangeM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
        tdstBlockResourceMem *pResMem;
        tdstRangeSplitListMem *pRangeList;
        tdstRangeSplitMem *pRange;

        switch (cType)
        {
                case SCR_EA_Anl_BeginSection:
                        // Not ACP_Compliant, but works: get TrackList* from Anchor BRMem:
						SCR_M_RdL0_GetSectionLong(-1,0,tdstBlockResourceMem *,pResMem);
                        pRangeList=&(pResMem->uRes.stSplit.stRangeList);
                        SNDLST2_M_StaticInitAnchor(pRangeList);
                        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pRangeList);
						break;
                case SCR_EA_Anl_EndSubSection:
                        // We have loaded a track:
                        SCR_M_RdL0_GetSectionLong(0,0,tdstRangeSplitListMem *,pRangeList);
                        SCR_M_RdL0_GetSectionLong(1,0,tdstRangeSplitMem *,pRange);
						// register track in list:
                        SNDLST2_M_StaticAddTail( pRangeList, pRange);
                        break;
        }
        return  SCR_ERV_Anl_NormalReturn;
}



//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadRangeM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndRangeM section (split)
//					Fills a track struct with its data from script
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/



SCR_tde_Anl_ReturnValue SND_fn_eLoadRangeM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
    tdstRangeSplitMem *pRange;
    tdstBlockResourceMem *pResMem;
	SCR_tdst_Cxt_Values* pScriptContext;

    switch (cType)
    {
    case SCR_EA_Anl_BeginSection:
		pRange=SND_fn_pCreateRangeM();
		SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pRange);
		break;
    case SCR_EA_Anl_Entry:
        SCR_M_RdL0_GetSectionLong(0,0,tdstRangeSplitMem*,pRange);
		if (strcmp(szAction,"LoadResource")==0)
        {
                // get pointer to referenced resource: 
				if (SCR_fn_uc_RdL0_GetNumberOfParameters(szParams)==1) // A VIRER
					pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0],SCR_CDF_uw_Anl_Normal);
				else pScriptContext=((SCR_tdst_Cxt_Values**)szParams[1])[0];
                pResMem=(tdstBlockResourceMem*)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext, 0);
				// register pointer in track:
                pRange->uRes.pstPtr=pResMem;
        }
        if (strcmp(szAction,"SetPitchValue")==0)
        {
                pRange->rPitchA=M_DoubleToRealSnd(SCRIPT_DOUBLE(szParams[0]));
                pRange->rPitchB=M_DoubleToRealSnd(SCRIPT_DOUBLE(szParams[1]));
                pRange->rPitchC=M_DoubleToRealSnd(SCRIPT_DOUBLE(szParams[2]));
                pRange->rPitchD=M_DoubleToRealSnd(SCRIPT_DOUBLE(szParams[3]));
        }
        if (strcmp(szAction,"SetVolume")==0)
                pRange->ucVolume=SCRIPT_INT(szParams[0]);
        else if (strcmp(szAction,"SetPitchCoef")==0)
                pRange->rCoefPitch=M_DoubleToRealSnd(SCRIPT_DOUBLE(szParams[0]));
        break;
    case SCR_EA_Anl_EndSection:
        SCR_M_RdL0_GetSectionLong(0,0,tdstRangeSplitMem *,pRange);
#ifndef DISABLE_SPLIT
        SND_fn_vInitRangeSplit(pRange);
#endif
        break;
    }
    return  SCR_ERV_Anl_NormalReturn;
}


//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadSwitchListM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndSwitchListM section (switch)
//					
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/

SCR_tde_Anl_ReturnValue SND_fn_eLoadSwitchListM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	SCR_tdst_Cxt_Values *pScriptContext;
        tdstBlockResourceMem *pResMem;
        tdstTypeSwitchMem* pSwitchList;
        tdstSwitchElement *pSwitchElement;
		char szTemp[260];

        switch (cType)
        {
                case SCR_EA_Anl_BeginSection:
                        // Not ACP_Compliant, but works: get RefRes* from Anchor BRMem:
                        SCR_M_RdL0_GetSectionLong(-1,0,tdstBlockResourceMem *,pResMem);
						pSwitchList=&(pResMem->uRes.stSwitch);
                        SNDLST2_M_StaticInitAnchor(pSwitchList);
						pSwitchList->bDynamic=FALSE;
						pSwitchList->bMaintainIfSwitched=FALSE;
						pSwitchList->hDefault=(SND_tdxHandleToSoundInfo)NULL;
                        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pSwitchList);
                        break;
// MUST BE DELETED ONCE THE OLD SCRIPTS ARE CONVERTED ( FROM 'CASE' to 'BREAK'):
                case SCR_EA_Anl_Entry:
					
					SCR_M_RdL0_GetSectionLong(0,0,tdstTypeSwitchMem *,pSwitchList);
					if (strcmp(szAction,"SetInfoType")==0)
					{
						pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal);
						pSwitchList->lTypeSwitch=(long)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext,0);
					}
					else if (strcmp(szAction,"SoundInfoType")==0)
					{
						sprintf(szTemp,"%s.sif^%s",SND_fn_czGetProjectTitle(),szParams[0]);
						pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szTemp, SCR_CDF_uw_Anl_Normal);
						pSwitchList->lTypeSwitch=(long)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext,0);
					}
					else if (strcmp(szAction,"SetDefaultValue")==0)
					{
						pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal);
						pSwitchList->hDefault=(long)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext,0);
					}
					else if (strcmp(szAction,"SetDynamic")==0)
					{
						pSwitchList->bDynamic=(SndBool)((char*)szParams[1])[0];
					}
					else if (strcmp(szAction,"SetMaintainIfSwitched")==0)
					{
						pSwitchList->bMaintainIfSwitched=(SndBool)((char*)szParams[1])[0];
					}
					break;
                case SCR_EA_Anl_EndSubSection:
                        // We have loaded a resource reference:
                        SCR_M_RdL0_GetSectionLong(0,0,tdstTypeSwitchMem *,pSwitchList);
                        SCR_M_RdL0_GetSectionLong(1,0,tdstSwitchElement *,pSwitchElement);
						// register resource reference in list:
                        SNDLST2_M_StaticAddTail( pSwitchList, pSwitchElement);
                        break;
        }
        return  SCR_ERV_Anl_NormalReturn;
}



//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadSwitchElementM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndSwitchElementM section (switch)
//					Fills a SwitchElement struct with its data from script
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/



SCR_tde_Anl_ReturnValue SND_fn_eLoadSwitchElementM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	SCR_tdst_Cxt_Values *pScriptContext;
    tdstSwitchElement *pSwitchElement;
    tdstBlockResourceMem *pResMem;
	char szTemp[260];

    switch (cType)
    {
    case SCR_EA_Anl_BeginSection:
        pSwitchElement=SND_fn_pCreateSwitchElementM();
        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pSwitchElement);
        break;
    case SCR_EA_Anl_Entry:
        SCR_M_RdL0_GetSectionLong(0,0,tdstSwitchElement *,pSwitchElement);
		if (strcmp(szAction,"LoadResource")==0)
        {
            // get pointer to referenced resource: 
			if (SCR_fn_uc_RdL0_GetNumberOfParameters(szParams)==1) // A VIRER
				pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0],SCR_CDF_uw_Anl_Normal);
			else pScriptContext=((SCR_tdst_Cxt_Values**)szParams[1])[0];
            pResMem=(tdstBlockResourceMem*)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext, 0);
			// register pointer in track:
            pSwitchElement->uRes.pstPtr=pResMem;
        }
        else if (strcmp(szAction,"SetInfoValue")==0)
        {
			pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal);
			pSwitchElement->hIndice=(SND_tdxHandleToSoundInfo)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext,0);
        }
		else if (strcmp(szAction,"SoundInfoValue")==0)
		{
			sprintf(szTemp,"%s.sif^%s",SND_fn_czGetProjectTitle(),szParams[0]);
			pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szTemp, SCR_CDF_uw_Anl_Normal);
			pSwitchElement->hIndice=(SND_tdxHandleToSoundInfo)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext,0);
		}
	}
    return  SCR_ERV_Anl_NormalReturn;
}

//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadRandomListM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndRandomListM section (RANDOM)
//					
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 11/03/98            Author : Stéphane RONSE
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/

SCR_tde_Anl_ReturnValue SND_fn_eLoadRandomListM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
        tdstBlockResourceMem *pResMem;
        tdstTypeRandomMem* pRandomList;
        tdstRandomElement *pRandomElement;

        switch (cType)
        {
                case SCR_EA_Anl_BeginSection:
                        // Not ACP_Compliant, but works: get RefRes* from Anchor BRMem:
                        SCR_M_RdL0_GetSectionLong(-1,0,tdstBlockResourceMem *,pResMem);
						pRandomList=&(pResMem->uRes.stRandom);
                        SNDLST2_M_StaticInitAnchor(pRandomList);
						pRandomList->rProbNothing=0;
						pRandomList->bNothingCanBeChosenTwice=TRUE;
                        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pRandomList);
                        break;
                case SCR_EA_Anl_Entry:
						break;
                case SCR_EA_Anl_EndSubSection:
                        // We have loaded a resource reference:
                        SCR_M_RdL0_GetSectionLong(0,0,tdstTypeRandomMem *,pRandomList);
                        SCR_M_RdL0_GetSectionLong(1,0,tdstRandomElement *,pRandomElement);
						// register resource reference in list:
                        SNDLST2_M_StaticAddTail( pRandomList, pRandomElement);
                        break;
        }
        return  SCR_ERV_Anl_NormalReturn;
}



//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadRandomElementM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndRandomElementM section (RANDOM)
//					Fills a RandomElement struct with its data from script
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Stéphane RONSE
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/



SCR_tde_Anl_ReturnValue SND_fn_eLoadRandomElementM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	SCR_tdst_Cxt_Values *pScriptContext;
    tdstRandomElement *pRandomElement;
    tdstBlockResourceMem *pResMem;

    switch (cType)
    {
    case SCR_EA_Anl_BeginSection:
        pRandomElement=SND_fn_pCreateRandomElementM();
        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pRandomElement);
        break;
    case SCR_EA_Anl_Entry:
        SCR_M_RdL0_GetSectionLong(0,0,tdstRandomElement *,pRandomElement);
		if (strcmp(szAction,"LoadResource")==0)
        {
            // get pointer to referenced resource: 
			if (SCR_fn_uc_RdL0_GetNumberOfParameters(szParams)==1) // A VIRER
				pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0],SCR_CDF_uw_Anl_Normal);
			else pScriptContext=((SCR_tdst_Cxt_Values**)szParams[1])[0];
            pResMem=(tdstBlockResourceMem*)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext, 0);
			// register pointer in track:
            pRandomElement->uRes.pstPtr=pResMem;
        }
        else if (strcmp(szAction,"SetProbability")==0)
        {
			pRandomElement->rProb=M_DoubleToRealSnd(SCRIPT_DOUBLE(szParams[0]));
        }
        else if (strcmp(szAction,"SetElementCanBeChoosenTwice")==0)
        {
			pRandomElement->bCanBeChosenTwice=(SndBool)((char*)szParams[1])[0];
        }
	}
    return  SCR_ERV_Anl_NormalReturn;
}

//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadThemePartOutroM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndThemePartOutroM section 
//					its only function is to update the part's pointer:
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/11/98            Author : Stephane RONSE
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/

SCR_tde_Anl_ReturnValue SND_fn_eLoadThemePartOutroM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
    tdstBlockResourceMem    *pResMem;
    tdstThemePartOutro      *pPart;
	SCR_tdst_Cxt_Values* pScriptContext;
    tdstTypeThemeMem           *pTheme;
        
    switch (cType)
    {
    case SCR_EA_Anl_BeginSection:
		SCR_M_RdL0_GetSectionLong(-1,0,tdstBlockResourceMem *,pResMem);
		pTheme=&(pResMem->uRes.stTheme);

        pPart=SND_fn_pCreateThemePartOutro();
        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pPart);

		pTheme->pstPartOutro=pPart;
        break;
    case SCR_EA_Anl_Entry:
		SCR_M_RdL0_GetSectionLong(0,0,tdstThemePartOutro *,pPart);

		if (strcmp(szAction,"SetFadeDuration")==0)
			pPart->rFadeDuration=M_DoubleToRealSnd(SCRIPT_DOUBLE(szParams[0]));
		else if (strcmp(szAction,"SetTransitionType")==0)
		{
			if (!strcmp(szParams[0],"TRANSITION_CROSSFADE"))
				pPart->eTransition=TRANSITION_CROSSFADE;
			else if (!strcmp(szParams[0],"TRANSITION_ATENDOFPART"))
				pPart->eTransition=TRANSITION_ATENDOFPART;
			else if (!strcmp(szParams[0],"TRANSITION_OUTRO"))
				pPart->eTransition=TRANSITION_OUTRO;
		}
		else if (strcmp(szAction,"LoadResource")==0)
		{
			if (SCR_fn_uc_RdL0_GetNumberOfParameters(szParams)==1) // A VIRER
				pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0],SCR_CDF_uw_Anl_Normal);
			else pScriptContext=((SCR_tdst_Cxt_Values**)szParams[1])[0];
			pResMem=(tdstBlockResourceMem*)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext, 0);
			pPart->uRes.pstPtr=pResMem;
		}
		break;
    }
    return  SCR_ERV_Anl_NormalReturn;
}

//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadThemePartListM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndThemePartListM section 
//					its only function is to update the part's pointer:
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/

SCR_tde_Anl_ReturnValue SND_fn_eLoadThemePartListM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
        tdstBlockResourceMem    *pResMem;
        tdstThemePart           *pPart;
        tdstTypeThemeMem           *pTheme;
            
        switch (cType)
        {
                case SCR_EA_Anl_BeginSection:
                        SCR_M_RdL0_GetSectionLong(-1,0,tdstBlockResourceMem *,pResMem);
						pTheme=&(pResMem->uRes.stTheme);
                        SNDLST2_M_StaticInitAnchor(pTheme);
                        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pTheme);
                        break;
                case SCR_EA_Anl_EndSubSection:
                        SCR_M_RdL0_GetSectionLong(0,0,tdstTypeThemeMem *,pTheme);
                        SCR_M_RdL0_GetSectionLong(1,0,tdstThemePart *,pPart);
						SNDLST2_M_StaticAddTail(pTheme,pPart);
						
						pTheme->ulNbParts=SNDLST2_M_StaticGetNumberOfElements(pTheme);

                        break;
        }
        return  SCR_ERV_Anl_NormalReturn;
}

//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadThemePartM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndThemePartM section 
//					Fills a part struct with its corresponding res pointer
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------*/

SCR_tde_Anl_ReturnValue SND_fn_eLoadThemePartM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
    tdstBlockResourceMem    *pResMem;
    tdstThemePart           *pPart;
	SCR_tdst_Cxt_Values* pScriptContext;
        
    switch (cType)
    {
    case SCR_EA_Anl_BeginSection:
        pPart=SND_fn_pCreateThemePart();
        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pPart);
        break;
    case SCR_EA_Anl_Entry:
		SCR_M_RdL0_GetSectionLong(0,0,tdstThemePart *,pPart);

		if (strcmp(szAction,"SetStartLoop")==0)
			pPart->bLoopStart=(SndBool)((char*)szParams[1])[0];
		else if (strcmp(szAction,"SetEndLoop")==0)
			pPart->bLoopEnd=(SndBool)((char*)szParams[1])[0];
		else if (strcmp(szAction,"SetNumberOfLoops")==0)
			pPart->lNbLoops=atoi(szParams[0]);
		else if (strcmp(szAction,"SetFadeDuration")==0)
			pPart->rFadeDuration=M_DoubleToRealSnd(SCRIPT_DOUBLE(szParams[0]));
		else if (strcmp(szAction,"SetTransitionType")==0)
		{
			if (!strcmp(szParams[0],"TRANSITION_CROSSFADE"))
				pPart->eTransition=TRANSITION_CROSSFADE;
			else if (!strcmp(szParams[0],"TRANSITION_ATENDOFPART"))
				pPart->eTransition=TRANSITION_ATENDOFPART;
			else if (!strcmp(szParams[0],"TRANSITION_OUTRO"))
				pPart->eTransition=TRANSITION_OUTRO;
		}
		else if (strcmp(szAction,"LoadResource")==0)
		{
			if (SCR_fn_uc_RdL0_GetNumberOfParameters(szParams)==1) // A VIRER
				pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(szParams[0],SCR_CDF_uw_Anl_Normal);
			else pScriptContext=((SCR_tdst_Cxt_Values**)szParams[1])[0];
			pResMem=(tdstBlockResourceMem*)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext, 0);
			pPart->uRes.pstPtr=pResMem;
		}
		break;
    }
    return  SCR_ERV_Anl_NormalReturn;
}








//***************************************************************************
//***************************************************************************
//*																			*
//*																			*
//*						SCRIPT CALLBACKS : EVENTS			 				*
//*																			*
//*																			*
//***************************************************************************
//***************************************************************************


//-----------------------------------------------------------------------------
//  Name : SND_fn_eLoadEventM
//-----------------------------------------------------------------------------
//  Description :   Script Callback for  SndEventM section. 
//					If the event is in a sound bank,return its pointer,
//					or NULL if the bank is not loaded,
//					If the event is in no sound bank, load it from script,
//					and load referenced events and resources.					
//-----------------------------------------------------------------------------
//  Input :  usual script callback input params        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//------------------------------------------------------------------------------


SCR_tde_Anl_ReturnValue SND_fn_eLoadEventM(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	static unsigned long ulNextEventBinId=0;
    SND_tdstBlockEvent *pEvent;
    unsigned long ulEvtId;

	switch (cType)
    {
	case SCR_EA_Anl_BeginSection:
		// create event:
        pEvent=SND_fn_pCreateEventM();
        SCR_M_RdL0_SetSectionLong(0,0,(unsigned long)pEvent);

		// Get event type:
		pEvent->eType=SND_fn_eGetEventTypeFromString(szParams[0]);

		ulEvtId=atoi(szAction);
		pEvent->Id=ulEvtId;
		SCR_M_RdL0_SetSectionLong(0,1,ulEvtId);

		break;
	case SCR_EA_Anl_Entry:
		SCR_M_RdL0_GetSectionLong(0,0,SND_tdstBlockEvent *,pEvent);

		if (strcmp(szAction,"SetStopable")==0)  
			pEvent->bStopable=(SndBool)(*szParams[1]);

		else if (strcmp(szAction,"SetDynamic")==0)  
			pEvent->bDynamic=(SndBool)(*szParams[1]);

		else
		{
			switch (pEvent->eType)
			{
			case EVT_SON_PLAY: 
				 SND_fn_vAnalyseEventParamsPlay(szAction,szParams,pEvent);
				break;
			case EVT_SON_STOP:
				 SND_fn_vAnalyseEventParamsStop(szAction,szParams,pEvent);
				break;
			case EVT_SON_STOP_N_GO:
				 SND_fn_vAnalyseEventParamsStopNGo(szAction,szParams,pEvent);
					break;
			case EVT_SON_STOP_N_GO_CROSSFADE:
				 SND_fn_vAnalyseEventParamsStopNGoFade(szAction,szParams,pEvent);
					break;
			case EVT_SON_PITCH:
			case EVT_SON_VOLUME:
			case EVT_SON_PAN:
				 SND_fn_vAnalyseEventParamsXtraParam(szAction,szParams,pEvent);
					break;
			case EVT_SON_EXTRA:
				 SND_fn_vAnalyseEventParamsExtraAll(szAction,szParams,pEvent);
					break;
			case EVT_SON_CHANGE_VOLUME:
				 SND_fn_vAnalyseEventChangeVolume(szAction,szParams,pEvent);
					break;
			case EVT_SON_EFFET:
				 SND_fn_vAnalyseEventParamsEffect(szAction,szParams,pEvent);
					break;
			}
		}
    }        // end switch (cType)
    return  SCR_ERV_Anl_NormalReturn;
}





//***************************************************************************
//***************************************************************************
//*																			*
//*																			*
//*						SCRIPT INIT FUNCTIONS				 				*
//*																			*
//*																			*
//***************************************************************************
//***************************************************************************


void SND_fn_vInitScriptSnd(void)
{
	tdstResTypeFunctions stTypeFunctions;

 	// Initialize script callbacks:
    SCR_fn_v_RdL0_RegisterCallback("SndResourceDisk",SND_fn_eLoadResDisk,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndEventM",SND_fn_eLoadEventM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndResourceM",SND_fn_eLoadResM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndTrackListM",SND_fn_eLoadPolyTrackM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndTrackM",SND_fn_eLoadTrackM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndSplitRangeListM",SND_fn_eLoadPolyRangeM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndSplitRangeM",SND_fn_eLoadRangeM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndSwitchListM",SND_fn_eLoadSwitchListM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndSwitchElementM",SND_fn_eLoadSwitchElementM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndRandomListM",SND_fn_eLoadRandomListM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndRandomElementM",SND_fn_eLoadRandomElementM,SCR_CRC_c_RdL0_ForSection);
    
    SCR_fn_v_RdL0_RegisterCallback("SndThemePartListM",SND_fn_eLoadThemePartListM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndThemePartOutroM",SND_fn_eLoadThemePartOutroM,SCR_CRC_c_RdL0_ForSection);
    SCR_fn_v_RdL0_RegisterCallback("SndThemePartM",SND_fn_eLoadThemePartM,SCR_CRC_c_RdL0_ForSection);



	SND_fn_vInitResTypeList();

	stTypeFunctions.m_pBRDiskInit=NULL;
	stTypeFunctions.m_pBRMemInit=NULL;

	// type sample:
	stTypeFunctions.m_iResTypeId=TYPE_SAMPLE;
	stTypeFunctions.m_pAnalyseEntry=SND_fn_vAnalyseScriptEntryForResSample;
	SND_fn_vAddResType(&stTypeFunctions);

	// type midi:
	stTypeFunctions.m_iResTypeId=TYPE_MIDI;
	stTypeFunctions.m_pAnalyseEntry=SND_fn_vAnalyseScriptEntryForResMidi;
	SND_fn_vAddResType(&stTypeFunctions);

	// type cd:
	stTypeFunctions.m_iResTypeId=TYPE_CDAUDIO;
	stTypeFunctions.m_pAnalyseEntry=SND_fn_vAnalyseScriptEntryForResCd;
	SND_fn_vAddResType(&stTypeFunctions);

	// type switch:
	stTypeFunctions.m_iResTypeId=TYPE_SWITCH;
	stTypeFunctions.m_pAnalyseEntry=SND_fn_vAnalyseScriptEntryForResSwitch;
	SND_fn_vAddResType(&stTypeFunctions);

	// type random:
	stTypeFunctions.m_iResTypeId=TYPE_RANDOM;
	stTypeFunctions.m_pAnalyseEntry=SND_fn_vAnalyseScriptEntryForResRandom;
	SND_fn_vAddResType(&stTypeFunctions);

	// type sequence:
	stTypeFunctions.m_iResTypeId=TYPE_SEQUENCE;
	stTypeFunctions.m_pAnalyseEntry=SND_fn_vAnalyseScriptEntryForResSequence;
	SND_fn_vAddResType(&stTypeFunctions);

	// type split:
	stTypeFunctions.m_iResTypeId=TYPE_SPLIT;
	stTypeFunctions.m_pAnalyseEntry=SND_fn_vAnalyseScriptEntryForResSplit;
	SND_fn_vAddResType(&stTypeFunctions);

	// type theme:
	stTypeFunctions.m_iResTypeId=TYPE_THEME;
	stTypeFunctions.m_pAnalyseEntry=SND_fn_vAnalyseScriptEntryForResTheme;
	SND_fn_vAddResType(&stTypeFunctions);

}



void SND_fn_vDesInitScriptSnd(void)
{
	SND_fn_vDesInitResTypeList();

}


//-----------------------------------------------------------------------------
//  Name : SND_fn_bInitDataLoadSnd
//-----------------------------------------------------------------------------
//  Description :   Hybrid initialization based on the lcb file: 
//					required to store the project name,in order to find the sif name.
//-----------------------------------------------------------------------------
//  Input :  const char * : project file title ( without extension).        
//  Output : SCR_tde_Anl_ReturnValue    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//-----------------------------------------------------------------------------

char g_czProjectTitle[MAX_PATH]="";

SndBool SND_fn_bInitDataLoadSnd(const char *_szFileTitle)
{
	strcpy(g_czProjectTitle,_szFileTitle);

#if defined (SUPERVISATER) && defined(_DLL_COMPILATION_MODE)
	//Send theProjectTitle to the SuperVisater
	fn_vSetProjectTitleForSuperVisater(_szFileTitle);
#endif

	return TRUE;
}

//-----------------------------------------------------------------------------
//  Name : SND_fn_czGetProjectTitle(void)
//-----------------------------------------------------------------------------
//  Description :   Returns the title of a project, as set by the editor: 
//-----------------------------------------------------------------------------
//  Input :  void.        
//  Output : const char *    
//-----------------------------------------------------------------------------
//  Creation date : 04/02/98            Author : Frédéric Décréau
//-----------------------------------------------------------------------------
//  Modification date :                 Modification Author :
//  Modifications :
//-----------------------------------------------------------------------------


const char * SND_fn_czGetProjectTitle(void)
{
	return g_czProjectTitle;
}


//***************************************************************************
//***************************************************************************
//*																			*
//*																			*
//*						RESOURCE TYPE  FUNCTIONS							*
//*																			*
//*																			*
//***************************************************************************
//***************************************************************************


// These function manage a list of structure, one for each resource type.
// In each structure is the resource type id, and a series of functions for the 
// script load of the resources.




static tdstResTypeList g_stResTypeList;


void SND_fn_vInitResTypeList(void)
{
	SNDLST2_M_DynamicInitAnchor(&g_stResTypeList);
}

void SND_fn_vDesInitResTypeList(void)
{
	tdstResTypeFunctions *pFunctions,*pFunctionsNext;
	int i;

	SNDLST2_M_DynamicForEachMovingElementOf(&g_stResTypeList,pFunctions,pFunctionsNext,i)
	{
			SNDLST2_M_DynamicIsolate(pFunctions);
			GlobalFree(pFunctions);
	}
}


void SND_fn_vAddResType(tdstResTypeFunctions *_pResFunctions)
{       
	tdstResTypeFunctions *pFunctions;

	pFunctions=GlobalAlloc(GPTR,sizeof(tdstResTypeFunctions));
	memcpy(pFunctions,_pResFunctions,sizeof(tdstResTypeFunctions));
	SNDLST2_M_DynamicInitElement(pFunctions);
	SNDLST2_M_DynamicAddTail(&g_stResTypeList, pFunctions);
}

void SND_fn_vAnalyseScriptEntryForResType(int _iResTypeId,char *szAction, char *szParams[],tdstBlockResourceDisk *pResDisk)
{
	tdstResTypeFunctions *pFunctions;
	int i;

	SNDLST2_M_DynamicForEachElementOf(&g_stResTypeList,pFunctions,i)
	{
		if (pFunctions->m_iResTypeId==_iResTypeId)
		{
			if (pFunctions->m_pAnalyseEntry!=NULL)
				pFunctions->m_pAnalyseEntry(szAction,szParams,pResDisk);
			return;
		}
	}
}

void SND_fn_vInitBRMemForResType(int _iResTypeId,tdstBlockResourceMem *pResMem)
{
	tdstResTypeFunctions *pFunctions;
	int i;

	SNDLST2_M_DynamicForEachElementOf(&g_stResTypeList,pFunctions,i)
	{
		if (pFunctions->m_iResTypeId==_iResTypeId)
		{
			if (pFunctions->m_pBRMemInit!=NULL)
				pFunctions->m_pBRMemInit(pResMem);
			return;
		}
	}
}

void SND_fn_vInitBRDiskForResType(int _iResTypeId,tdstBlockResourceDisk *pResDisk)
{
	tdstResTypeFunctions *pFunctions;
	int i;

	SNDLST2_M_DynamicForEachElementOf(&g_stResTypeList,pFunctions,i)
	{
		if (pFunctions->m_iResTypeId==_iResTypeId)
		{
			pFunctions->m_pBRDiskInit(pResDisk);
			if (pFunctions->m_pBRDiskInit!=NULL)
				pFunctions->m_pBRDiskInit(pResDisk);
			return;
		}
	}
}


// Get ptr onto resource from ist editor-id
// return NULL when resource cannot be solved
tdstBlockResourceMem* SND_fn_pstGetResFromEdIdSnd(unsigned long ulEdId)
{
	char section[128];
	SCR_tdst_Cxt_Values* pScriptContext;

	//do check in SND_g_lListEdSectionResource
	fn_vGetSectionNameFromEdIdResource(ulEdId,section,sizeof(section));

	pScriptContext=SCR_fnp_st_RdL0_AnalyseSection(section,SCR_CDF_uw_Anl_Normal);
	return (tdstBlockResourceMem*)SCR_M_ul_RdL0_ExtractLongValue(pScriptContext, 0);
}




#endif 
//NO_ACP_SOUND*
