Browse Source

cmDspBuiltIn.c,cmDspKr.h/c:Inital development of cmActiveMeas in cmDspKr.c.

master
kpl 11 years ago
parent
commit
4576de0263
3 changed files with 225 additions and 1 deletions
  1. 1
    1
      dsp/cmDspBuiltIn.c
  2. 223
    0
      dsp/cmDspKr.c
  3. 1
    0
      dsp/cmDspKr.h

+ 1
- 1
dsp/cmDspBuiltIn.c View File

@@ -5370,7 +5370,7 @@ cmDspClassConsFunc_t _cmDspClassBuiltInArray[] =
5370 5370
   cmScModClassCons,
5371 5371
   cmGSwitchClassCons,
5372 5372
   cmScaleRangeClassCons,
5373
-
5373
+  cmActiveMeasClassCons,
5374 5374
   NULL,
5375 5375
 };
5376 5376
 

+ 223
- 0
dsp/cmDspKr.c View File

@@ -1621,3 +1621,226 @@ struct cmDspClass_str* cmScaleRangeClassCons( cmDspCtx_t* ctx )
1621 1621
 
1622 1622
   return &_cmScaleRangeDC;
1623 1623
 }
1624
+
1625
+
1626
+//==========================================================================================================================================
1627
+
1628
+enum
1629
+{
1630
+  kCntAmId,
1631
+  kSflocAmId,
1632
+  kLocAmId,
1633
+  kTypeAmId,
1634
+  kValueAmId,
1635
+  kCstAmId,
1636
+  kCmdAmId,
1637
+  kEvenAmId,
1638
+  kDynAmId,
1639
+  kTempoAmId,
1640
+  kCostAmId
1641
+};
1642
+
1643
+cmDspClass_t _cmActiveMeasDC;
1644
+
1645
+typedef struct
1646
+{
1647
+  unsigned loc;
1648
+  unsigned type;
1649
+  double   value;
1650
+  double   cost;
1651
+} cmDspActiveMeasRecd_t;
1652
+
1653
+int cmDspActiveMeasRecdCompare(const void * p0, const void * p1)
1654
+{
1655
+  return ((int)((cmDspActiveMeasRecd_t*)p0)->loc) - (int)(((cmDspActiveMeasRecd_t*)p1)->loc);
1656
+}
1657
+
1658
+typedef struct
1659
+{
1660
+  cmDspInst_t            inst;
1661
+  unsigned               addSymId;
1662
+  unsigned               clearSymId;
1663
+  unsigned               printSymId;    
1664
+  cmDspActiveMeasRecd_t* array; // array[cnt]
1665
+  unsigned               cnt;   
1666
+  unsigned               nextEmptyIdx;
1667
+  unsigned               nextFullIdx;
1668
+} cmDspActiveMeas_t;
1669
+
1670
+cmDspInst_t*  _cmDspActiveMeasAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
1671
+{
1672
+
1673
+  cmDspVarArg_t args[] =
1674
+  {
1675
+    { "cnt",      kCntAmId,      0,0, kInDsvFl  | kUIntDsvFl,    "Maximum count of active measurements."},
1676
+    { "sfloc",    kSflocAmId,    0,0, kInDsvFl  | kUIntDsvFl,    "Score follower location input." },
1677
+    { "loc",      kLocAmId,      0,0, kInDsvFl  | kUIntDsvFl,    "Meas. location." },
1678
+    { "type",     kTypeAmId,     0,0, kInDsvFl  | kUIntDsvFl,    "Meas. Type." },
1679
+    { "val",      kValueAmId,    0,0, kInDsvFl  | kDoubleDsvFl,  "Meas. Value."},
1680
+    { "cst",      kCstAmId,      0,0, kInDsvFl  | kDoubleDsvFl,  "Meas. Cost."},
1681
+    { "cmd",      kCmdAmId,      0,0, kInDsvFl  | kSymDsvFl,     "Commands:add | clear | print"}, 
1682
+    { "even",     kEvenAmId,     0,0, kOutDsvFl | kDoubleDsvFl,  "Even out"},
1683
+    { "dyn",      kDynAmId,      0,0, kOutDsvFl | kDoubleDsvFl,  "Dyn out"},
1684
+    { "tempo",    kTempoAmId,    0,0, kOutDsvFl | kDoubleDsvFl,  "Tempo out"},
1685
+    { "cost",     kCostAmId,     0,0, kOutDsvFl | kDoubleDsvFl,  "Cost out"},
1686
+    { NULL, 0, 0, 0, 0 }
1687
+  };
1688
+
1689
+
1690
+
1691
+  cmDspActiveMeas_t* p = cmDspInstAlloc(cmDspActiveMeas_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
1692
+
1693
+  p->addSymId   = cmSymTblRegisterStaticSymbol(ctx->stH,"add");
1694
+  p->clearSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"clear");
1695
+  p->printSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"print");
1696
+
1697
+  cmDspSetDefaultUInt(  ctx,&p->inst,kCntAmId,  0,100);
1698
+  cmDspSetDefaultDouble(ctx,&p->inst,kEvenAmId, 0,0);
1699
+  cmDspSetDefaultDouble(ctx,&p->inst,kDynAmId,  0,0);
1700
+  cmDspSetDefaultDouble(ctx,&p->inst,kTempoAmId,0,0);
1701
+  cmDspSetDefaultDouble(ctx,&p->inst,kTempoAmId,0,0);
1702
+
1703
+
1704
+  return &p->inst;
1705
+}
1706
+
1707
+cmDspRC_t _cmDspActiveMeasPrint(cmDspCtx_t* ctx, cmDspActiveMeas_t* p )
1708
+{
1709
+  unsigned i;
1710
+  for(i=0; i<p->nextEmptyIdx; ++i)
1711
+  {
1712
+    const cmChar_t* label = "<null>";
1713
+    switch( p->array[i].type )
1714
+    {
1715
+      case kEvenVarScId:    label="even "; break;
1716
+      case kDynVarScId:     label="dyn  "; break;
1717
+      case kTempoVarScId:   label="tempo"; break;
1718
+      default:
1719
+        { assert(0); }
1720
+    }
1721
+
1722
+    cmRptPrintf(ctx->rpt,"loc:%i %s %f %f\n",p->array[i].loc,label,p->array[i].value,p->array[i].cost);
1723
+  }
1724
+
1725
+  return kOkDspRC;
1726
+}
1727
+
1728
+cmDspRC_t _cmDspActiveMeasClear(cmDspCtx_t* ctx, cmDspActiveMeas_t* p )
1729
+{
1730
+  p->nextEmptyIdx = 0;
1731
+  p->nextFullIdx  = cmInvalidIdx;
1732
+  return kOkDspRC;
1733
+}
1734
+
1735
+cmDspRC_t _cmDspActiveMeasFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
1736
+{
1737
+  cmDspActiveMeas_t* p  = (cmDspActiveMeas_t*)inst;
1738
+  _cmDspActiveMeasClear(ctx,p);
1739
+  cmMemPtrFree(&p->array);
1740
+  return kOkDspRC;
1741
+}
1742
+
1743
+cmDspRC_t _cmDspActiveMeasReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
1744
+{
1745
+  cmDspRC_t          rc = kOkDspRC;
1746
+  cmDspActiveMeas_t* p  = (cmDspActiveMeas_t*)inst;
1747
+
1748
+  cmDspApplyAllDefaults(ctx,inst);
1749
+
1750
+  unsigned cnt = cmMax(100,cmDspUInt(inst,kCntAmId));
1751
+  _cmDspActiveMeasFree(ctx,inst,evt);
1752
+  p->array = cmMemAllocZ(cmDspActiveMeasRecd_t,cnt);
1753
+  p->cnt   = cnt;
1754
+  return rc;
1755
+}
1756
+
1757
+cmDspRC_t _cmDspActiveMeasRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
1758
+{
1759
+  cmDspRC_t       rc = kOkDspRC;
1760
+  cmDspActiveMeas_t* p  = (cmDspActiveMeas_t*)inst;
1761
+
1762
+  cmDspSetEvent(ctx,inst,evt);
1763
+
1764
+  switch( evt->dstVarId )
1765
+  {
1766
+    case kSflocAmId:
1767
+      if( p->nextFullIdx != cmInvalidIdx )
1768
+      {
1769
+        unsigned sflocIdx = cmDspUInt(inst,kSflocAmId);
1770
+        for(; p->nextFullIdx < p->nextEmptyIdx; p->nextFullIdx++)
1771
+        {
1772
+          cmDspActiveMeasRecd_t* r = p->array + p->nextFullIdx;
1773
+          if( r->loc > sflocIdx )
1774
+            break;
1775
+
1776
+          unsigned varId = cmInvalidId;
1777
+          switch( r->type )
1778
+          {
1779
+            case kEvenVarScId:   varId = kEvenAmId;  break;
1780
+            case kDynVarScId:    varId = kDynAmId;   break;
1781
+            case kTempoVarScId:  varId = kTempoAmId; break;
1782
+            default:
1783
+              { assert(0); }
1784
+          }
1785
+
1786
+          cmDspSetDouble(ctx,inst,varId,r->value);
1787
+          cmDspSetDouble(ctx,inst,kCostAmId,r->value);
1788
+        } 
1789
+        
1790
+
1791
+      }
1792
+      break;
1793
+
1794
+    case kCmdAmId:
1795
+      {
1796
+        unsigned cmdSymId = cmDspSymbol(inst,kCmdAmId);
1797
+
1798
+        if( cmdSymId == p->addSymId )
1799
+        {
1800
+          if( p->nextEmptyIdx >= p->cnt )
1801
+            cmDspInstErr(ctx,inst,kProcFailDspRC,"The active measurement list is full cnt=%i.",p->cnt);
1802
+          else
1803
+          {
1804
+            cmDspActiveMeasRecd_t* r = p->array + p->nextEmptyIdx;
1805
+            r->loc   = cmDspUInt(  inst,kLocAmId);
1806
+            r->type  = cmDspUInt(  inst,kTypeAmId);
1807
+            r->value = cmDspDouble(inst,kValueAmId);
1808
+            r->cost  = cmDspDouble(inst,kCstAmId);
1809
+            p->nextEmptyIdx += 1;
1810
+
1811
+            qsort(p->array,p->nextEmptyIdx,sizeof(p->array[0]),cmDspActiveMeasRecdCompare);
1812
+
1813
+            if( p->nextEmptyIdx == 1 && p->nextFullIdx == cmInvalidIdx )
1814
+              p->nextFullIdx = 0;
1815
+
1816
+          }
1817
+        }
1818
+          
1819
+        if( cmdSymId == p->clearSymId )
1820
+          rc = _cmDspActiveMeasClear(ctx,p);
1821
+        else
1822
+          if( cmdSymId == p->printSymId )
1823
+            rc = _cmDspActiveMeasPrint(ctx,p);
1824
+      }
1825
+      break;
1826
+
1827
+  }
1828
+  return rc;
1829
+}
1830
+
1831
+
1832
+struct cmDspClass_str* cmActiveMeasClassCons( cmDspCtx_t* ctx )
1833
+{
1834
+  cmDspClassSetup(&_cmActiveMeasDC,ctx,"ActiveMeas",
1835
+    NULL,
1836
+    _cmDspActiveMeasAlloc,
1837
+    _cmDspActiveMeasFree,
1838
+    _cmDspActiveMeasReset,
1839
+    NULL,
1840
+    _cmDspActiveMeasRecv,
1841
+    NULL,NULL,
1842
+    "Scale a value inside an input range to a value in the output range.");
1843
+
1844
+  return &_cmActiveMeasDC;
1845
+}
1846
+

+ 1
- 0
dsp/cmDspKr.h View File

@@ -13,6 +13,7 @@ extern "C" {
13 13
   struct cmDspClass_str* cmScModClassCons( cmDspCtx_t* ctx );
14 14
   struct cmDspClass_str* cmGSwitchClassCons( cmDspCtx_t* ctx );
15 15
   struct cmDspClass_str* cmScaleRangeClassCons( cmDspCtx_t* ctx );
16
+  struct cmDspClass_str* cmActiveMeasClassCons( cmDspCtx_t* ctx );
16 17
 
17 18
 #ifdef __cplusplus
18 19
 }

Loading…
Cancel
Save