From 83450bedc8d881da31f9abc81af53c30c25a5f72 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 20 Apr 2013 10:39:24 -0700 Subject: [PATCH] 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. --- cmProc4.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 3 deletions(-) diff --git a/cmProc4.c b/cmProc4.c index 3a50bd9..815f3bf 100644 --- a/cmProc4.c +++ b/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; iobj, 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; iobj, 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; - }