|
@@ -1699,18 +1699,22 @@ enum
|
1699
|
1699
|
|
1700
|
1700
|
cmDspClass_t _cmActiveMeasDC;
|
1701
|
1701
|
|
1702
|
|
-typedef struct
|
|
1702
|
+typedef struct cmDspAmRecd_str
|
1703
|
1703
|
{
|
1704
|
1704
|
unsigned loc;
|
1705
|
1705
|
unsigned type;
|
1706
|
1706
|
double value;
|
1707
|
1707
|
double cost;
|
1708
|
|
-} cmDspActiveMeasRecd_t;
|
|
1708
|
+ struct cmDspAmRecd_str* link;
|
|
1709
|
+} cmDspAmRecd_t;
|
|
1710
|
+
|
1709
|
1711
|
|
|
1712
|
+/*
|
1710
|
1713
|
int cmDspActiveMeasRecdCompare(const void * p0, const void * p1)
|
1711
|
1714
|
{
|
1712
|
1715
|
return ((int)((cmDspActiveMeasRecd_t*)p0)->loc) - (int)(((cmDspActiveMeasRecd_t*)p1)->loc);
|
1713
|
1716
|
}
|
|
1717
|
+*/
|
1714
|
1718
|
|
1715
|
1719
|
typedef struct
|
1716
|
1720
|
{
|
|
@@ -1719,12 +1723,90 @@ typedef struct
|
1719
|
1723
|
unsigned clearSymId;
|
1720
|
1724
|
unsigned printSymId;
|
1721
|
1725
|
unsigned rewindSymId;
|
1722
|
|
- cmDspActiveMeasRecd_t* array; // array[cnt]
|
1723
|
|
- unsigned cnt;
|
1724
|
|
- unsigned nextEmptyIdx;
|
1725
|
|
- unsigned nextFullIdx;
|
|
1726
|
+ cmDspAmRecd_t* array; // array[cnt]
|
|
1727
|
+ unsigned cnt;
|
|
1728
|
+ cmDspAmRecd_t* list; // first recd in list sorted on 'loc'.
|
|
1729
|
+ cmDspAmRecd_t* avail; // next empty recd
|
|
1730
|
+ cmDspAmRecd_t* sent; // last recd sent
|
1726
|
1731
|
} cmDspActiveMeas_t;
|
1727
|
1732
|
|
|
1733
|
+void _cmDspAmAllocList( cmDspActiveMeas_t* p, unsigned cnt )
|
|
1734
|
+{
|
|
1735
|
+ assert(p->array == NULL );
|
|
1736
|
+
|
|
1737
|
+ cmDspAmRecd_t* r = cmMemAllocZ(cmDspAmRecd_t,cnt);
|
|
1738
|
+
|
|
1739
|
+ p->cnt = cnt;
|
|
1740
|
+ p->array = r;
|
|
1741
|
+ p->list = NULL;
|
|
1742
|
+ p->avail = r;
|
|
1743
|
+ p->sent = NULL;
|
|
1744
|
+}
|
|
1745
|
+
|
|
1746
|
+
|
|
1747
|
+cmDspRC_t _cmDspActiveMeasAdd( cmDspCtx_t* ctx, cmDspActiveMeas_t* p, unsigned loc, unsigned type, double value, double cost)
|
|
1748
|
+{
|
|
1749
|
+ assert( type != kInvalidVarScId );
|
|
1750
|
+
|
|
1751
|
+ cmDspAmRecd_t* rp = p->list;
|
|
1752
|
+ cmDspAmRecd_t* pp = NULL;
|
|
1753
|
+
|
|
1754
|
+
|
|
1755
|
+ // search for the location to add the new record
|
|
1756
|
+ for(; rp!=NULL; rp=rp->link)
|
|
1757
|
+ {
|
|
1758
|
+ // if this loc and type already exists then replace the value and cost fields
|
|
1759
|
+ if( rp->loc==loc && rp->type==type )
|
|
1760
|
+ goto foundLabel;
|
|
1761
|
+
|
|
1762
|
+ // if this loc should be inserted before rp
|
|
1763
|
+ if( loc < rp->loc )
|
|
1764
|
+ break;
|
|
1765
|
+
|
|
1766
|
+ pp = rp;
|
|
1767
|
+ }
|
|
1768
|
+
|
|
1769
|
+ // if the pre-allocated list is full
|
|
1770
|
+ if( p->avail >= p->array+p->cnt )
|
|
1771
|
+ return cmDspInstErr(ctx,&p->inst,kInvalidArgDspRC,"Unable to store new measurement record. All preallocated active measurement slots are in use.");
|
|
1772
|
+
|
|
1773
|
+
|
|
1774
|
+ // if prepending to the list
|
|
1775
|
+ if( pp == NULL )
|
|
1776
|
+ {
|
|
1777
|
+ rp = p->avail;
|
|
1778
|
+ rp->link = p->list;
|
|
1779
|
+ p->list = rp;
|
|
1780
|
+ }
|
|
1781
|
+ else
|
|
1782
|
+ {
|
|
1783
|
+ // if appending to the list after pp
|
|
1784
|
+ if( rp == NULL )
|
|
1785
|
+ {
|
|
1786
|
+ // nothing to do
|
|
1787
|
+ }
|
|
1788
|
+ else // if inserting between pp and rp
|
|
1789
|
+ {
|
|
1790
|
+ p->avail->link = rp;
|
|
1791
|
+ }
|
|
1792
|
+
|
|
1793
|
+ rp = p->avail;
|
|
1794
|
+ pp->link = rp;
|
|
1795
|
+
|
|
1796
|
+ }
|
|
1797
|
+
|
|
1798
|
+ p->avail += 1;
|
|
1799
|
+
|
|
1800
|
+ foundLabel:
|
|
1801
|
+ rp->loc = loc;
|
|
1802
|
+ rp->type = type;
|
|
1803
|
+ rp->value = value;
|
|
1804
|
+ rp->cost = cost;
|
|
1805
|
+
|
|
1806
|
+ return kOkDspRC;
|
|
1807
|
+}
|
|
1808
|
+
|
|
1809
|
+
|
1728
|
1810
|
cmDspInst_t* _cmDspActiveMeasAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
1729
|
1811
|
{
|
1730
|
1812
|
|
|
@@ -1733,7 +1815,7 @@ cmDspInst_t* _cmDspActiveMeasAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, uns
|
1733
|
1815
|
{ "cnt", kCntAmId, 0,0, kInDsvFl | kUIntDsvFl, "Maximum count of active measurements."},
|
1734
|
1816
|
{ "sfloc", kSflocAmId, 0,0, kInDsvFl | kUIntDsvFl, "Score follower location input." },
|
1735
|
1817
|
{ "loc", kLocAmId, 0,0, kInDsvFl | kUIntDsvFl, "Meas. location." },
|
1736
|
|
- { "type", kTypeAmId, 0,0, kInDsvFl | kUIntDsvFl, "Meas. Type." },
|
|
1818
|
+ { "type", kTypeAmId, 0,0, kInDsvFl | kUIntDsvFl, "Meas. Type. (even,dyn,...)" },
|
1737
|
1819
|
{ "val", kValueAmId, 0,0, kInDsvFl | kDoubleDsvFl, "Meas. Value."},
|
1738
|
1820
|
{ "cst", kCstAmId, 0,0, kInDsvFl | kDoubleDsvFl, "Meas. Cost."},
|
1739
|
1821
|
{ "cmd", kCmdAmId, 0,0, kInDsvFl | kSymDsvFl, "Commands:add | clear | dump | rewind"},
|
|
@@ -1754,24 +1836,23 @@ cmDspInst_t* _cmDspActiveMeasAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, uns
|
1754
|
1836
|
p->printSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"dump");
|
1755
|
1837
|
p->rewindSymId= cmSymTblRegisterStaticSymbol(ctx->stH,"rewind");
|
1756
|
1838
|
|
1757
|
|
- cmDspSetDefaultUInt( ctx,&p->inst,kCntAmId, 0,100);
|
|
1839
|
+ cmDspSetDefaultUInt( ctx,&p->inst,kCntAmId, 0,256);
|
1758
|
1840
|
cmDspSetDefaultUInt( ctx,&p->inst,kScLocAmId,0,0);
|
1759
|
1841
|
cmDspSetDefaultDouble(ctx,&p->inst,kEvenAmId, 0,0);
|
1760
|
1842
|
cmDspSetDefaultDouble(ctx,&p->inst,kDynAmId, 0,0);
|
1761
|
1843
|
cmDspSetDefaultDouble(ctx,&p->inst,kTempoAmId,0,0);
|
1762
|
1844
|
cmDspSetDefaultDouble(ctx,&p->inst,kTempoAmId,0,0);
|
1763
|
1845
|
|
1764
|
|
-
|
1765
|
1846
|
return &p->inst;
|
1766
|
1847
|
}
|
1767
|
1848
|
|
1768
|
1849
|
cmDspRC_t _cmDspActiveMeasPrint(cmDspCtx_t* ctx, cmDspActiveMeas_t* p )
|
1769
|
1850
|
{
|
1770
|
|
- unsigned i;
|
1771
|
|
- for(i=0; i<p->nextEmptyIdx; ++i)
|
|
1851
|
+ cmDspAmRecd_t* rp = p->list;
|
|
1852
|
+ for(; rp!=NULL; rp=rp->link)
|
1772
|
1853
|
{
|
1773
|
1854
|
const cmChar_t* label = "<null>";
|
1774
|
|
- switch( p->array[i].type )
|
|
1855
|
+ switch( rp->type )
|
1775
|
1856
|
{
|
1776
|
1857
|
case kEvenVarScId: label="even "; break;
|
1777
|
1858
|
case kDynVarScId: label="dyn "; break;
|
|
@@ -1780,7 +1861,7 @@ cmDspRC_t _cmDspActiveMeasPrint(cmDspCtx_t* ctx, cmDspActiveMeas_t* p )
|
1780
|
1861
|
{ assert(0); }
|
1781
|
1862
|
}
|
1782
|
1863
|
|
1783
|
|
- cmRptPrintf(ctx->rpt,"loc:%i %s %f %f\n",p->array[i].loc,label,p->array[i].value,p->array[i].cost);
|
|
1864
|
+ cmRptPrintf(ctx->rpt,"loc:%i %s %f %f\n",rp->loc,label,rp->value,rp->cost);
|
1784
|
1865
|
}
|
1785
|
1866
|
|
1786
|
1867
|
return kOkDspRC;
|
|
@@ -1788,15 +1869,17 @@ cmDspRC_t _cmDspActiveMeasPrint(cmDspCtx_t* ctx, cmDspActiveMeas_t* p )
|
1788
|
1869
|
|
1789
|
1870
|
cmDspRC_t _cmDspActiveMeasClear(cmDspCtx_t* ctx, cmDspActiveMeas_t* p )
|
1790
|
1871
|
{
|
1791
|
|
- p->nextEmptyIdx = 0;
|
1792
|
|
- p->nextFullIdx = cmInvalidIdx;
|
|
1872
|
+ memset(p->array,0,sizeof(p->array[0])*p->cnt);
|
|
1873
|
+ p->avail = p->array;
|
|
1874
|
+ p->list = NULL;
|
|
1875
|
+ p->avail = p->array;
|
|
1876
|
+
|
1793
|
1877
|
return kOkDspRC;
|
1794
|
1878
|
}
|
1795
|
1879
|
|
1796
|
1880
|
cmDspRC_t _cmDspActiveMeasFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
1797
|
1881
|
{
|
1798
|
1882
|
cmDspActiveMeas_t* p = (cmDspActiveMeas_t*)inst;
|
1799
|
|
- _cmDspActiveMeasClear(ctx,p);
|
1800
|
1883
|
cmMemPtrFree(&p->array);
|
1801
|
1884
|
return kOkDspRC;
|
1802
|
1885
|
}
|
|
@@ -1810,20 +1893,81 @@ cmDspRC_t _cmDspActiveMeasReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspE
|
1810
|
1893
|
|
1811
|
1894
|
unsigned cnt = cmMax(100,cmDspUInt(inst,kCntAmId));
|
1812
|
1895
|
_cmDspActiveMeasFree(ctx,inst,evt);
|
1813
|
|
- p->array = cmMemAllocZ(cmDspActiveMeasRecd_t,cnt);
|
1814
|
|
- p->cnt = cnt;
|
|
1896
|
+ _cmDspAmAllocList(p,cnt);
|
|
1897
|
+
|
1815
|
1898
|
return rc;
|
1816
|
1899
|
}
|
1817
|
1900
|
|
1818
|
1901
|
cmDspRC_t _cmDspActiveMeasRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
1819
|
1902
|
{
|
1820
|
|
- cmDspRC_t rc = kOkDspRC;
|
|
1903
|
+ cmDspRC_t rc = kOkDspRC;
|
1821
|
1904
|
cmDspActiveMeas_t* p = (cmDspActiveMeas_t*)inst;
|
1822
|
1905
|
cmDspSetEvent(ctx,inst,evt);
|
1823
|
1906
|
|
1824
|
1907
|
switch( evt->dstVarId )
|
1825
|
1908
|
{
|
1826
|
1909
|
case kSflocAmId:
|
|
1910
|
+ {
|
|
1911
|
+
|
|
1912
|
+ unsigned sfloc = cmDspUInt(inst,kSflocAmId); // get the recv'd score location
|
|
1913
|
+ cmDspAmRecd_t* rp = p->sent==NULL ? p->list : p->sent->link; // get the next recd to send
|
|
1914
|
+ bool fl = false;
|
|
1915
|
+
|
|
1916
|
+ for(; rp!=NULL; rp=rp->link)
|
|
1917
|
+ if( rp->loc <= sfloc )
|
|
1918
|
+ {
|
|
1919
|
+ // deterimine the records type
|
|
1920
|
+ unsigned varId = cmInvalidId;
|
|
1921
|
+ switch( rp->type )
|
|
1922
|
+ {
|
|
1923
|
+ case kEvenVarScId: varId = kEvenAmId; break;
|
|
1924
|
+ case kDynVarScId: varId = kDynAmId; break;
|
|
1925
|
+ case kTempoVarScId: varId = kTempoAmId; break;
|
|
1926
|
+ default:
|
|
1927
|
+ { assert(0); }
|
|
1928
|
+ }
|
|
1929
|
+
|
|
1930
|
+ // Sending the location triggers the avail-ch to switch - so the location should only
|
|
1931
|
+ // be sent once.
|
|
1932
|
+ if( !fl )
|
|
1933
|
+ {
|
|
1934
|
+ cmDspSetUInt(ctx,inst,kScLocAmId,rp->loc);
|
|
1935
|
+ fl = true;
|
|
1936
|
+ }
|
|
1937
|
+
|
|
1938
|
+ // transmit the records value and cost
|
|
1939
|
+ cmDspSetDouble(ctx,inst,varId,rp->value);
|
|
1940
|
+ cmDspSetDouble(ctx,inst,kCostAmId,rp->cost);
|
|
1941
|
+ p->sent = rp;
|
|
1942
|
+ }
|
|
1943
|
+
|
|
1944
|
+ }
|
|
1945
|
+ break;
|
|
1946
|
+
|
|
1947
|
+ case kCmdAmId:
|
|
1948
|
+ {
|
|
1949
|
+ unsigned cmdSymId = cmDspSymbol(inst,kCmdAmId);
|
|
1950
|
+
|
|
1951
|
+ if( cmdSymId == p->addSymId )
|
|
1952
|
+ rc = _cmDspActiveMeasAdd(ctx,p,cmDspUInt(inst,kLocAmId),cmDspUInt(inst,kTypeAmId),cmDspDouble(inst,kValueAmId),cmDspDouble(inst,kCstAmId));
|
|
1953
|
+ else
|
|
1954
|
+ if( cmdSymId == p->clearSymId )
|
|
1955
|
+ rc = _cmDspActiveMeasClear(ctx,p);
|
|
1956
|
+ else
|
|
1957
|
+ if( cmdSymId == p->printSymId )
|
|
1958
|
+ rc = _cmDspActiveMeasPrint(ctx,p);
|
|
1959
|
+ else
|
|
1960
|
+ if(cmdSymId == p->rewindSymId )
|
|
1961
|
+ p->sent = NULL;
|
|
1962
|
+ }
|
|
1963
|
+ break;
|
|
1964
|
+
|
|
1965
|
+ }
|
|
1966
|
+
|
|
1967
|
+ /*
|
|
1968
|
+ switch( evt->dstVarId )
|
|
1969
|
+ {
|
|
1970
|
+ case kSflocAmId:
|
1827
|
1971
|
if( p->nextFullIdx != cmInvalidIdx )
|
1828
|
1972
|
{
|
1829
|
1973
|
// get the recv'd score location
|
|
@@ -1903,6 +2047,8 @@ cmDspRC_t _cmDspActiveMeasRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEv
|
1903
|
2047
|
break;
|
1904
|
2048
|
|
1905
|
2049
|
}
|
|
2050
|
+ */
|
|
2051
|
+
|
1906
|
2052
|
return rc;
|
1907
|
2053
|
}
|
1908
|
2054
|
|