瀏覽代碼

cmProc4.h/c, cmDspKr.c : Initial changes to support scMod 'in' and 'cross'.

master
kevin 7 年之前
父節點
當前提交
286a303d04
共有 3 個文件被更改,包括 303 次插入134 次删除
  1. 231
    111
      cmProc4.c
  2. 33
    9
      cmProc4.h
  3. 39
    14
      dsp/cmDspKr.c

+ 231
- 111
cmProc4.c 查看文件

@@ -2707,6 +2707,8 @@ _cmScModTypeMap_t _cmScModTypeArray[] =
2707 2707
   { kSetLineModTId, 3, "sline" },
2708 2708
   { kPostModTId,    4, "post"  },
2709 2709
   { kExecModTId,    5, "exec"  },
2710
+  { kInputModTId,   6, "input" },
2711
+  { kCrossModTId,   7, "cross" },
2710 2712
   { kInvalidModTId, 0, "<invalid>"}
2711 2713
 };
2712 2714
 
@@ -2748,7 +2750,7 @@ cmScModVar_t* _cmScModulatorInsertVar( cmScModulator* p, unsigned varSymId, unsi
2748 2750
   {
2749 2751
     vp = cmMemAllocZ(cmScModVar_t,1);
2750 2752
     vp->varSymId = varSymId;
2751
-    vp->outVarId = cmInvalidId;
2753
+    vp->varId = cmInvalidId;
2752 2754
     vp->vlink    = p->vlist;
2753 2755
     p->vlist     = vp;
2754 2756
   }
@@ -2771,15 +2773,10 @@ cmScModEntry_t* _cmScModulatorInsertEntry(cmScModulator* p, cmScModEntryGroup_t*
2771 2773
 
2772 2774
   g->earray[idx].scLocIdx = scLocIdx;
2773 2775
   g->earray[idx].typeId   = typeId;
2774
-  g->earray[idx].varPtr   = _cmScModulatorInsertVar(p,varSymId,0);
2775
-
2776
-  if( g->earray[idx].varPtr->outVarId == cmInvalidIdx )
2777
-    g->earray[idx].varPtr->outVarId = p->outVarCnt++;
2778 2776
 
2779 2777
   return g->earray + idx;
2780 2778
 }
2781 2779
 
2782
-
2783 2780
 /*
2784 2781
 {
2785 2782
   [
@@ -2833,6 +2830,114 @@ cmRC_t _cmScModulatorParseParam( cmScModulator* p, cmSymTblH_t stH, cmJsonNode_t
2833 2830
 }
2834 2831
 
2835 2832
 
2833
+
2834
+// If the requested parameter has a value then return it in *valPtr.
2835
+// If it does not then do nothing. This function applies scaling to RHS values.
2836
+cmRC_t  _cmScModGetParam( cmScModulator* p, const cmScModParam_t* pp, double* valPtr )
2837
+{
2838
+  cmRC_t rc = cmOkRC;
2839
+
2840
+  switch( pp->pid )
2841
+  {
2842
+    case kInvalidModPId:
2843
+      rc  = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "An invalid parameter was encountered.");
2844
+      goto errLabel;
2845
+      break;
2846
+
2847
+    case kLiteralModPId:
2848
+      *valPtr = pp->val;
2849
+      break;
2850
+
2851
+    case kSymbolModPId:
2852
+      {
2853
+        cmScModVar_t* vp;
2854
+
2855
+        // get a pointer to the parameter variable
2856
+        if((vp = _cmScModSymToVar(p, pp->symId )) == NULL )
2857
+        {
2858
+          rc  = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Variable '%s' not found.",cmSymTblLabel(p->stH,pp->symId));    
2859
+          goto errLabel;
2860
+        } 
2861
+
2862
+        // if this is not a 'calculated' paramter then scale it here.
2863
+        if( cmIsFlag(vp->flags,kCalcModFl ) && vp->min!=DBL_MAX && vp->max!=DBL_MAX )
2864
+          *valPtr = (vp->value - vp->min)/(vp->max-vp->min);
2865
+        else
2866
+          *valPtr = vp->value;
2867
+      }
2868
+      break;
2869
+
2870
+    default:
2871
+      { assert(0); }
2872
+  }
2873
+
2874
+ errLabel:
2875
+  return rc;
2876
+}
2877
+
2878
+void _cmScModDumpParam( cmScModulator* p, const cmChar_t* label, const cmScModParam_t* pp )
2879
+{
2880
+  printf("%s: ",label);
2881
+
2882
+  switch( pp->pid )
2883
+  {
2884
+    case kInvalidModPId:
2885
+      printf("<invalid>");
2886
+      break;
2887
+
2888
+    case kLiteralModPId:
2889
+      if( pp->val == DBL_MAX )
2890
+        printf("<max> ");
2891
+      else
2892
+        printf("%f ",pp->val);
2893
+      break;
2894
+
2895
+    case kSymbolModPId:
2896
+      printf("%s ",cmSymTblLabel(p->stH,pp->symId));
2897
+      break;
2898
+
2899
+    default:
2900
+      { assert(0); }
2901
+  }
2902
+}
2903
+
2904
+void _cmScModDumpVal( cmChar_t* label, double val )
2905
+{
2906
+  printf("%s:",label);
2907
+
2908
+  if( val == DBL_MAX )
2909
+    printf("<max> " );
2910
+  else
2911
+    printf("%f ",val);
2912
+}
2913
+
2914
+
2915
+void _cmScModDumpVar( cmScModulator* p, const cmScModVar_t* vp )
2916
+{
2917
+   printf("%7s %3i fl:0x%x entry:%p alink:%p %s",cmSymTblLabel(p->stH,vp->varSymId),vp->varId,vp->flags,vp->entry,vp->alink, cmIsFlag(vp->flags,kInputModFl)?"input":"");
2918
+    _cmScModDumpVal("val",vp->value);
2919
+    _cmScModDumpVal("min",vp->min);
2920
+    _cmScModDumpVal("max",vp->max);
2921
+    _cmScModDumpVal("rate",vp->rate);
2922
+    _cmScModDumpVal("v0",vp->v0);
2923
+}
2924
+
2925
+void _cmScModDumpEntry( cmScModulator* p, const cmScModEntry_t* ep)
2926
+{
2927
+  const _cmScModTypeMap_t* tm = _cmScModTypeIdToMap( ep->typeId );
2928
+
2929
+  printf("%10i ",ep->scLocIdx);
2930
+    
2931
+  printf("%5s %7s", tm==NULL ? "invld" : tm->label, cmSymTblLabel(p->stH,ep->varPtr->varSymId));
2932
+  _cmScModDumpParam(p," beg", &ep->beg);
2933
+  _cmScModDumpParam(p," end", &ep->end);
2934
+  _cmScModDumpParam(p," min", &ep->min);
2935
+  _cmScModDumpParam(p," max", &ep->max);
2936
+  _cmScModDumpParam(p," rate",&ep->rate);
2937
+  printf("\n");
2938
+  
2939
+}
2940
+
2836 2941
 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 2942
 {
2838 2943
   cmRC_t          rc            = cmOkRC;
@@ -2914,9 +3019,11 @@ cmRC_t _cmScModParseEntryGroup( cmScModulator* p, cmCtx_t* ctx, cmJsonH_t jsH, c
2914 3019
     // get the count of the elmenets in the data array
2915 3020
     unsigned paramCnt = cmJsonChildCount(onp);
2916 3021
 
3022
+
2917 3023
     // fill the entry record and find or create the target var
2918 3024
     cmScModEntry_t* ep = _cmScModulatorInsertEntry(p,g,i,scLocIdx,varSymId,map->typeId,paramCnt);
2919 3025
 
3026
+    
2920 3027
     typedef struct
2921 3028
     {
2922 3029
       const cmChar_t* label;
@@ -2932,6 +3039,7 @@ cmRC_t _cmScModParseEntryGroup( cmScModulator* p, cmCtx_t* ctx, cmJsonH_t jsH, c
2932 3039
       { "val", &ep->beg },
2933 3040
       { "end", &ep->end },
2934 3041
       { "dur", &ep->dur },
3042
+      { "arg", &ep->arg },
2935 3043
       { NULL, NULL }
2936 3044
     };
2937 3045
 
@@ -2939,7 +3047,21 @@ cmRC_t _cmScModParseEntryGroup( cmScModulator* p, cmCtx_t* ctx, cmJsonH_t jsH, c
2939 3047
     for(j=0; mapArray[j].param!=NULL; ++j)
2940 3048
       if((dnp = cmJsonFindValue(jsH,mapArray[j].label, onp, kInvalidTId )) != NULL )
2941 3049
         if((rc = _cmScModulatorParseParam(p,stH,dnp,mapArray[j].param)) != cmOkRC )
2942
-          goto errLabel;    
3050
+          goto errLabel;
3051
+
3052
+    // create the variable associated with this entry
3053
+    ep->varPtr = _cmScModulatorInsertVar(p,varSymId, ep->typeId==kInputModTId ? kInputModFl : 0);
3054
+
3055
+
3056
+    // set the variable id value
3057
+    if( ep->varPtr->varId == cmInvalidIdx )
3058
+    {
3059
+      if( ep->typeId != kInputModTId )
3060
+        ep->varPtr->varId = p->outVarCnt++;
3061
+      else
3062
+        ep->varPtr->varId = p->inVarCnt++;
3063
+    }
3064
+    
2943 3065
   }
2944 3066
 
2945 3067
  errLabel:
@@ -3022,6 +3144,8 @@ cmRC_t  _cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx,
3022 3144
   p->elist     = NULL;
3023 3145
   p->nei       = 0;
3024 3146
   p->outVarCnt = 0;
3147
+  p->inVarCnt  = 0;
3148
+  
3025 3149
   
3026 3150
   // reload the file
3027 3151
   if((rc = _cmScModulatorParse(p,ctx,p->stH,p->fn)) != cmOkRC )
@@ -3120,13 +3244,29 @@ cmScModVar_t* cmScModulatorOutVar( cmScModulator* p, unsigned idx )
3120 3244
   cmScModEntryGroup_t* g = p->glist;
3121 3245
   for(; g!=NULL; g=g->link)
3122 3246
     for(i=0; i<g->en; ++i)
3123
-      if( g->earray[i].varPtr->outVarId == idx )
3247
+      if( cmIsNotFlag(g->earray[i].varPtr->flags,kInputModFl) && g->earray[i].varPtr->varId == idx )
3248
+        return g->earray[i].varPtr;
3249
+
3250
+  return NULL;  
3251
+}
3252
+
3253
+unsigned        cmScModulatorInVarCount( cmScModulator* p )
3254
+{ return p->inVarCnt; }
3255
+
3256
+cmScModVar_t* cmScModulatorInVar( cmScModulator* p, unsigned idx )
3257
+{
3258
+  unsigned i;
3259
+  cmScModEntryGroup_t* g = p->glist;
3260
+  for(; g!=NULL; g=g->link)
3261
+    for(i=0; i<g->en; ++i)
3262
+      if( cmIsFlag(g->earray[i].varPtr->flags,kInputModFl) && g->earray[i].varPtr->varId == idx )
3124 3263
         return g->earray[i].varPtr;
3125 3264
 
3126 3265
   return NULL;  
3127 3266
 }
3128 3267
 
3129
-cmRC_t         cmScModulatorSetValue( cmScModulator* p, unsigned varSymId, double value, double min, double max )
3268
+
3269
+cmScModVar_t* _cmScModSetValuePrefix( cmScModulator* p, unsigned varSymId )
3130 3270
 {
3131 3271
   cmScModVar_t* vp;
3132 3272
   // if the var does not exist ....
@@ -3137,6 +3277,14 @@ cmRC_t         cmScModulatorSetValue( cmScModulator* p, unsigned varSymId, doubl
3137 3277
     assert(vp!=NULL);    
3138 3278
   }
3139 3279
 
3280
+  return vp;
3281
+}
3282
+
3283
+
3284
+cmRC_t         cmScModulatorSetValueMinMax( cmScModulator* p, unsigned varSymId, double value, double min, double max )
3285
+{
3286
+  cmScModVar_t* vp =  _cmScModSetValuePrefix(p, varSymId );
3287
+  
3140 3288
   assert( min <= max);
3141 3289
 
3142 3290
   vp->min   = min;
@@ -3146,6 +3294,15 @@ cmRC_t         cmScModulatorSetValue( cmScModulator* p, unsigned varSymId, doubl
3146 3294
   return cmOkRC;
3147 3295
 }
3148 3296
 
3297
+cmRC_t         cmScModulatorSetValue( cmScModulator* p, unsigned varSymId, double value )
3298
+{
3299
+  cmScModVar_t* vp =  _cmScModSetValuePrefix(p, varSymId );
3300
+  
3301
+  vp->value = value;
3302
+
3303
+  return cmOkRC;
3304
+}
3305
+
3149 3306
 
3150 3307
 cmRC_t cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx, unsigned entryGroupSymId )
3151 3308
 {
@@ -3171,50 +3328,6 @@ void  _cmScModUnlinkActive( cmScModulator* p, cmScModVar_t* vp, cmScModVar_t* pp
3171 3328
   vp->entry = NULL;
3172 3329
 }
3173 3330
 
3174
-// If the requested parameter has a value then return it in *valPtr.
3175
-// If it does not then do nothing. This function applies scaling to RHS values.
3176
-cmRC_t  _cmScModGetParam( cmScModulator* p, const cmScModParam_t* pp, double* valPtr )
3177
-{
3178
-  cmRC_t rc = cmOkRC;
3179
-
3180
-  switch( pp->pid )
3181
-  {
3182
-    case kInvalidModPId:
3183
-      rc  = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "An invalid parameter was encountered.");
3184
-      goto errLabel;
3185
-      break;
3186
-
3187
-    case kLiteralModPId:
3188
-      *valPtr = pp->val;
3189
-      break;
3190
-
3191
-    case kSymbolModPId:
3192
-      {
3193
-        cmScModVar_t* vp;
3194
-
3195
-        // get a pointer to the parameter variable
3196
-        if((vp = _cmScModSymToVar(p, pp->symId )) == NULL )
3197
-        {
3198
-          rc  = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Variable '%s' not found.",cmSymTblLabel(p->stH,pp->symId));    
3199
-          goto errLabel;
3200
-        } 
3201
-
3202
-        // if this is not a 'calculated' paramter then scale it here.
3203
-        if( cmIsFlag(vp->flags,kCalcModFl ) && vp->min!=DBL_MAX && vp->max!=DBL_MAX )
3204
-          *valPtr = (vp->value - vp->min)/(vp->max-vp->min);
3205
-        else
3206
-          *valPtr = vp->value;
3207
-      }
3208
-      break;
3209
-
3210
-    default:
3211
-      { assert(0); }
3212
-  }
3213
-
3214
- errLabel:
3215
-  return rc;
3216
-}
3217
-
3218 3331
 cmRC_t  _cmScModActivateEntries( cmScModulator* p, cmScModEntry_t* earray, unsigned* idxRef, unsigned cnt, unsigned scLocIdx );
3219 3332
 
3220 3333
 cmRC_t  _cmScModActivateGroup( cmScModulator* p, cmScModEntry_t* ep )
@@ -3231,6 +3344,49 @@ cmRC_t  _cmScModActivateGroup( cmScModulator* p, cmScModEntry_t* ep )
3231 3344
   return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Entry group '%s' not found.",cmSymTblLabel(p->stH,ep->beg.symId));    
3232 3345
 }
3233 3346
 
3347
+
3348
+cmRC_t _cmScModGetCrossParam( cmScModulator* p, cmScModEntry_t* ep, cmScModParam_t* pp, const cmChar_t* label, double* valRef )
3349
+{
3350
+  cmRC_t rc;
3351
+  
3352
+  if((rc = _cmScModGetParam(p, pp, valRef )) != cmOkRC )
3353
+    rc = cmCtxRtCondition( &p->obj, cmInvalidArgRC, "Invalid %s parameter for cross variable:%s",label,cmSymTblLabel(p->stH,ep->varPtr->varSymId) );
3354
+
3355
+  return rc;
3356
+  
3357
+}
3358
+
3359
+cmRC_t _cmScModExecCross( cmScModulator* p, cmScModEntry_t* ep )
3360
+{
3361
+  cmRC_t rc = cmOkRC;
3362
+  double x  = 0.0;
3363
+  //double x0 = 0.0, x1 = 0.0;
3364
+  double y0 = 0.0, y1 = 0.0;
3365
+
3366
+  if((rc = _cmScModGetCrossParam(p, ep, &ep->arg, "src var", &x )) != cmOkRC )
3367
+    return rc;
3368
+    
3369
+  //if((rc = _cmScModGetCrossParam(p, ep, &ep->beg, "src min", &x0 )) != cmOkRC )
3370
+  //  return rc;
3371
+
3372
+  //if((rc = _cmScModGetCrossParam(p, ep, &ep->end, "src max", &x1 )) != cmOkRC )
3373
+  //  return rc;
3374
+  
3375
+  if((rc = _cmScModGetCrossParam(p, ep, &ep->min, "dst min", &y0 )) != cmOkRC )
3376
+    return rc;
3377
+  
3378
+  if((rc = _cmScModGetCrossParam(p, ep, &ep->max, "dst max", &y1 )) != cmOkRC )
3379
+    return rc;
3380
+
3381
+  //double xx = x0 + (x-x0) / (x1-x0);
3382
+
3383
+  printf("%s x:%f y0:%f y1:%f\n",__FUNCTION__,x,y0,y1);
3384
+  
3385
+  ep->varPtr->value =  y0 + x * (y1-y0);
3386
+
3387
+  return rc;  
3388
+}
3389
+
3234 3390
 // Type specific variable activation - 
3235 3391
 cmRC_t _cmScModActivate(cmScModulator* p, cmScModEntry_t* ep )
3236 3392
 {
@@ -3277,6 +3433,12 @@ cmRC_t _cmScModActivate(cmScModulator* p, cmScModEntry_t* ep )
3277 3433
       rc = _cmScModActivateGroup(p,ep);
3278 3434
       break;
3279 3435
 
3436
+    case kInputModTId:
3437
+      break;
3438
+
3439
+    case kCrossModTId:
3440
+      break;
3441
+
3280 3442
     default:
3281 3443
       { assert(0); }
3282 3444
   }
@@ -3306,6 +3468,7 @@ cmRC_t  _cmScModExecSendValue( cmScModulator* p, cmScModVar_t* vp )
3306 3468
   return rc;
3307 3469
 }
3308 3470
 
3471
+// Execute a variable.
3309 3472
 // Return true if vp should be deactivated otherwise return false.
3310 3473
 bool  _cmScModExec( cmScModulator* p, cmScModVar_t* vp )
3311 3474
 {
@@ -3322,6 +3485,7 @@ bool  _cmScModExec( cmScModulator* p, cmScModVar_t* vp )
3322 3485
       
3323 3486
     case kSetModTId:
3324 3487
       {
3488
+        // Get a new value for the variable *vp.
3325 3489
         if((rc = _cmScModGetParam(p,&vp->entry->beg,&vp->value)) != cmOkRC )
3326 3490
           goto errLabel;
3327 3491
         
@@ -3343,6 +3507,7 @@ bool  _cmScModExec( cmScModulator* p, cmScModVar_t* vp )
3343 3507
         if((rc = _cmScModGetParam(p,&vp->entry->dur,&td)) != cmOkRC) 
3344 3508
           goto errLabel;
3345 3509
 
3510
+        // update the value of the var *vp
3346 3511
         double v  = vp->v0 + (v1-vp->v0) * (vp->phase * p->samplesPerCycle) / (p->srate * td);        
3347 3512
 
3348 3513
         if((fl =  (vp->value <= v1 && v >= v1) || (vp->value >= v1 && v <= v1 )) == true )
@@ -3360,6 +3525,16 @@ bool  _cmScModExec( cmScModulator* p, cmScModVar_t* vp )
3360 3525
       sendFl = false;
3361 3526
       break;
3362 3527
 
3528
+    case kInputModTId:
3529
+      sendFl = false;
3530
+      break;
3531
+      
3532
+    case kCrossModTId:
3533
+      _cmScModExecCross(p,vp->entry);
3534
+      vp->phase = 0; // force the value to be sent
3535
+      fl = true;
3536
+      break;
3537
+      
3363 3538
     default:
3364 3539
       { assert(0); }
3365 3540
   }
@@ -3451,58 +3626,13 @@ cmRC_t cmScModulatorExec( cmScModulator* p, unsigned scLocIdx )
3451 3626
 }
3452 3627
 
3453 3628
 
3454
-void _cmScModDumpParam( cmScModulator* p, const cmChar_t* label, cmScModParam_t* pp )
3455
-{
3456
-  printf("%s: ",label);
3457
-
3458
-  switch( pp->pid )
3459
-  {
3460
-    case kInvalidModPId:
3461
-      printf("<invalid>");
3462
-      break;
3463
-
3464
-    case kLiteralModPId:
3465
-      if( pp->val == DBL_MAX )
3466
-        printf("<max> ");
3467
-      else
3468
-        printf("%f ",pp->val);
3469
-      break;
3470
-
3471
-    case kSymbolModPId:
3472
-      printf("%s ",cmSymTblLabel(p->stH,pp->symId));
3473
-      break;
3474
-
3475
-    default:
3476
-      { assert(0); }
3477
-  }
3478
-}
3479
-
3480
-void _cmScModDumpVal( cmChar_t* label, double val )
3481
-{
3482
-  printf("%s:",label);
3483
-
3484
-  if( val == DBL_MAX )
3485
-    printf("<max> " );
3486
-  else
3487
-    printf("%f ",val);
3488
-}
3489
-
3490
-void _cmScModDumpVar( cmScModulator* p, const cmScModVar_t* vp )
3491
-{
3492
-    printf("%7s %3i fl:0x%x entry:%p alink:%p ",cmSymTblLabel(p->stH,vp->varSymId),vp->outVarId,vp->flags,vp->entry,vp->alink);
3493
-    _cmScModDumpVal("val",vp->value);
3494
-    _cmScModDumpVal("min",vp->min);
3495
-    _cmScModDumpVal("max",vp->max);
3496
-    _cmScModDumpVal("rate",vp->rate);
3497
-    _cmScModDumpVal("v0",vp->v0);
3498
-}
3499 3629
 
3500 3630
 cmRC_t  cmScModulatorDump(  cmScModulator* p )
3501 3631
 {
3502 3632
   cmRC_t rc = cmOkRC;
3503 3633
 
3504 3634
   printf("MOD:\n");
3505
-  printf("nei:%i alist:%p outVarCnt:%i\n",p->nei,p->alist,p->outVarCnt);
3635
+  printf("nei:%i alist:%p outVarCnt:%i inVarCnt:%i\n",p->nei,p->alist,p->outVarCnt,p->inVarCnt);
3506 3636
 
3507 3637
   printf("ENTRIES:\n");
3508 3638
   cmScModEntryGroup_t* g = p->glist;
@@ -3513,19 +3643,9 @@ cmRC_t  cmScModulatorDump(  cmScModulator* p )
3513 3643
     for(i=0; i<g->en; ++i)
3514 3644
     {
3515 3645
       cmScModEntry_t* ep = g->earray + i;
3516
-      const _cmScModTypeMap_t* tm = _cmScModTypeIdToMap( ep->typeId );
3517
-
3518 3646
       printf("%3i ",i);
3519
-
3520
-      printf("%10i ",ep->scLocIdx);
3521
-    
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");
3647
+      
3648
+      _cmScModDumpEntry(p,ep);
3529 3649
     }
3530 3650
   }
3531 3651
   

+ 33
- 9
cmProc4.h 查看文件

@@ -402,11 +402,21 @@ extern "C" {
402 402
 
403 403
   //( { label:cmScMod file_desc:"Store and recall parameter information under score follower control." kw:[proc] } 
404 404
   /*
405
+
406
+    File format:
407
+    {
408
+      entry_group_label :
409
+      [
410
+        <loc> <mod> <var> <type> <params>    // entry record
411
+      ]
412
+    }
413
+
414
+
405 415
     Syntax: <loc> <mod> <var> <type>   <params>
406 416
     <loc> - score location
407 417
     <mod> - name of the modulator 
408 418
     <var> - variable name 
409
-    <type> - type of operation
419
+    <type> - type of operation (see Types: note below)
410 420
 
411 421
     <params>
412 422
 
@@ -416,6 +426,7 @@ extern "C" {
416 426
     <val>  - type dependent value - see 'Types' below.  
417 427
     <end>  - ending value for a ramping variable
418 428
     <dur>  - determines the length of time to get to the ending value
429
+    <in>   - set to '1' to indicate that this is an input variable
419 430
 
420 431
     The value of parameters may be literal numeric values or may refer to
421 432
     variables by their name.
@@ -426,6 +437,8 @@ extern "C" {
426 437
     sline  = set <var> to <val> and ramp to <end> over <dur> seconds
427 438
     post   = send a 'post' msg after each transmission (can be used to change the cross-fader after each msg)
428 439
     exec   = execute the entry group <val>
440
+    input  = declare an 'input' variable and set its <min> and <max>.
441
+    cross  = generate an output value by interpolating between two preset values.
429 442
 
430 443
   */
431 444
   enum
@@ -436,13 +449,16 @@ extern "C" {
436 449
     kLineModTId,     // linear ramp variable to parray[0] over parray[1] seconds
437 450
     kSetLineModTId,  // set variable to parray[0] and ramp to parray[1] over parray[2] seconds
438 451
     kPostModTId,     //
439
-    kExecModTId      // execute an entry group 
452
+    kExecModTId,     // execute an entry group
453
+    kInputModTId,    // This is an 'input' variable.
454
+    kCrossModTId     // generate an output value by interpolating between two preset variable values
440 455
   };
441 456
 
442 457
   enum
443 458
   {
444 459
     kActiveModFl = 0x01,  // this variable is on the 'active' list
445
-    kCalcModFl   = 0x02   // when this variable is used as a parameter it's value must be calculated rather than used directly.
460
+    kCalcModFl   = 0x02,  // when this variable is used as a parameter it's value must be calculated rather than used directly.
461
+    kInputModFl  = 0x04   // this is an input variable
446 462
   };
447 463
 
448 464
   struct cmScModEntry_str;
@@ -461,11 +477,12 @@ extern "C" {
461 477
     double       val;     // value of literals
462 478
   } cmScModParam_t;
463 479
 
480
+  // cmScModVar_t is used to track the value of a variable.
464 481
   typedef struct cmScModVar_str
465 482
   {
466 483
     unsigned                 flags;    // see kXXXModFl flags above.
467 484
     unsigned                 varSymId; // variable name 
468
-    unsigned                 outVarId; // output var id
485
+    unsigned                 varId;    // var id
469 486
     double                   value;    // current value of this variable
470 487
     double                   v0;       // reserved internal variable
471 488
     unsigned                 phase;    // cycle phase since activation  
@@ -489,6 +506,7 @@ extern "C" {
489 506
     cmScModParam_t min;           // min value for this variable
490 507
     cmScModParam_t max;           // max value for this variable
491 508
     cmScModParam_t rate;          // update rate in milliseconds (DBL_MAX to disable)
509
+    cmScModParam_t arg;           // cross input variable
492 510
     cmScModVar_t*  varPtr;        // target variable 
493 511
   } cmScModEntry_t;
494 512
 
@@ -515,11 +533,12 @@ extern "C" {
515 533
     cmScModVar_t*   vlist;        // variable list
516 534
     cmScModVar_t*   alist;        // active variable list
517 535
     cmScModVar_t*   elist;        // last element on the active list
518
-    unsigned        nei;          // next entry index
536
+    unsigned        nei;          // next entry index in xlist->earray[] to examine for activation
519 537
     unsigned        outVarCnt;    // count of unique vars that are targets of entry recds
538
+    unsigned        inVarCnt;     
520 539
     bool            postFl;       // send a 'post' msg after each transmission
521
-    cmScModEntryGroup_t* xlist;
522
-    cmScModEntryGroup_t* glist;
540
+    cmScModEntryGroup_t* xlist;   // entry group to execute
541
+    cmScModEntryGroup_t* glist;   // entry group list
523 542
   } cmScModulator;
524 543
 
525 544
 
@@ -532,9 +551,14 @@ extern "C" {
532 551
   unsigned       cmScModulatorOutVarCount( cmScModulator* p );
533 552
 
534 553
   // Return a pointer to the variable at vlist[idx].
535
-  cmScModVar_t*  cmScModulatorOutVar( cmScModulator* p, unsigned idx ); 
554
+  cmScModVar_t*  cmScModulatorOutVar( cmScModulator* p, unsigned idx );
555
+
556
+  unsigned       cmScModulatorInVarCount( cmScModulator* p );
557
+  cmScModVar_t*  cmScModulatorInVar( cmScModulator* p, unsigned idx );
558
+  
536 559
 
537
-  cmRC_t         cmScModulatorSetValue( cmScModulator* p, unsigned varSymId, double value, double min, double max );
560
+  cmRC_t         cmScModulatorSetValueMinMax( cmScModulator* p, unsigned varSymId, double value, double min, double max );
561
+  cmRC_t         cmScModulatorSetValue(       cmScModulator* p, unsigned varSymId, double value );
538 562
 
539 563
   cmRC_t         cmScModulatorReset( cmScModulator* p, cmCtx_t* ctx, unsigned scLocIdx, unsigned entryGroupSymId );
540 564
   cmRC_t         cmScModulatorExec(  cmScModulator* p, unsigned scLocIdx );

+ 39
- 14
dsp/cmDspKr.c 查看文件

@@ -1307,6 +1307,7 @@ void _cmScFolMatcherCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
1307 1307
         cmDsvSetDouble(&vv,ap->sfp->smp->set[i].value);
1308 1308
         cmDsvSetDouble(&cv,ap->sfp->smp->set[i].match_cost);
1309 1309
 
1310
+               
1310 1311
         for(j=0; j<ap->sfp->smp->set[i].sp->sectCnt; ++j)
1311 1312
         {
1312 1313
           cmDspStoreSetValueViaSym(ap->ctx->dsH, ap->sfp->smp->set[i].sp->symArray[j], &vv );
@@ -1381,7 +1382,7 @@ cmDspRC_t _cmDspScFolReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
1381 1382
   cmDspRC_t     rc;
1382 1383
   if((rc = cmDspApplyAllDefaults(ctx,inst)) != kOkDspRC )
1383 1384
     return rc;
1384
-
1385
+  
1385 1386
   return _cmDspScFolOpenScore(ctx,inst);
1386 1387
 }
1387 1388
 
@@ -1499,6 +1500,10 @@ typedef struct
1499 1500
   unsigned       offSymId;
1500 1501
   unsigned       postSymId;
1501 1502
   unsigned       dumpSymId;
1503
+  unsigned       minInVarId;
1504
+  unsigned       maxInVarId;
1505
+  unsigned*      inVarIdMap;
1506
+  unsigned       inVarIdOffs;
1502 1507
 } cmDspScMod_t;
1503 1508
 
1504 1509
 void _cmDspScModCb( void* arg, unsigned varSymId, double value, bool postFl )
@@ -1560,33 +1565,45 @@ cmDspInst_t*  _cmDspScModAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
1560 1565
     return NULL;
1561 1566
   }
1562 1567
   unsigned      fixArgCnt = sizeof(args)/sizeof(args[0]) - 1;
1563
-  unsigned      argCnt    = fixArgCnt + cmScModulatorOutVarCount(mp);
1568
+  unsigned      outVarCnt = cmScModulatorOutVarCount(mp);
1569
+  unsigned      inVarCnt  = cmScModulatorInVarCount(mp);
1570
+  unsigned      argCnt    = fixArgCnt + inVarCnt + outVarCnt;
1564 1571
   cmDspVarArg_t a[ argCnt+1 ];
1565 1572
   unsigned      i;
1566
-
1573
+  unsigned*     inVarIdMap = cmMemAllocZ( unsigned, inVarCnt );
1567 1574
   cmDspArgCopy( a, argCnt, 0, args, fixArgCnt );
1568 1575
 
1569 1576
   for(i=fixArgCnt; i<argCnt; ++i)
1570 1577
   {
1571
-    unsigned            varIdx    = i - fixArgCnt;
1572
-    const cmScModVar_t* vp        = cmScModulatorOutVar(mp,varIdx);
1578
+    unsigned            inVarIdx  = i - fixArgCnt;
1579
+    unsigned            outVarIdx = inVarIdx - inVarCnt; 
1580
+    bool                inputFl   = inVarIdx < inVarCnt;
1581
+    const cmScModVar_t* vp        = inputFl ? cmScModulatorInVar(mp,inVarIdx) : cmScModulatorOutVar(mp,outVarIdx);
1573 1582
     const cmChar_t*     label     = cmSymTblLabel( ctx->stH, vp->varSymId );
1574
-    const cmChar_t*     docStr    = cmTsPrintfS("Variable output for %s",label);
1583
+    const cmChar_t*     docStr    = cmTsPrintfS("Variable %s for %s",inputFl?"input":"output",label);
1584
+    unsigned            flags     = inputFl ? kInDsvFl : kOutDsvFl;
1585
+
1586
+    if( inputFl )
1587
+      inVarIdMap[ inVarIdx ] = vp->varSymId;
1575 1588
 
1576
-    cmDspArgSetup(ctx, a + i, label, cmInvalidId, i, 0, 0, kOutDsvFl | kDoubleDsvFl, docStr ); 
1589
+    cmDspArgSetup(ctx, a + i, label, cmInvalidId, i, 0, 0, flags | kDoubleDsvFl, docStr ); 
1577 1590
   }
1578 1591
   cmDspArgSetupNull(a+argCnt); // set terminating arg. flags
1579 1592
 
1580 1593
   cmDspScMod_t* p = cmDspInstAlloc(cmDspScMod_t,ctx,classPtr,a,instSymId,id,storeSymId,va_cnt,vl);
1581 1594
 
1582 1595
 
1583
-  p->fn       = cmMemAllocStr(fn);
1584
-  p->modLabel = cmMemAllocStr(modLabel);
1585
-  p->mp       = mp;
1586
-  p->onSymId  = cmSymTblId(ctx->stH,"on");
1587
-  p->offSymId = cmSymTblId(ctx->stH,"off");
1588
-  p->postSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"post");
1589
-  p->dumpSymId = cmSymTblId(ctx->stH,"dump");
1596
+  p->fn          = cmMemAllocStr(fn);
1597
+  p->modLabel    = cmMemAllocStr(modLabel);
1598
+  p->mp          = mp;
1599
+  p->onSymId     = cmSymTblId(ctx->stH,"on");
1600
+  p->offSymId    = cmSymTblId(ctx->stH,"off");
1601
+  p->postSymId   = cmSymTblRegisterStaticSymbol(ctx->stH,"post");
1602
+  p->dumpSymId   = cmSymTblId(ctx->stH,"dump");
1603
+  p->minInVarId  = fixArgCnt;
1604
+  p->maxInVarId  = p->minInVarId + inVarCnt - 1;
1605
+  p->inVarIdMap  = inVarIdMap;
1606
+  p->inVarIdOffs = fixArgCnt;
1590 1607
 
1591 1608
   mp->cbArg = p;  // set the modulator callback arg
1592 1609
 
@@ -1609,6 +1626,7 @@ cmDspRC_t _cmDspScModFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
1609 1626
 
1610 1627
   cmMemFree(p->fn);
1611 1628
   cmMemFree(p->modLabel);
1629
+  cmMemFree(p->inVarIdMap);
1612 1630
   return rc;
1613 1631
 }
1614 1632
 
@@ -1627,6 +1645,13 @@ cmDspRC_t _cmDspScModRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
1627 1645
   cmDspScMod_t* p  = (cmDspScMod_t*)inst;
1628 1646
 
1629 1647
   cmDspSetEvent(ctx,inst,evt);
1648
+
1649
+  if( p->minInVarId <= evt->dstVarId && evt->dstVarId <= p->maxInVarId )
1650
+  {
1651
+    double v = cmDspDouble(inst,evt->dstVarId);
1652
+    printf("%s : %i %f\n",__FUNCTION__,evt->dstVarId,v);
1653
+    cmScModulatorSetValue( p->mp, p->inVarIdMap[ evt->dstVarId - p->inVarIdOffs ], v );
1654
+  }
1630 1655
   
1631 1656
   switch( evt->dstVarId )
1632 1657
   {

Loading…
取消
儲存