Explorar el Código

cmDspFx.h/c Initial code for cmAvailCh DSP object.

master
kevin hace 12 años
padre
commit
a659c4a2bf
Se han modificado 2 ficheros con 123 adiciones y 0 borrados
  1. 122
    0
      dsp/cmDspFx.c
  2. 1
    0
      dsp/cmDspFx.h

+ 122
- 0
dsp/cmDspFx.c Ver fichero

@@ -5653,6 +5653,128 @@ struct cmDspClass_str* cmRouterClassCons( cmDspCtx_t* ctx )
5653 5653
   return &_cmRouter_DC;
5654 5654
 }
5655 5655
 
5656
+//==========================================================================================================================================
5657
+enum
5658
+{
5659
+  kChCntAvId,
5660
+  kTrigAvId,
5661
+  kChIdxAvId,  
5662
+  kBaseInDisAvId,
5663
+};
5664
+
5665
+cmDspClass_t _cmAvailCh_DC;
5666
+
5667
+typedef struct
5668
+{
5669
+  cmDspInst_t   inst;
5670
+  unsigned      chCnt;
5671
+  unsigned      baseOutEnaAvId; 
5672
+  unsigned      baseInDisAvId;
5673
+  unsigned      enableSymId;
5674
+  unsigned      disableSymId;
5675
+  bool*         stateArray;
5676
+} cmDspAvailCh_t;
5677
+
5678
+cmDspInst_t*  _cmDspAvailCh_Alloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
5679
+{
5680
+  if( va_cnt < 1 )
5681
+  {
5682
+    cmDspClassErr(ctx,classPtr,kVarArgParseFailDspRC,"The 'AvailCh' constructor must be given an channel count.");
5683
+    return NULL;
5684
+  }
5685
+
5686
+  va_list vl1;
5687
+  va_copy(vl1,vl);
5688
+
5689
+  int     chCnt            = va_arg(vl,int);
5690
+
5691
+  if( chCnt <= 0 )
5692
+  {
5693
+    cmDspClassErr(ctx,classPtr,kInvalidArgDspRC,"The 'AvailCh' constructor must be given a positive channel count.");
5694
+    return NULL;
5695
+  }
5696
+
5697
+  unsigned baseInDisAvId     = kBaseInDisAvId;
5698
+  unsigned baseOutEnaAvId    = baseInDisAvId + chCnt;
5699
+
5700
+  cmDspAvailCh_t* p = cmDspInstAllocV(cmDspAvailCh_t,ctx,classPtr,instSymId,id,storeSymId,va_cnt,vl1,
5701
+    1,         "chs",    kChCntAvId,        0, 0, kUIntDsvFl     | kReqArgDsvFl,  "Channel count.",
5702
+    1,         "trig",   kTrigAvId,         0, 0, kTypeDsvMask   | kInDsvFl,      "Trigger the unit to select the next available channel.", 
5703
+    1,         "ch",     kChIdxAvId,        0, 0, kUIntDsvFl     | kReqArgDsvFl | kInDsvFl,    "Currently selected channel.",
5704
+    chCnt,     "dis",    baseInDisAvId,     0, 0, kTypeDsvMask   | kInDsvFl,     "Disable inputs.",
5705
+    chCnt,     "ena",    baseOutEnaAvId,    0, 0, kSymDsvFl      | kOutDsvFl,    "'enable' outputs",
5706
+    0 );
5707
+
5708
+  p->chCnt     = chCnt;
5709
+
5710
+  p->baseInDisAvId   =  baseInDisAvId;
5711
+  p->baseOutEnaAvId  =  baseOutEnaAvId;
5712
+  p->enableSymId     =  cmSymTblRegisterStaticSymbol(ctx->stH,"enable");
5713
+  p->disableSymId    =  cmSymTblRegisterStaticSymbol(ctx->stH,"disable");
5714
+
5715
+  unsigned i;
5716
+  for(i=0; i<chCnt; ++i)
5717
+    cmDspSetDefaultSymbol( ctx, &p->inst, baseOutEnaAvId+i, p->disableSymId );
5718
+
5719
+  cmDspSetDefaultUInt( ctx, &p->inst, kChIdxAvId, 0, cmInvalidIdx );
5720
+
5721
+  return &p->inst;
5722
+}
5723
+
5724
+cmDspRC_t _cmDspAvailCh_Free(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5725
+{
5726
+  return kOkDspRC;
5727
+}
5728
+
5729
+cmDspRC_t _cmDspAvailCh_Reset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5730
+{
5731
+  return cmDspApplyAllDefaults(ctx,inst);
5732
+}
5733
+
5734
+
5735
+cmDspRC_t _cmDspAvailCh_Recv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5736
+{ 
5737
+  cmDspRC_t    rc = kOkDspRC;
5738
+  cmDspAvailCh_t* p  = (cmDspAvailCh_t*)inst;
5739
+
5740
+  // if this is a trigger
5741
+  if( evt->dstVarId == kTrigAvId )
5742
+  {
5743
+    unsigned i;
5744
+    for(i=0; i<p->chCnt; ++i)
5745
+      if( cmDspSymbol(inst,p->baseOutEnaAvId+i) == p->disableSymId )
5746
+      {
5747
+        cmDspSetUInt(ctx,inst,kChIdxAvId,i);
5748
+        cmDspSetSymbol(ctx,inst,p->baseOutEnaAvId,p->enableSymId);
5749
+      }
5750
+    return rc;
5751
+  }
5752
+
5753
+  // if this is an incoming disable message.
5754
+  if( p->baseInDisAvId <= evt->dstVarId && evt->dstVarId < p->baseInDisAvId+p->chCnt )
5755
+  {
5756
+    cmDspSetSymbol(ctx,inst,p->baseOutEnaAvId,p->disableSymId);
5757
+    return rc;
5758
+  }
5759
+
5760
+  return rc;
5761
+}
5762
+
5763
+struct cmDspClass_str* cmAvailChClassCons( cmDspCtx_t* ctx )
5764
+{
5765
+  cmDspClassSetup(&_cmAvailCh_DC,ctx,"AvailCh",
5766
+    NULL,
5767
+    _cmDspAvailCh_Alloc,
5768
+    _cmDspAvailCh_Free,
5769
+    _cmDspAvailCh_Reset,
5770
+    NULL,
5771
+    _cmDspAvailCh_Recv,
5772
+    NULL,NULL,
5773
+    "Enable the next availabled channel");
5774
+
5775
+  return &_cmAvailCh_DC;
5776
+}
5777
+
5656 5778
  
5657 5779
 //==========================================================================================================================================
5658 5780
  

+ 1
- 0
dsp/cmDspFx.h Ver fichero

@@ -37,6 +37,7 @@ extern "C" {
37 37
   struct cmDspClass_str* cmGateToSymClassCons(  cmDspCtx_t* ctx );
38 38
   struct cmDspClass_str* cmPortToSymClassCons(  cmDspCtx_t* ctx );
39 39
   struct cmDspClass_str* cmRouterClassCons(     cmDspCtx_t* ctx );
40
+  struct cmDspClass_str* cmAvailChClassCons(    cmDspCtx_t* ctx );
40 41
   struct cmDspClass_str* cmPresetClassCons(     cmDspCtx_t* ctx );
41 42
   struct cmDspClass_str* cmBcastSymClassCons(   cmDspCtx_t* ctx );
42 43
   struct cmDspClass_str* cmSegLineClassCons(    cmDspCtx_t* ctx );

Loading…
Cancelar
Guardar