cmProc4.c: _cmScModulatorParse() now allows values from previous entries to
be automatically applied to subsequent entries. New entries must therefore only fill in the fields which change.
This commit is contained in:
parent
14f163394d
commit
83450bedc8
165
cmProc4.c
165
cmProc4.c
@ -3499,7 +3499,7 @@ cmScModEntry_t* _cmScModulatorInsertEntry(cmScModulator* p, unsigned idx, unsign
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, const cmChar_t* fn )
|
||||
cmRC_t _cmScModulatorParse2( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, const cmChar_t* fn )
|
||||
{
|
||||
cmRC_t rc = cmOkRC;
|
||||
cmJsonNode_t* jnp = NULL;
|
||||
@ -3527,7 +3527,7 @@ cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, con
|
||||
|
||||
for(i=0; i<entryCnt; ++i)
|
||||
{
|
||||
cmJsRC_t jsRC;
|
||||
cmJsRC_t jsRC;
|
||||
const char* errLabelPtr = NULL;
|
||||
unsigned scLocIdx = cmInvalidIdx;
|
||||
const cmChar_t* modLabel = NULL;
|
||||
@ -3613,6 +3613,166 @@ cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, con
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, const cmChar_t* fn )
|
||||
{
|
||||
cmRC_t rc = cmOkRC;
|
||||
cmJsonNode_t* jnp = NULL;
|
||||
cmJsonH_t jsH = cmJsonNullHandle;
|
||||
unsigned i = cmInvalidIdx;
|
||||
unsigned j = cmInvalidIdx;
|
||||
|
||||
// read the JSON file
|
||||
if( cmJsonInitializeFromFile(&jsH, fn, ctx ) != kOkJsRC )
|
||||
return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "JSON file parse failed on the modulator file: %s.",cmStringNullGuard(fn) );
|
||||
|
||||
jnp = cmJsonRoot(jsH);
|
||||
|
||||
// validate that the first child as an array
|
||||
if( jnp==NULL || ((jnp = cmJsonNodeMemberValue(jnp,"array")) == NULL) || cmJsonIsArray(jnp)==false )
|
||||
{
|
||||
rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Modulator file header syntax error in file:%s",cmStringNullGuard(fn) );
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// allocate the entry array
|
||||
unsigned entryCnt = cmJsonChildCount(jnp);
|
||||
p->earray = cmMemResizeZ(cmScModEntry_t,p->earray,entryCnt);
|
||||
p->en = entryCnt;
|
||||
|
||||
unsigned prvScLocIdx = cmInvalidIdx;
|
||||
const cmChar_t* prvModLabel = NULL;
|
||||
const cmChar_t* prvVarLabel = NULL;
|
||||
const cmChar_t* prvTypeLabel = NULL;
|
||||
for(i=0; i<entryCnt; ++i)
|
||||
{
|
||||
cmJsRC_t jsRC;
|
||||
const char* errLabelPtr = NULL;
|
||||
unsigned scLocIdx = cmInvalidIdx;
|
||||
const cmChar_t* modLabel = NULL;
|
||||
const cmChar_t* varLabel = NULL;
|
||||
const cmChar_t* typeLabel = NULL;
|
||||
cmJsonNode_t* onp = cmJsonArrayElement(jnp,i);
|
||||
cmJsonNode_t* dnp = NULL;
|
||||
const _cmScModTypeMap_t* map = NULL;
|
||||
|
||||
if((jsRC = cmJsonMemberValues( onp, &errLabelPtr,
|
||||
"loc", kIntTId | kOptArgJsFl, &scLocIdx,
|
||||
"mod", kStringTId | kOptArgJsFl, &modLabel,
|
||||
"var", kStringTId | kOptArgJsFl, &varLabel,
|
||||
"type",kStringTId | kOptArgJsFl, &typeLabel,
|
||||
NULL )) != kOkJsRC )
|
||||
{
|
||||
if( errLabelPtr == NULL )
|
||||
rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Error:%s on record at index %i in file:%s",errLabelPtr,i,cmStringNullGuard(fn) );
|
||||
else
|
||||
rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Synax error in Modulator record at index %i in file:%s",i,cmStringNullGuard(fn) );
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// if the score location was not given use the previous score location
|
||||
if( scLocIdx == cmInvalidIdx )
|
||||
scLocIdx = prvScLocIdx;
|
||||
else
|
||||
prvScLocIdx = scLocIdx;
|
||||
|
||||
// if the mod label was not given use the previous one
|
||||
if( modLabel == NULL )
|
||||
modLabel = prvModLabel;
|
||||
else
|
||||
prvModLabel = modLabel;
|
||||
|
||||
if( modLabel == NULL )
|
||||
{
|
||||
rc = cmCtxRtCondition(&p->obj, cmInvalidArgRC, "No 'mod' label has been set in mod file '%s'.",cmStringNullGuard(fn));
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// if the var label was not given use the previous one
|
||||
if( varLabel == NULL )
|
||||
varLabel = prvVarLabel;
|
||||
else
|
||||
prvVarLabel = varLabel;
|
||||
|
||||
if( varLabel == NULL )
|
||||
{
|
||||
rc = cmCtxRtCondition(&p->obj, cmInvalidArgRC, "No 'var' label has been set in mod file '%s'.",cmStringNullGuard(fn));
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// if the type label was not given use the previous one
|
||||
if( typeLabel == NULL )
|
||||
typeLabel = prvTypeLabel;
|
||||
else
|
||||
prvTypeLabel = typeLabel;
|
||||
|
||||
if( typeLabel == NULL )
|
||||
{
|
||||
rc = cmCtxRtCondition(&p->obj, cmInvalidArgRC, "No 'type' label has been set in mod file '%s'.",cmStringNullGuard(fn));
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// validate the entry type label
|
||||
if((map = _cmScModTypeLabelToMap(typeLabel)) == NULL )
|
||||
{
|
||||
rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Unknown entry type '%s' in Modulator record at index %i in file:%s",cmStringNullGuard(typeLabel),i,cmStringNullGuard(fn) );
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
unsigned modSymId = cmSymTblRegisterSymbol(stH,modLabel);
|
||||
unsigned varSymId = cmSymTblRegisterSymbol(stH,varLabel);
|
||||
|
||||
// the mod entry label must match the modulators label
|
||||
if( p->modSymId != modSymId )
|
||||
{
|
||||
--p->en;
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the count of the elmenets in the data array
|
||||
unsigned paramCnt = cmJsonChildCount(onp);
|
||||
|
||||
// fill the entry record and find or create the target var
|
||||
cmScModEntry_t* ep = _cmScModulatorInsertEntry(p,i,scLocIdx,modSymId,varSymId,map->typeId,paramCnt);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const cmChar_t* label;
|
||||
cmScModParam_t* param;
|
||||
} map_t;
|
||||
|
||||
// parse the var and parameter records
|
||||
map_t mapArray[] =
|
||||
{
|
||||
{ "min", &ep->min },
|
||||
{ "max", &ep->max },
|
||||
{ "rate",&ep->rate },
|
||||
{ "val", &ep->beg },
|
||||
{ "end", &ep->end },
|
||||
{ "dur", &ep->dur },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
unsigned j=0;
|
||||
for(j=0; mapArray[j].param!=NULL; ++j)
|
||||
if((dnp = cmJsonFindValue(jsH,mapArray[j].label, onp, kInvalidTId )) != NULL )
|
||||
if((rc = _cmScModulatorParseParam(p,stH,dnp,mapArray[j].param)) != cmOkRC )
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
errLabel:
|
||||
|
||||
if( rc != cmOkRC )
|
||||
cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Error parsing in Modulator 'data' record at index %i value index %i in file:%s",i,j,cmStringNullGuard(fn) );
|
||||
|
||||
|
||||
// release the JSON tree
|
||||
if( cmJsonIsValid(jsH) )
|
||||
cmJsonFinalize(&jsH);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
cmRC_t _cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx )
|
||||
{
|
||||
cmRC_t rc = cmOkRC;
|
||||
@ -4029,5 +4189,4 @@ cmRC_t cmScModulatorDump( cmScModulator* p )
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user