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
   if((rc = cmScModulatorFinal(p)) != cmOkRC )
2686
   if((rc = cmScModulatorFinal(p)) != cmOkRC )
2687
     return rc;
2687
     return rc;
2688
 
2688
 
2689
-  cmMemFree(p->earray);
2690
-  cmMemFree(p->xlist);
2689
+  //cmMemFree(p->earray);
2690
+  //cmMemFree(p->xlist);
2691
   cmObjFree(pp);
2691
   cmObjFree(pp);
2692
   return rc;
2692
   return rc;
2693
 }
2693
 }
2743
 {
2743
 {
2744
   cmScModVar_t* vp = _cmScModSymToVar(p,varSymId);
2744
   cmScModVar_t* vp = _cmScModSymToVar(p,varSymId);
2745
 
2745
 
2746
+  // if the specified variable was not found then create one
2746
   if( vp == NULL )
2747
   if( vp == NULL )
2747
   {
2748
   {
2748
     vp = cmMemAllocZ(cmScModVar_t,1);
2749
     vp = cmMemAllocZ(cmScModVar_t,1);
2764
   return vp;
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
  // A parameter value may be either a symbol identifier (mapped to a variable)
2792
  // A parameter value may be either a symbol identifier (mapped to a variable)
2793
  // or a literal number.  This function determines which form the paramter
2793
  // or a literal number.  This function determines which form the paramter
2794
  // value takes and parses it accordingly.
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
   cmRC_t rc = cmOkRC;
2797
   cmRC_t rc = cmOkRC;
2798
 
2798
 
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
   // allocate the entry array
2845
   // allocate the entry array
2938
   unsigned entryCnt = cmJsonChildCount(jnp);
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
   for(i=0; i<entryCnt; ++i)
2850
   for(i=0; i<entryCnt; ++i)
2949
   {
2851
   {
2950
     cmJsRC_t                 jsRC        = kOkJsRC;
2852
     cmJsRC_t                 jsRC        = kOkJsRC;
2951
     const char*              errLabelPtr = NULL;
2853
     const char*              errLabelPtr = NULL;
2952
     unsigned                 scLocIdx    = cmInvalidIdx;
2854
     unsigned                 scLocIdx    = cmInvalidIdx;
2953
-    const cmChar_t*          modLabel    = NULL;
2954
     const cmChar_t*          varLabel    = NULL;
2855
     const cmChar_t*          varLabel    = NULL;
2955
     const cmChar_t*          typeLabel   = NULL;
2856
     const cmChar_t*          typeLabel   = NULL;
2956
     cmJsonNode_t*            onp         = cmJsonArrayElement(jnp,i);
2857
     cmJsonNode_t*            onp         = cmJsonArrayElement(jnp,i);
2957
     cmJsonNode_t*            dnp         = NULL;
2858
     cmJsonNode_t*            dnp         = NULL;
2958
     const _cmScModTypeMap_t* map         = NULL;
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
     if((jsRC = cmJsonMemberValues( onp, &errLabelPtr,
2862
     if((jsRC = cmJsonMemberValues( onp, &errLabelPtr,
2996
-          "mod", kStringTId | kOptArgJsFl, &modLabel,
2997
           "var", kStringTId | kOptArgJsFl, &varLabel,
2863
           "var", kStringTId | kOptArgJsFl, &varLabel,
2998
           "type",kStringTId | kOptArgJsFl, &typeLabel,
2864
           "type",kStringTId | kOptArgJsFl, &typeLabel,
2865
+          "loc", kIntTId    | kOptArgJsFl, &scLocIdx,
2999
           NULL )) != kOkJsRC )
2866
           NULL )) != kOkJsRC )
3000
     {
2867
     {
3001
       if( errLabelPtr == NULL )
2868
       if( errLabelPtr == NULL )
3011
     else
2878
     else
3012
       prvScLocIdx = scLocIdx;
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
     // if the var label was not given use the previous one
2881
     // if the var label was not given use the previous one
3033
     if( varLabel == NULL )
2882
     if( varLabel == NULL )
3034
       varLabel = prvVarLabel;
2883
       varLabel = prvVarLabel;
3060
       goto errLabel;
2909
       goto errLabel;
3061
     }
2910
     }
3062
     
2911
     
3063
-    unsigned modSymId = cmSymTblRegisterSymbol(stH,modLabel);
3064
     unsigned varSymId = cmSymTblRegisterSymbol(stH,varLabel);
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
     // get the count of the elmenets in the data array
2914
     // get the count of the elmenets in the data array
3074
     unsigned paramCnt = cmJsonChildCount(onp);
2915
     unsigned paramCnt = cmJsonChildCount(onp);
3075
 
2916
 
3076
     // fill the entry record and find or create the target var
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
     typedef struct
2920
     typedef struct
3080
     {
2921
     {
3103
 
2944
 
3104
  errLabel:
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
   // release the JSON tree
3009
   // release the JSON tree
3111
   if( cmJsonIsValid(jsH) )
3010
   if( cmJsonIsValid(jsH) )
3112
     cmJsonFinalize(&jsH);
3011
     cmJsonFinalize(&jsH);
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
   cmRC_t rc = cmOkRC;
3019
   cmRC_t rc = cmOkRC;
3121
 
3020
 
3128
   if((rc = _cmScModulatorParse(p,ctx,p->stH,p->fn)) != cmOkRC )
3027
   if((rc = _cmScModulatorParse(p,ctx,p->stH,p->fn)) != cmOkRC )
3129
     goto errLabel;
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
   // clear the active flag on all variables
3052
   // clear the active flag on all variables
3137
   cmScModVar_t* vp = p->vlist;
3053
   cmScModVar_t* vp = p->vlist;
3160
   p->samplesPerCycle = samplesPerCycle;
3076
   p->samplesPerCycle = samplesPerCycle;
3161
   p->srate           = srate;
3077
   p->srate           = srate;
3162
   
3078
   
3163
-
3164
   if( rc != cmOkRC )
3079
   if( rc != cmOkRC )
3165
     cmScModulatorFinal(p);
3080
     cmScModulatorFinal(p);
3166
   else
3081
   else
3167
-    _cmScModulatorReset(p,ctx,0);
3082
+    _cmScModulatorReset(p,ctx,0,cmInvalidId);
3168
 
3083
 
3169
   return rc;
3084
   return rc;
3170
 }
3085
 }
3187
   while( g != NULL )
3102
   while( g != NULL )
3188
   {
3103
   {
3189
     cmScModEntryGroup_t* g0 = g->link;
3104
     cmScModEntryGroup_t* g0 = g->link;
3190
-    cmMemFree(g->base);
3105
+    cmMemFree(g->earray);
3191
     cmMemFree(g);
3106
     cmMemFree(g);
3192
     g = g0;
3107
     g = g0;
3193
   }
3108
   }
3202
 cmScModVar_t* cmScModulatorOutVar( cmScModulator* p, unsigned idx )
3117
 cmScModVar_t* cmScModulatorOutVar( cmScModulator* p, unsigned idx )
3203
 {
3118
 {
3204
   unsigned i;
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
   return NULL;  
3126
   return NULL;  
3210
 }
3127
 }
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
   return cmScModulatorExec(p,scLocIdx);
3153
   return cmScModulatorExec(p,scLocIdx);
3237
 }
3154
 }
3238
 
3155
 
3298
   return rc;
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
   cmScModEntryGroup_t* g = p->glist;
3222
   cmScModEntryGroup_t* g = p->glist;
3306
   for(; g!=NULL; g=g->link)
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
       unsigned idx = 0;
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
   return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Entry group '%s' not found.",cmSymTblLabel(p->stH,ep->beg.symId));    
3231
   return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Entry group '%s' not found.",cmSymTblLabel(p->stH,ep->beg.symId));    
3357
       break;
3274
       break;
3358
 
3275
 
3359
     case kExecModTId:
3276
     case kExecModTId:
3360
-      rc = _cmScModExecGroup(p,ep);
3277
+      rc = _cmScModActivateGroup(p,ep);
3361
       break;
3278
       break;
3362
 
3279
 
3363
     default:
3280
     default:
3466
 // Execute the entries in xparray[] begining with entry xparray[idx] and continuing until:
3383
 // Execute the entries in xparray[] begining with entry xparray[idx] and continuing until:
3467
 // 1) cnt - idx entries have been executed
3384
 // 1) cnt - idx entries have been executed
3468
 // 2) an entry is located whose scLocIdx != scLocIdx and also not -1
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
   assert( idxRef != NULL );
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
   unsigned idx = *idxRef;
3392
   unsigned idx = *idxRef;
3476
   
3393
   
3477
   // trigger entries that have expired since the last call to this function
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
     // if the variable assoc'd with this entry is not on the active list ...
3399
     // if the variable assoc'd with this entry is not on the active list ...
3483
     if( cmIsFlag(ep->varPtr->flags,kActiveModFl) == false )
3400
     if( cmIsFlag(ep->varPtr->flags,kActiveModFl) == false )
3516
 cmRC_t cmScModulatorExec( cmScModulator* p, unsigned scLocIdx )
3433
 cmRC_t cmScModulatorExec( cmScModulator* p, unsigned scLocIdx )
3517
 {
3434
 {
3518
   cmRC_t rc = cmOkRC;
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
   // Update the active variables
3439
   // Update the active variables
3559
   cmScModVar_t* pp = NULL;
3440
   cmScModVar_t* pp = NULL;
3624
   printf("nei:%i alist:%p outVarCnt:%i\n",p->nei,p->alist,p->outVarCnt);
3505
   printf("nei:%i alist:%p outVarCnt:%i\n",p->nei,p->alist,p->outVarCnt);
3625
 
3506
 
3626
   printf("ENTRIES:\n");
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
       printf("%10i ",ep->scLocIdx);
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
   printf("VARIABLES\n");
3532
   printf("VARIABLES\n");
3650
   cmScModVar_t* vp = p->vlist;
3533
   cmScModVar_t* vp = p->vlist;
3651
   for(; vp!=NULL; vp=vp->vlink)
3534
   for(; vp!=NULL; vp=vp->vlink)

+ 5
- 10
cmProc4.h View File

477
     struct cmScModVar_str*   alink;    // p->alist link
477
     struct cmScModVar_str*   alink;    // p->alist link
478
   } cmScModVar_t;
478
   } cmScModVar_t;
479
 
479
 
480
-  enum { kLocLabelEntryFl = 0x01 };
481
-
482
   // Each entry gives a time tagged location and some parameters 
480
   // Each entry gives a time tagged location and some parameters 
483
   // for an algorthm which is used to set/modulate a value.
481
   // for an algorthm which is used to set/modulate a value.
484
   typedef struct cmScModEntry_str
482
   typedef struct cmScModEntry_str
485
   {
483
   {
486
-    unsigned       flags;         // { kLocLabelEntryFl }
487
     unsigned       scLocIdx;      // entry start time
484
     unsigned       scLocIdx;      // entry start time
488
     unsigned       typeId;        // variable type
485
     unsigned       typeId;        // variable type
489
     cmScModParam_t beg;           // parameter values
486
     cmScModParam_t beg;           // parameter values
497
 
494
 
498
   typedef struct cmScModEntryGroup_str
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
     struct cmScModEntryGroup_str* link;
500
     struct cmScModEntryGroup_str* link;
503
   } cmScModEntryGroup_t;
501
   } cmScModEntryGroup_t;
504
 
502
 
514
     void*           cbArg;        // first arg to cbFunc()
512
     void*           cbArg;        // first arg to cbFunc()
515
     unsigned        samplesPerCycle; // interval in samples between calls to cmScModulatorExec()
513
     unsigned        samplesPerCycle; // interval in samples between calls to cmScModulatorExec()
516
     double          srate;        // system sample rate
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
     cmScModVar_t*   vlist;        // variable list
515
     cmScModVar_t*   vlist;        // variable list
520
     cmScModVar_t*   alist;        // active variable list
516
     cmScModVar_t*   alist;        // active variable list
521
     cmScModVar_t*   elist;        // last element on the active list
517
     cmScModVar_t*   elist;        // last element on the active list
522
     unsigned        nei;          // next entry index
518
     unsigned        nei;          // next entry index
523
     unsigned        outVarCnt;    // count of unique vars that are targets of entry recds
519
     unsigned        outVarCnt;    // count of unique vars that are targets of entry recds
524
     bool            postFl;       // send a 'post' msg after each transmission
520
     bool            postFl;       // send a 'post' msg after each transmission
525
-    cmScModEntry_t**     xlist;
526
-    unsigned             xn;
521
+    cmScModEntryGroup_t* xlist;
527
     cmScModEntryGroup_t* glist;
522
     cmScModEntryGroup_t* glist;
528
   } cmScModulator;
523
   } cmScModulator;
529
 
524
 
541
 
536
 
542
   cmRC_t         cmScModulatorSetValue( cmScModulator* p, unsigned varSymId, double value, double min, double max );
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
   cmRC_t         cmScModulatorExec(  cmScModulator* p, unsigned scLocIdx );
540
   cmRC_t         cmScModulatorExec(  cmScModulator* p, unsigned scLocIdx );
546
   cmRC_t         cmScModulatorDump(  cmScModulator* p );
541
   cmRC_t         cmScModulatorDump(  cmScModulator* p );
547
 
542
 

+ 4
- 1
dsp/cmDspKr.c View File

1236
   kScLocIdxMdId,
1236
   kScLocIdxMdId,
1237
   kResetIdxMdId,
1237
   kResetIdxMdId,
1238
   kCmdMdId,
1238
   kCmdMdId,
1239
+  kSelMdId,
1239
   kPostMdId
1240
   kPostMdId
1240
 };
1241
 };
1241
 
1242
 
1279
     { "index",   kScLocIdxMdId, 0,0, kInDsvFl  | kUIntDsvFl,  "Score follower index input."},
1280
     { "index",   kScLocIdxMdId, 0,0, kInDsvFl  | kUIntDsvFl,  "Score follower index input."},
1280
     { "reset",   kResetIdxMdId, 0,0, kInDsvFl  | kUIntDsvFl | kOptArgDsvFl, "Reset the modulator and go to the score index."},
1281
     { "reset",   kResetIdxMdId, 0,0, kInDsvFl  | kUIntDsvFl | kOptArgDsvFl, "Reset the modulator and go to the score index."},
1281
     { "cmd",     kCmdMdId,      0,0, kInDsvFl  | kSymDsvFl  | kOptArgDsvFl, "on | off."},
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
     { "post",    kPostMdId,     0,0, kOutDsvFl | kSymDsvFl, "Sends 'post' symbol after a message transmission if the 'post' flag is set in scMod."},
1284
     { "post",    kPostMdId,     0,0, kOutDsvFl | kSymDsvFl, "Sends 'post' symbol after a message transmission if the 'post' flag is set in scMod."},
1283
     { NULL, 0, 0, 0, 0 }
1285
     { NULL, 0, 0, 0, 0 }
1284
   };
1286
   };
1346
 
1348
 
1347
   cmDspSetDefaultUInt(ctx,&p->inst,kScLocIdxMdId,0,0);
1349
   cmDspSetDefaultUInt(ctx,&p->inst,kScLocIdxMdId,0,0);
1348
   cmDspSetDefaultSymbol(ctx,&p->inst,kCmdMdId,p->offSymId);
1350
   cmDspSetDefaultSymbol(ctx,&p->inst,kCmdMdId,p->offSymId);
1351
+  cmDspSetDefaultSymbol(ctx,&p->inst,kSelMdId,cmInvalidId);
1349
   return &p->inst;
1352
   return &p->inst;
1350
 }
1353
 }
1351
 
1354
 
1389
       {
1392
       {
1390
         unsigned symId = cmDspSymbol(inst,kCmdMdId);
1393
         unsigned symId = cmDspSymbol(inst,kCmdMdId);
1391
         if( symId == p->onSymId )
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
         if( symId == p->dumpSymId )
1397
         if( symId == p->dumpSymId )
1395
           cmScModulatorDump(p->mp);
1398
           cmScModulatorDump(p->mp);

Loading…
Cancel
Save