Parcourir la source

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.
master
kevin il y a 11 ans
Parent
révision
83450bedc8
1 fichiers modifiés avec 162 ajouts et 3 suppressions
  1. 162
    3
      cmProc4.c

+ 162
- 3
cmProc4.c Voir le fichier

@@ -3499,7 +3499,7 @@ cmScModEntry_t* _cmScModulatorInsertEntry(cmScModulator* p, unsigned idx, unsign
3499 3499
   return rc;
3500 3500
 }
3501 3501
 
3502
-cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, const cmChar_t* fn )
3502
+cmRC_t _cmScModulatorParse2( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, const cmChar_t* fn )
3503 3503
 {
3504 3504
   cmRC_t        rc  = cmOkRC;
3505 3505
   cmJsonNode_t* jnp = NULL;
@@ -3527,7 +3527,7 @@ cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, con
3527 3527
 
3528 3528
   for(i=0; i<entryCnt; ++i)
3529 3529
   {
3530
-    cmJsRC_t                jsRC;
3530
+    cmJsRC_t                 jsRC;
3531 3531
     const char*              errLabelPtr = NULL;
3532 3532
     unsigned                 scLocIdx    = cmInvalidIdx;
3533 3533
     const cmChar_t*          modLabel    = NULL;
@@ -3613,6 +3613,166 @@ cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, con
3613 3613
   return rc;
3614 3614
 }
3615 3615
 
3616
+cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, const cmChar_t* fn )
3617
+{
3618
+  cmRC_t        rc  = cmOkRC;
3619
+  cmJsonNode_t* jnp = NULL;
3620
+  cmJsonH_t     jsH = cmJsonNullHandle;
3621
+  unsigned      i   = cmInvalidIdx;
3622
+  unsigned      j   = cmInvalidIdx;
3623
+
3624
+  // read the JSON file
3625
+  if( cmJsonInitializeFromFile(&jsH, fn, ctx ) != kOkJsRC )
3626
+    return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "JSON file parse failed on the modulator file: %s.",cmStringNullGuard(fn) );
3627
+
3628
+  jnp = cmJsonRoot(jsH);
3629
+
3630
+  // validate that the first child as an array
3631
+  if( jnp==NULL || ((jnp = cmJsonNodeMemberValue(jnp,"array")) == NULL) || cmJsonIsArray(jnp)==false )
3632
+  {
3633
+    rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Modulator file header syntax error in file:%s",cmStringNullGuard(fn) );
3634
+    goto errLabel;
3635
+  }
3636
+
3637
+  // allocate the entry array
3638
+  unsigned entryCnt = cmJsonChildCount(jnp);
3639
+  p->earray         = cmMemResizeZ(cmScModEntry_t,p->earray,entryCnt);
3640
+  p->en             = entryCnt;
3641
+
3642
+  unsigned        prvScLocIdx = cmInvalidIdx;
3643
+  const cmChar_t* prvModLabel   = NULL;
3644
+  const cmChar_t* prvVarLabel   = NULL;
3645
+  const cmChar_t* prvTypeLabel  = NULL;
3646
+  for(i=0; i<entryCnt; ++i)
3647
+  {
3648
+    cmJsRC_t                 jsRC;
3649
+    const char*              errLabelPtr = NULL;
3650
+    unsigned                 scLocIdx    = cmInvalidIdx;
3651
+    const cmChar_t*          modLabel    = NULL;
3652
+    const cmChar_t*          varLabel    = NULL;
3653
+    const cmChar_t*          typeLabel   = NULL;
3654
+    cmJsonNode_t*            onp         = cmJsonArrayElement(jnp,i);
3655
+    cmJsonNode_t*            dnp         = NULL;
3656
+    const _cmScModTypeMap_t* map         = NULL;
3657
+
3658
+    if((jsRC = cmJsonMemberValues( onp, &errLabelPtr, 
3659
+          "loc", kIntTId    | kOptArgJsFl, &scLocIdx,
3660
+          "mod", kStringTId | kOptArgJsFl, &modLabel,
3661
+          "var", kStringTId | kOptArgJsFl, &varLabel,
3662
+          "type",kStringTId | kOptArgJsFl, &typeLabel,
3663
+          NULL )) != kOkJsRC )
3664
+    {
3665
+      if( errLabelPtr == NULL )
3666
+        rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Error:%s on record at index %i in file:%s",errLabelPtr,i,cmStringNullGuard(fn) );
3667
+      else
3668
+        rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Synax error in Modulator record at index %i in file:%s",i,cmStringNullGuard(fn) );
3669
+      goto errLabel;
3670
+    }
3671
+
3672
+    // if the score location was not given use the previous score location
3673
+    if( scLocIdx == cmInvalidIdx )
3674
+      scLocIdx = prvScLocIdx;
3675
+    else
3676
+      prvScLocIdx = scLocIdx;
3677
+
3678
+    // if the mod label was not given use the previous one
3679
+    if( modLabel == NULL )
3680
+      modLabel = prvModLabel;
3681
+    else
3682
+      prvModLabel = modLabel;
3683
+
3684
+    if( modLabel == NULL )
3685
+    {
3686
+      rc = cmCtxRtCondition(&p->obj, cmInvalidArgRC, "No 'mod' label has been set in mod file '%s'.",cmStringNullGuard(fn));
3687
+      goto errLabel;
3688
+    }
3689
+
3690
+    // if the var label was not given use the previous one
3691
+    if( varLabel == NULL )
3692
+      varLabel = prvVarLabel;
3693
+    else
3694
+      prvVarLabel = varLabel;
3695
+
3696
+    if( varLabel == NULL )
3697
+    {
3698
+      rc = cmCtxRtCondition(&p->obj, cmInvalidArgRC, "No 'var' label has been set in mod file '%s'.",cmStringNullGuard(fn));
3699
+      goto errLabel;
3700
+    }
3701
+
3702
+    // if the type label was not given use the previous one 
3703
+    if( typeLabel == NULL )
3704
+      typeLabel = prvTypeLabel;
3705
+    else
3706
+      prvTypeLabel = typeLabel;
3707
+
3708
+    if( typeLabel == NULL )
3709
+    {
3710
+      rc = cmCtxRtCondition(&p->obj, cmInvalidArgRC, "No 'type' label has been set in mod file '%s'.",cmStringNullGuard(fn));
3711
+      goto errLabel;
3712
+    }
3713
+
3714
+    // validate the entry type label
3715
+    if((map = _cmScModTypeLabelToMap(typeLabel)) == NULL )
3716
+    {
3717
+      rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Unknown entry type '%s' in Modulator record at index %i in file:%s",cmStringNullGuard(typeLabel),i,cmStringNullGuard(fn) );
3718
+      goto errLabel;
3719
+    }
3720
+    
3721
+    unsigned modSymId = cmSymTblRegisterSymbol(stH,modLabel);
3722
+    unsigned varSymId = cmSymTblRegisterSymbol(stH,varLabel);
3723
+
3724
+    // the mod entry label must match the modulators label
3725
+    if( p->modSymId != modSymId )
3726
+    {
3727
+      --p->en;
3728
+        continue;
3729
+    } 
3730
+
3731
+    // get the count of the elmenets in the data array
3732
+    unsigned paramCnt = cmJsonChildCount(onp);
3733
+
3734
+    // fill the entry record and find or create the target var
3735
+    cmScModEntry_t* ep = _cmScModulatorInsertEntry(p,i,scLocIdx,modSymId,varSymId,map->typeId,paramCnt);
3736
+
3737
+    typedef struct
3738
+    {
3739
+      const cmChar_t* label;
3740
+      cmScModParam_t* param;
3741
+    } map_t;
3742
+
3743
+    // parse the var and parameter records
3744
+    map_t mapArray[] = 
3745
+    {
3746
+      { "min", &ep->min  },
3747
+      { "max", &ep->max  },
3748
+      { "rate",&ep->rate },
3749
+      { "val", &ep->beg },
3750
+      { "end", &ep->end },
3751
+      { "dur", &ep->dur },
3752
+      { NULL, NULL }
3753
+    };
3754
+
3755
+    unsigned j=0;
3756
+    for(j=0; mapArray[j].param!=NULL; ++j)
3757
+      if((dnp = cmJsonFindValue(jsH,mapArray[j].label, onp, kInvalidTId )) != NULL )
3758
+        if((rc = _cmScModulatorParseParam(p,stH,dnp,mapArray[j].param)) != cmOkRC )
3759
+          goto errLabel;    
3760
+  }
3761
+
3762
+ errLabel:
3763
+
3764
+  if( rc != cmOkRC )
3765
+    cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Error parsing in Modulator 'data' record at index %i value index %i in file:%s",i,j,cmStringNullGuard(fn) );    
3766
+
3767
+
3768
+  // release the JSON tree
3769
+  if( cmJsonIsValid(jsH) )
3770
+    cmJsonFinalize(&jsH);
3771
+
3772
+  return rc;
3773
+}
3774
+
3775
+
3616 3776
 cmRC_t  _cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx )
3617 3777
 {
3618 3778
   cmRC_t rc = cmOkRC;
@@ -4029,5 +4189,4 @@ cmRC_t  cmScModulatorDump(  cmScModulator* p )
4029 4189
   }
4030 4190
   
4031 4191
   return rc;
4032
-
4033 4192
 }

Chargement…
Annuler
Enregistrer