Browse Source

cmProc4.h/c, cmDspKr.c : Changed cmScModulator to use entry groups rather than a single entry list.

master
kevin 8 years ago
parent
commit
7ff73452e2
3 changed files with 150 additions and 269 deletions
  1. 141
    258
      cmProc4.c
  2. 5
    10
      cmProc4.h
  3. 4
    1
      dsp/cmDspKr.c

+ 141
- 258
cmProc4.c View File

@@ -2686,8 +2686,8 @@ cmRC_t cmScModulatorFree(  cmScModulator** pp )
2686 2686
   if((rc = cmScModulatorFinal(p)) != cmOkRC )
2687 2687
     return rc;
2688 2688
 
2689
-  cmMemFree(p->earray);
2690
-  cmMemFree(p->xlist);
2689
+  //cmMemFree(p->earray);
2690
+  //cmMemFree(p->xlist);
2691 2691
   cmObjFree(pp);
2692 2692
   return rc;
2693 2693
 }
@@ -2743,6 +2743,7 @@ cmScModVar_t* _cmScModulatorInsertVar( cmScModulator* p, unsigned varSymId, unsi
2743 2743
 {
2744 2744
   cmScModVar_t* vp = _cmScModSymToVar(p,varSymId);
2745 2745
 
2746
+  // if the specified variable was not found then create one
2746 2747
   if( vp == NULL )
2747 2748
   {
2748 2749
     vp = cmMemAllocZ(cmScModVar_t,1);
@@ -2764,19 +2765,18 @@ cmScModVar_t* _cmScModulatorInsertVar( cmScModulator* p, unsigned varSymId, unsi
2764 2765
   return vp;
2765 2766
 }
2766 2767
 
2767
-cmScModEntry_t* _cmScModulatorInsertEntry(cmScModulator* p, unsigned idx, unsigned scLocIdx, unsigned modSymId, unsigned varSymId, unsigned typeId, unsigned entryFlags, unsigned paramCnt )
2768
+cmScModEntry_t* _cmScModulatorInsertEntry(cmScModulator* p, cmScModEntryGroup_t* g, unsigned idx, unsigned scLocIdx, unsigned varSymId, unsigned typeId, unsigned paramCnt )
2768 2769
 {
2769
-  assert( idx < p->en );
2770
+  assert( idx < g->en );
2770 2771
 
2771
-  p->earray[idx].scLocIdx = scLocIdx;
2772
-  p->earray[idx].typeId   = typeId;
2773
-  p->earray[idx].varPtr   = _cmScModulatorInsertVar(p,varSymId,0);
2774
-  p->earray[idx].flags    = entryFlags;
2772
+  g->earray[idx].scLocIdx = scLocIdx;
2773
+  g->earray[idx].typeId   = typeId;
2774
+  g->earray[idx].varPtr   = _cmScModulatorInsertVar(p,varSymId,0);
2775 2775
 
2776
-  if( p->earray[idx].varPtr->outVarId == cmInvalidIdx )
2777
-    p->earray[idx].varPtr->outVarId = p->outVarCnt++;
2776
+  if( g->earray[idx].varPtr->outVarId == cmInvalidIdx )
2777
+    g->earray[idx].varPtr->outVarId = p->outVarCnt++;
2778 2778
 
2779
-  return p->earray + idx;
2779
+  return g->earray + idx;
2780 2780
 }
2781 2781
 
2782 2782
 
@@ -2792,7 +2792,7 @@ cmScModEntry_t* _cmScModulatorInsertEntry(cmScModulator* p, unsigned idx, unsign
2792 2792
  // A parameter value may be either a symbol identifier (mapped to a variable)
2793 2793
  // or a literal number.  This function determines which form the paramter
2794 2794
  // value takes and parses it accordingly.
2795
-  cmRC_t _cmScModulatorParseParam( cmScModulator* p, cmSymTblH_t stH, cmJsonNode_t* np, cmScModParam_t* pp )
2795
+cmRC_t _cmScModulatorParseParam( cmScModulator* p, cmSymTblH_t stH, cmJsonNode_t* np, cmScModParam_t* pp )
2796 2796
 {
2797 2797
   cmRC_t rc = cmOkRC;
2798 2798
 
@@ -2833,169 +2833,36 @@ cmScModEntry_t* _cmScModulatorInsertEntry(cmScModulator* p, unsigned idx, unsign
2833 2833
 }
2834 2834
 
2835 2835
 
2836
-void _cmScProcessEntryGroups( cmScModulator* p )
2836
+cmRC_t _cmScModParseEntryGroup( cmScModulator* p, cmCtx_t* ctx, cmJsonH_t jsH, cmSymTblH_t stH, cmJsonNode_t* jnp, cmScModEntryGroup_t* g, const cmChar_t* fn )
2837 2837
 {
2838
-  unsigned i=0;
2839
-
2840
-  cmScModEntryGroup_t* g0 = NULL;
2841
-  cmScModEntryGroup_t* g1 = p->glist;
2838
+  cmRC_t          rc            = cmOkRC;
2839
+  unsigned        prvScLocIdx   = cmInvalidIdx;
2840
+  const cmChar_t* prvVarLabel   = "<dummy>";
2841
+  const cmChar_t* prvTypeLabel  = NULL;
2842
+  unsigned        i;
2842 2843
   
2843
-  while( i<p->en )
2844
-  {
2845
-    // if this is the first entry in a group
2846
-    if( cmIsFlag(p->earray[i].flags , kLocLabelEntryFl ) )
2847
-    {
2848
-      // if no group record is avaiable ...
2849
-      if( g1 == NULL )
2850
-      {
2851
-        // ... then allocate one and ...
2852
-        g1 = cmMemAllocZ(cmScModEntryGroup_t,1);
2853
-
2854
-        // ... link it to the end of the group list
2855
-        if( g0 == NULL )
2856
-          p->glist = g1;
2857
-        else
2858
-          g0->link = g1;
2859
-                
2860
-      }
2861
-
2862
-      unsigned j;
2863
-
2864
-      g1->n = 0;
2865
-      
2866
-      // get a count of the entries in this group
2867
-      while( i<p->en && p->earray[i+g1->n].scLocIdx == p->earray[i].scLocIdx )
2868
-        g1->n += 1;
2869 2844
       
2870
-      // allocate an array to hold the group
2871
-      g1->base = cmMemResizeZ(cmScModEntry_t*,g1->base,g1->n);
2872
-
2873
-      for(j=0; j<g1->n; ++j)
2874
-        g1->base[j] = p->earray + i + j;
2875
-
2876
-      i += g1->n;
2877
-
2878
-      // make the next group record available
2879
-      g0 = g1;
2880
-      g1 = g1->link;
2881
-
2882
-
2883
-
2884
-    }
2885
-    else
2886
-    {
2887
-      i += 1;
2888
-    }
2889
-  }
2890
-
2891
-  // set successive records as invalid
2892
-  for(; g1 != NULL; g1=g1->link)
2893
-    g1->base = NULL;
2894
-
2895
-}
2896
-
2897
-void _cmScProcessExecList( cmScModulator* p )
2898
-{
2899
-  unsigned i,j;
2900
-  unsigned n = 0;
2901
-  for(i=0; i<p->en; ++i)
2902
-    if( cmIsNotFlag(p->earray[i].flags,kLocLabelEntryFl) )
2903
-      n += 1;
2904
-
2905
-  p->xlist = cmMemResizeZ(cmScModEntry_t*,p->xlist,n);
2906
-  p->xn    = n;
2907
-
2908
-  
2909
-  for(i=0,j=0; i<p->en; ++i)
2910
-    if( cmIsNotFlag(p->earray[i].flags,kLocLabelEntryFl) )
2911
-      p->xlist[j++] = p->earray + i;
2912
-  
2913
-  assert( j == p->xn );
2914
-}
2915
-
2916
-cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, const cmChar_t* fn )
2917
-{
2918
-  cmRC_t        rc  = cmOkRC;
2919
-  cmJsonNode_t* jnp = NULL;
2920
-  cmJsonH_t     jsH = cmJsonNullHandle;
2921
-  unsigned      i   = cmInvalidIdx;
2922
-  unsigned      j   = cmInvalidIdx;
2923
-
2924
-  // read the JSON file
2925
-  if( cmJsonInitializeFromFile(&jsH, fn, ctx ) != kOkJsRC )
2926
-    return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "JSON file parse failed on the modulator file: %s.",cmStringNullGuard(fn) );
2927
-
2928
-  jnp = cmJsonRoot(jsH);
2929
-
2930
-  // validate that the first child as an array
2931
-  if( jnp==NULL || ((jnp = cmJsonNodeMemberValue(jnp,"array")) == NULL) || cmJsonIsArray(jnp)==false )
2932
-  {
2933
-    rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Modulator file header syntax error in file:%s",cmStringNullGuard(fn) );
2934
-    goto errLabel;
2935
-  }
2936
-
2937 2845
   // allocate the entry array
2938 2846
   unsigned entryCnt = cmJsonChildCount(jnp);
2939
-  p->earray         = cmMemResizeZ(cmScModEntry_t,p->earray,entryCnt);
2940
-  p->en             = entryCnt;
2847
+  g->earray         = cmMemResizeZ(cmScModEntry_t,g->earray,entryCnt);
2848
+  g->en             = entryCnt;
2941 2849
 
2942
-  unsigned        prvScLocIdx   = cmInvalidIdx;
2943
-  const cmChar_t* prvModLabel   = NULL;
2944
-  const cmChar_t* prvVarLabel   = NULL;
2945
-  const cmChar_t* prvTypeLabel  = NULL;
2946
-  unsigned        prvEntryFlags = 0;
2947
-  
2948 2850
   for(i=0; i<entryCnt; ++i)
2949 2851
   {
2950 2852
     cmJsRC_t                 jsRC        = kOkJsRC;
2951 2853
     const char*              errLabelPtr = NULL;
2952 2854
     unsigned                 scLocIdx    = cmInvalidIdx;
2953
-    const cmChar_t*          modLabel    = NULL;
2954 2855
     const cmChar_t*          varLabel    = NULL;
2955 2856
     const cmChar_t*          typeLabel   = NULL;
2956 2857
     cmJsonNode_t*            onp         = cmJsonArrayElement(jnp,i);
2957 2858
     cmJsonNode_t*            dnp         = NULL;
2958 2859
     const _cmScModTypeMap_t* map         = NULL;
2959
-    unsigned                 locTypeId   = kIntTId;
2960
-    unsigned                 entryFlags  = cmInvalidId;
2961
-
2962
-    // if a 'loc' field was specified for this label
2963
-    if( cmJsonFindPair( onp, "loc" ) != NULL )
2964
-    {
2965
-      const cmChar_t*  locLabel = NULL;
2966
-
2967
-      // get the type of the 'loc' value field
2968
-      if( cmJsonMemberType(onp, "loc", &locTypeId) == kOkJsRC )
2969
-      {
2970
-        // read the 'loc' value field
2971
-        if( locTypeId == kStringTId )
2972
-          rc         = cmJsonStringMember( onp, "loc", &locLabel );
2973
-        else
2974
-          rc       = cmJsonUIntMember( onp, "loc", &scLocIdx);
2975
-        
2976
-      }
2977
-
2978
-      // check for parsing errors
2979
-      if( rc != kOkJsRC )
2980
-      {
2981
-        rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Error:Reading 'loc' field on record at index %i in file:%s",i,cmStringNullGuard(fn) );
2982
-        goto errLabel;
2983
-      }
2984
-
2985
-      // if a label was given then convert it to a symbol id
2986
-      if( locLabel != NULL )
2987
-      {
2988
-        scLocIdx   = cmSymTblRegisterSymbol(stH,locLabel);
2989
-        entryFlags = kLocLabelEntryFl; 
2990
-      }
2991
-      
2992
-    }
2860
+    
2993 2861
 
2994
-          
2995 2862
     if((jsRC = cmJsonMemberValues( onp, &errLabelPtr,
2996
-          "mod", kStringTId | kOptArgJsFl, &modLabel,
2997 2863
           "var", kStringTId | kOptArgJsFl, &varLabel,
2998 2864
           "type",kStringTId | kOptArgJsFl, &typeLabel,
2865
+          "loc", kIntTId    | kOptArgJsFl, &scLocIdx,
2999 2866
           NULL )) != kOkJsRC )
3000 2867
     {
3001 2868
       if( errLabelPtr == NULL )
@@ -3011,24 +2878,6 @@ cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, con
3011 2878
     else
3012 2879
       prvScLocIdx = scLocIdx;
3013 2880
 
3014
-    // if the flags field was not specified
3015
-    if( entryFlags == cmInvalidId )
3016
-      entryFlags = prvEntryFlags;
3017
-    else
3018
-      prvEntryFlags = entryFlags;
3019
-
3020
-    // if the mod label was not given use the previous one
3021
-    if( modLabel == NULL )
3022
-      modLabel = prvModLabel;
3023
-    else
3024
-      prvModLabel = modLabel;
3025
-
3026
-    if( modLabel == NULL )
3027
-    {
3028
-      rc = cmCtxRtCondition(&p->obj, cmInvalidArgRC, "No 'mod' label has been set in mod file '%s'.",cmStringNullGuard(fn));
3029
-      goto errLabel;
3030
-    }
3031
-
3032 2881
     // if the var label was not given use the previous one
3033 2882
     if( varLabel == NULL )
3034 2883
       varLabel = prvVarLabel;
@@ -3060,21 +2909,13 @@ cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, con
3060 2909
       goto errLabel;
3061 2910
     }
3062 2911
     
3063
-    unsigned modSymId = cmSymTblRegisterSymbol(stH,modLabel);
3064 2912
     unsigned varSymId = cmSymTblRegisterSymbol(stH,varLabel);
3065 2913
 
3066
-    // the mod entry label must match the modulators label
3067
-    if( p->modSymId != modSymId )
3068
-    {
3069
-      --p->en;
3070
-        continue;
3071
-    } 
3072
-
3073 2914
     // get the count of the elmenets in the data array
3074 2915
     unsigned paramCnt = cmJsonChildCount(onp);
3075 2916
 
3076 2917
     // fill the entry record and find or create the target var
3077
-    cmScModEntry_t* ep = _cmScModulatorInsertEntry(p,i,scLocIdx,modSymId,varSymId,map->typeId,entryFlags,paramCnt);
2918
+    cmScModEntry_t* ep = _cmScModulatorInsertEntry(p,g,i,scLocIdx,varSymId,map->typeId,paramCnt);
3078 2919
 
3079 2920
     typedef struct
3080 2921
     {
@@ -3103,10 +2944,68 @@ cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, con
3103 2944
 
3104 2945
  errLabel:
3105 2946
 
3106
-  if( rc != cmOkRC )
3107
-    cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Error parsing in Modulator 'data' record at index %i value index %i in file:%s",i,j,cmStringNullGuard(fn) );    
2947
+  return rc;
2948
+}
3108 2949
 
2950
+cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, const cmChar_t* fn )
2951
+{
2952
+  cmRC_t               rc  = cmOkRC;
2953
+  cmJsonNode_t*        jnp = NULL;
2954
+  cmJsonH_t            jsH = cmJsonNullHandle;
2955
+  unsigned             i   = cmInvalidIdx;
2956
+  cmScModEntryGroup_t* g0  = NULL;
2957
+  cmScModEntryGroup_t* g1  = p->glist;
2958
+
2959
+  // read the JSON file
2960
+  if( cmJsonInitializeFromFile(&jsH, fn, ctx ) != kOkJsRC )
2961
+    return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "JSON file parse failed on the modulator file: %s.",cmStringNullGuard(fn) );
2962
+
2963
+  jnp = cmJsonRoot(jsH);
2964
+  
2965
+  unsigned groupCnt = cmJsonChildCount(jnp);
2966
+
2967
+  // for each entry group
2968
+  for(i=0; i<groupCnt; ++i)
2969
+  {
2970
+    // get the entry group record
2971
+    if( g1 == NULL )
2972
+    {
2973
+      g1 = cmMemAllocZ(cmScModEntryGroup_t,1);
2974
+    
2975
+      if( g0 == NULL )
2976
+        p->glist = g1;
2977
+      else
2978
+        g0->link = g1;
2979
+    }
2980
+    
2981
+    // get the entry group pair node
2982
+    cmJsonNode_t* gnp = cmJsonMemberAtIndex(jnp,i);
2983
+
2984
+    if( gnp == NULL || !cmJsonIsPair(gnp) )
2985
+    {
2986
+      rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Invalid entry group at index %i in score modulator file:%s",i,cmStringNullGuard(fn) );
2987
+      goto errLabel;
2988
+    }
2989
+
2990
+    // store the group label
2991
+    g1->symId = cmSymTblRegisterSymbol(stH,cmJsonPairLabel(gnp));
3109 2992
 
2993
+    // get and validate the group array value
2994
+    if( (gnp = cmJsonPairValue(gnp))==NULL || cmJsonIsArray(gnp)==false  )
2995
+      return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Group entry '%s' does not contain an array of entries in file:%s",cmStringNullGuard(cmJsonPairLabel(gnp)),cmStringNullGuard(fn) );
2996
+    
2997
+    // parse the entry group
2998
+    if((rc = _cmScModParseEntryGroup( p, ctx, jsH, stH, gnp, g1, fn )) != cmOkRC )
2999
+    {
3000
+      rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Syntax error in entry group at index %i in score modulator file:%s",i,cmStringNullGuard(fn) );
3001
+      goto errLabel;
3002
+    }
3003
+
3004
+    g0 = g1;
3005
+    g1 = g1->link;
3006
+  }
3007
+
3008
+ errLabel:
3110 3009
   // release the JSON tree
3111 3010
   if( cmJsonIsValid(jsH) )
3112 3011
     cmJsonFinalize(&jsH);
@@ -3115,7 +3014,7 @@ cmRC_t _cmScModulatorParse( cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, con
3115 3014
 }
3116 3015
 
3117 3016
 
3118
-cmRC_t  _cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx )
3017
+cmRC_t  _cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx, unsigned entryGroupSymId )
3119 3018
 {
3120 3019
   cmRC_t rc = cmOkRC;
3121 3020
 
@@ -3128,10 +3027,27 @@ cmRC_t  _cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx )
3128 3027
   if((rc = _cmScModulatorParse(p,ctx,p->stH,p->fn)) != cmOkRC )
3129 3028
     goto errLabel;
3130 3029
 
3131
-  _cmScProcessEntryGroups(p);  // fill p->glist
3030
+  // select the entry group to execute
3031
+  if( entryGroupSymId != cmInvalidId )
3032
+  {
3033
+    cmScModEntryGroup_t* g = p->glist;
3034
+    for(; g!=NULL; g=g->link)
3035
+      if( g->symId == entryGroupSymId )
3036
+      {
3037
+        cmCtxPrint(p->obj.ctx,"%s selected.\n",cmSymTblLabel(p->stH,entryGroupSymId));
3038
+        p->xlist = p->glist;
3039
+        break;
3040
+      }
3041
+  }
3132 3042
 
3133
-  _cmScProcessExecList(p);     // fill p->xlist
3043
+  // if an active entry group  has not been set - set it to the first entry group
3044
+  if( p->xlist == NULL )
3045
+  {
3046
+    if( entryGroupSymId != cmInvalidId )
3047
+      cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The modulator entry group '%s' was not found. The active entry group was set to the first group in the file.",cmSymTblLabel(p->stH,entryGroupSymId) );
3134 3048
 
3049
+    p->xlist = p->glist;
3050
+  }
3135 3051
 
3136 3052
   // clear the active flag on all variables
3137 3053
   cmScModVar_t* vp = p->vlist;
@@ -3160,11 +3076,10 @@ cmRC_t cmScModulatorInit(  cmScModulator* p, cmCtx_t* ctx, cmSymTblH_t stH, doub
3160 3076
   p->samplesPerCycle = samplesPerCycle;
3161 3077
   p->srate           = srate;
3162 3078
   
3163
-
3164 3079
   if( rc != cmOkRC )
3165 3080
     cmScModulatorFinal(p);
3166 3081
   else
3167
-    _cmScModulatorReset(p,ctx,0);
3082
+    _cmScModulatorReset(p,ctx,0,cmInvalidId);
3168 3083
 
3169 3084
   return rc;
3170 3085
 }
@@ -3187,7 +3102,7 @@ cmRC_t cmScModulatorFinal( cmScModulator* p )
3187 3102
   while( g != NULL )
3188 3103
   {
3189 3104
     cmScModEntryGroup_t* g0 = g->link;
3190
-    cmMemFree(g->base);
3105
+    cmMemFree(g->earray);
3191 3106
     cmMemFree(g);
3192 3107
     g = g0;
3193 3108
   }
@@ -3202,9 +3117,11 @@ unsigned        cmScModulatorOutVarCount( cmScModulator* p )
3202 3117
 cmScModVar_t* cmScModulatorOutVar( cmScModulator* p, unsigned idx )
3203 3118
 {
3204 3119
   unsigned i;
3205
-  for(i=0; i<p->en; ++i)
3206
-    if( p->earray[i].varPtr->outVarId == idx )
3207
-      return p->earray[i].varPtr;
3120
+  cmScModEntryGroup_t* g = p->glist;
3121
+  for(; g!=NULL; g=g->link)
3122
+    for(i=0; i<g->en; ++i)
3123
+      if( g->earray[i].varPtr->outVarId == idx )
3124
+        return g->earray[i].varPtr;
3208 3125
 
3209 3126
   return NULL;  
3210 3127
 }
@@ -3230,9 +3147,9 @@ cmRC_t         cmScModulatorSetValue( cmScModulator* p, unsigned varSymId, doubl
3230 3147
 }
3231 3148
 
3232 3149
 
3233
-cmRC_t cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx )
3150
+cmRC_t cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx, unsigned entryGroupSymId )
3234 3151
 {
3235
-  _cmScModulatorReset(p,ctx,scLocIdx);
3152
+  _cmScModulatorReset(p,ctx,scLocIdx,entryGroupSymId);
3236 3153
   return cmScModulatorExec(p,scLocIdx);
3237 3154
 }
3238 3155
 
@@ -3298,17 +3215,17 @@ cmRC_t  _cmScModGetParam( cmScModulator* p, const cmScModParam_t* pp, double* va
3298 3215
   return rc;
3299 3216
 }
3300 3217
 
3301
-cmRC_t  _cmScModExecEntries( cmScModulator* p, cmScModEntry_t** xparray, unsigned* idxRef, unsigned cnt, unsigned scLocIdx );
3218
+cmRC_t  _cmScModActivateEntries( cmScModulator* p, cmScModEntry_t* earray, unsigned* idxRef, unsigned cnt, unsigned scLocIdx );
3302 3219
 
3303
-cmRC_t  _cmScModExecGroup( cmScModulator* p, cmScModEntry_t* ep )
3220
+cmRC_t  _cmScModActivateGroup( cmScModulator* p, cmScModEntry_t* ep )
3304 3221
 {
3305 3222
   cmScModEntryGroup_t* g = p->glist;
3306 3223
   for(; g!=NULL; g=g->link)
3307
-    if( g->base != NULL && g->base[0]->scLocIdx == ep->beg.symId )
3224
+    if( g->symId == ep->beg.symId )
3308 3225
     {
3309 3226
       unsigned idx = 0;
3310 3227
 
3311
-      return  _cmScModExecEntries( p, g->base, &idx, g->n, ep->beg.symId );
3228
+      return  _cmScModActivateEntries( p, g->earray, &idx, g->en, ep->beg.symId );
3312 3229
     }
3313 3230
 
3314 3231
   return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Entry group '%s' not found.",cmSymTblLabel(p->stH,ep->beg.symId));    
@@ -3357,7 +3274,7 @@ cmRC_t _cmScModActivate(cmScModulator* p, cmScModEntry_t* ep )
3357 3274
       break;
3358 3275
 
3359 3276
     case kExecModTId:
3360
-      rc = _cmScModExecGroup(p,ep);
3277
+      rc = _cmScModActivateGroup(p,ep);
3361 3278
       break;
3362 3279
 
3363 3280
     default:
@@ -3466,18 +3383,18 @@ bool  _cmScModExec( cmScModulator* p, cmScModVar_t* vp )
3466 3383
 // Execute the entries in xparray[] begining with entry xparray[idx] and continuing until:
3467 3384
 // 1) cnt - idx entries have been executed
3468 3385
 // 2) an entry is located whose scLocIdx != scLocIdx and also not -1
3469
-cmRC_t  _cmScModExecEntries( cmScModulator* p, cmScModEntry_t** xparray, unsigned* idxRef, unsigned cnt, unsigned scLocIdx )
3386
+cmRC_t  _cmScModActivateEntries( cmScModulator* p, cmScModEntry_t* earray, unsigned* idxRef, unsigned cnt, unsigned scLocIdx )
3470 3387
 {
3471 3388
   assert( idxRef != NULL );
3472 3389
   
3473
-  cmRC_t trc;
3474
-  cmRC_t rc = cmOkRC;
3390
+  cmRC_t   trc;
3391
+  cmRC_t   rc  = cmOkRC;
3475 3392
   unsigned idx = *idxRef;
3476 3393
   
3477 3394
   // trigger entries that have expired since the last call to this function
3478
-  for(; idx<cnt && (xparray[idx]->scLocIdx==-1 || xparray[idx]->scLocIdx<=scLocIdx); ++idx)
3395
+  for(; idx<cnt && (earray[idx].scLocIdx==-1 || earray[idx].scLocIdx<=scLocIdx); ++idx)
3479 3396
   {
3480
-    cmScModEntry_t* ep = xparray[idx];
3397
+    cmScModEntry_t* ep = earray + idx;
3481 3398
 
3482 3399
     // if the variable assoc'd with this entry is not on the active list ...
3483 3400
     if( cmIsFlag(ep->varPtr->flags,kActiveModFl) == false )
@@ -3516,44 +3433,8 @@ cmRC_t  _cmScModExecEntries( cmScModulator* p, cmScModEntry_t** xparray, unsigne
3516 3433
 cmRC_t cmScModulatorExec( cmScModulator* p, unsigned scLocIdx )
3517 3434
 {
3518 3435
   cmRC_t rc = cmOkRC;
3519
-  /*
3520
-  cmRC_t trc;
3521
-
3522
-  // trigger entries that have expired since the last call to this function
3523
-  for(; p->nei<p->xn && (p->xlist[p->nei]->scLocIdx==-1 || p->xlist[p->nei]->scLocIdx<=scLocIdx); ++p->nei)
3524
-  {
3525
-    cmScModEntry_t* ep = p->xlist[p->nei];
3526
-
3527
-    // if the variable assoc'd with this entry is not on the active list ...
3528
-    if( cmIsFlag(ep->varPtr->flags,kActiveModFl) == false )
3529
-    {
3530
-      // ... then append it to the end of the active list ...
3531
-      ep->varPtr->flags |= kActiveModFl; 
3532
-
3533
-      if( p->elist == NULL )
3534
-        p->elist = ep->varPtr;
3535
-      else
3536
-      {
3537
-        p->elist->alink = ep->varPtr;
3538
-        p->elist        = ep->varPtr;
3539
-      }
3540
-
3541
-      p->elist->alink = NULL;
3542
-
3543
-      if( p->alist == NULL )
3544
-        p->alist = ep->varPtr;
3545
-    }
3546
-
3547
-    // do type specific activation
3548
-    if((trc = _cmScModActivate(p,ep)) != cmOkRC )
3549
-      rc = trc;
3550
-
3551
-    ep->varPtr->entry = ep;
3552
-
3553
-  }
3554
-  */
3555 3436
   
3556
-  rc =  _cmScModExecEntries(p, p->xlist, &p->nei, p->xn, scLocIdx );
3437
+  rc =  _cmScModActivateEntries(p, p->xlist->earray, &p->nei, p->xlist->en, scLocIdx );
3557 3438
   
3558 3439
   // Update the active variables
3559 3440
   cmScModVar_t* pp = NULL;
@@ -3624,28 +3505,30 @@ cmRC_t  cmScModulatorDump(  cmScModulator* p )
3624 3505
   printf("nei:%i alist:%p outVarCnt:%i\n",p->nei,p->alist,p->outVarCnt);
3625 3506
 
3626 3507
   printf("ENTRIES:\n");
3627
-  unsigned i;
3628
-  for(i=0; i<p->en; ++i)
3508
+  cmScModEntryGroup_t* g = p->glist;
3509
+  for(; g!=NULL; g=g->link)
3629 3510
   {
3630
-    cmScModEntry_t* ep = p->earray + i;
3631
-    const _cmScModTypeMap_t* tm = _cmScModTypeIdToMap( ep->typeId );
3511
+    printf("%s\n",cmSymTblLabel(p->stH,g->symId));
3512
+    unsigned i;
3513
+    for(i=0; i<g->en; ++i)
3514
+    {
3515
+      cmScModEntry_t* ep = g->earray + i;
3516
+      const _cmScModTypeMap_t* tm = _cmScModTypeIdToMap( ep->typeId );
3632 3517
 
3633
-    printf("%3i ",i);
3518
+      printf("%3i ",i);
3634 3519
 
3635
-    if( cmIsFlag(ep->flags,kLocLabelEntryFl) )
3636
-      printf("%10s ",cmSymTblLabel(p->stH,ep->scLocIdx));
3637
-    else
3638 3520
       printf("%10i ",ep->scLocIdx);
3639 3521
     
3640
-    printf("%5s %7s", tm==NULL ? "invld" : tm->label, cmSymTblLabel(p->stH,ep->varPtr->varSymId));
3641
-    _cmScModDumpParam(p," beg", &ep->beg);
3642
-    _cmScModDumpParam(p," end", &ep->end);
3643
-    _cmScModDumpParam(p," min", &ep->min);
3644
-    _cmScModDumpParam(p," max", &ep->max);
3645
-    _cmScModDumpParam(p," rate",&ep->rate);
3646
-    printf("\n");
3522
+      printf("%5s %7s", tm==NULL ? "invld" : tm->label, cmSymTblLabel(p->stH,ep->varPtr->varSymId));
3523
+      _cmScModDumpParam(p," beg", &ep->beg);
3524
+      _cmScModDumpParam(p," end", &ep->end);
3525
+      _cmScModDumpParam(p," min", &ep->min);
3526
+      _cmScModDumpParam(p," max", &ep->max);
3527
+      _cmScModDumpParam(p," rate",&ep->rate);
3528
+      printf("\n");
3529
+    }
3647 3530
   }
3648
-
3531
+  
3649 3532
   printf("VARIABLES\n");
3650 3533
   cmScModVar_t* vp = p->vlist;
3651 3534
   for(; vp!=NULL; vp=vp->vlink)

+ 5
- 10
cmProc4.h View File

@@ -477,13 +477,10 @@ extern "C" {
477 477
     struct cmScModVar_str*   alink;    // p->alist link
478 478
   } cmScModVar_t;
479 479
 
480
-  enum { kLocLabelEntryFl = 0x01 };
481
-
482 480
   // Each entry gives a time tagged location and some parameters 
483 481
   // for an algorthm which is used to set/modulate a value.
484 482
   typedef struct cmScModEntry_str
485 483
   {
486
-    unsigned       flags;         // { kLocLabelEntryFl }
487 484
     unsigned       scLocIdx;      // entry start time
488 485
     unsigned       typeId;        // variable type
489 486
     cmScModParam_t beg;           // parameter values
@@ -497,8 +494,9 @@ extern "C" {
497 494
 
498 495
   typedef struct cmScModEntryGroup_str
499 496
   {
500
-    cmScModEntry_t**              base;
501
-    unsigned                      n;
497
+    unsigned                      symId;   // this groups label
498
+    cmScModEntry_t*               earray;  // entries associated with this group
499
+    unsigned                      en;      // earray[en]
502 500
     struct cmScModEntryGroup_str* link;
503 501
   } cmScModEntryGroup_t;
504 502
 
@@ -514,16 +512,13 @@ extern "C" {
514 512
     void*           cbArg;        // first arg to cbFunc()
515 513
     unsigned        samplesPerCycle; // interval in samples between calls to cmScModulatorExec()
516 514
     double          srate;        // system sample rate
517
-    cmScModEntry_t* earray;       // earray[en] - entry array sorted on ascending cmScModEntry_t.scLocIdx
518
-    unsigned        en;           // count 
519 515
     cmScModVar_t*   vlist;        // variable list
520 516
     cmScModVar_t*   alist;        // active variable list
521 517
     cmScModVar_t*   elist;        // last element on the active list
522 518
     unsigned        nei;          // next entry index
523 519
     unsigned        outVarCnt;    // count of unique vars that are targets of entry recds
524 520
     bool            postFl;       // send a 'post' msg after each transmission
525
-    cmScModEntry_t**     xlist;
526
-    unsigned             xn;
521
+    cmScModEntryGroup_t* xlist;
527 522
     cmScModEntryGroup_t* glist;
528 523
   } cmScModulator;
529 524
 
@@ -541,7 +536,7 @@ extern "C" {
541 536
 
542 537
   cmRC_t         cmScModulatorSetValue( cmScModulator* p, unsigned varSymId, double value, double min, double max );
543 538
 
544
-  cmRC_t         cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx );
539
+  cmRC_t         cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx, unsigned entryGroupSymId );
545 540
   cmRC_t         cmScModulatorExec(  cmScModulator* p, unsigned scLocIdx );
546 541
   cmRC_t         cmScModulatorDump(  cmScModulator* p );
547 542
 

+ 4
- 1
dsp/cmDspKr.c View File

@@ -1236,6 +1236,7 @@ enum
1236 1236
   kScLocIdxMdId,
1237 1237
   kResetIdxMdId,
1238 1238
   kCmdMdId,
1239
+  kSelMdId,
1239 1240
   kPostMdId
1240 1241
 };
1241 1242
 
@@ -1279,6 +1280,7 @@ cmDspInst_t*  _cmDspScModAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
1279 1280
     { "index",   kScLocIdxMdId, 0,0, kInDsvFl  | kUIntDsvFl,  "Score follower index input."},
1280 1281
     { "reset",   kResetIdxMdId, 0,0, kInDsvFl  | kUIntDsvFl | kOptArgDsvFl, "Reset the modulator and go to the score index."},
1281 1282
     { "cmd",     kCmdMdId,      0,0, kInDsvFl  | kSymDsvFl  | kOptArgDsvFl, "on | off."},
1283
+    { "sel",     kSelMdId,      0,0, kInDsvFl  | kSymDsvFl  | kOptArgDsvFl, "Set the next active entry group name."},
1282 1284
     { "post",    kPostMdId,     0,0, kOutDsvFl | kSymDsvFl, "Sends 'post' symbol after a message transmission if the 'post' flag is set in scMod."},
1283 1285
     { NULL, 0, 0, 0, 0 }
1284 1286
   };
@@ -1346,6 +1348,7 @@ cmDspInst_t*  _cmDspScModAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
1346 1348
 
1347 1349
   cmDspSetDefaultUInt(ctx,&p->inst,kScLocIdxMdId,0,0);
1348 1350
   cmDspSetDefaultSymbol(ctx,&p->inst,kCmdMdId,p->offSymId);
1351
+  cmDspSetDefaultSymbol(ctx,&p->inst,kSelMdId,cmInvalidId);
1349 1352
   return &p->inst;
1350 1353
 }
1351 1354
 
@@ -1389,7 +1392,7 @@ cmDspRC_t _cmDspScModRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
1389 1392
       {
1390 1393
         unsigned symId = cmDspSymbol(inst,kCmdMdId);
1391 1394
         if( symId == p->onSymId )
1392
-          cmScModulatorReset(p->mp, ctx->cmCtx, cmDspUInt(inst,kScLocIdxMdId));
1395
+          cmScModulatorReset(p->mp, ctx->cmCtx, cmDspUInt(inst,kScLocIdxMdId), cmDspSymbol(inst,kSelMdId));
1393 1396
         
1394 1397
         if( symId == p->dumpSymId )
1395 1398
           cmScModulatorDump(p->mp);

Loading…
Cancel
Save