Sfoglia il codice sorgente

cmDspKr.c: Added cmMeas and Dyn,Even,Tempo outputs to cmDspScFol.

master
kevin 11 anni fa
parent
commit
030510039d
1 ha cambiato i file con 113 aggiunte e 40 eliminazioni
  1. 113
    40
      dsp/cmDspKr.c

+ 113
- 40
dsp/cmDspKr.c Vedi File

@@ -814,18 +814,30 @@ enum
814 814
   kD1SfId,
815 815
   kSmpIdxSfId,
816 816
   kCmdSfId,
817
-  kOutSfId
817
+  kOutSfId,
818
+  kDynSfId,
819
+  kEvenSfId,
820
+  kTempoSfId
818 821
 };
819 822
 
820 823
 cmDspClass_t _cmScFolDC;
824
+struct cmDspScFol_str;
821 825
 
822 826
 typedef struct
823 827
 {
824
-  cmDspInst_t inst;
825
-  cmScTrk*    sfp;
826
-  cmScH_t     scH;
827
-  unsigned    printSymId;
828
-  unsigned    quietSymId;
828
+  cmDspCtx_t*            ctx;
829
+  struct cmDspScFol_str* sfp;
830
+} cmDspScFolCbArg_t;
831
+
832
+typedef struct cmDspScFol_str
833
+{
834
+  cmDspInst_t       inst;
835
+  cmScMatcher*      sfp;
836
+  cmScMeas*         smp;
837
+  cmScH_t           scH;
838
+  cmDspScFolCbArg_t arg;
839
+  unsigned          printSymId;
840
+  unsigned          quietSymId;
829 841
 } cmDspScFol_t;
830 842
 
831 843
 cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
@@ -844,6 +856,9 @@ cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
844 856
     { "smpidx",kSmpIdxSfId,   0, 0, kInDsvFl | kUIntDsvFl,                    "MIDI time tag as a sample index"},
845 857
     { "cmd",   kCmdSfId,      0, 0, kInDsvFl | kSymDsvFl,                     "Command input: print | quiet"},
846 858
     { "out",   kOutSfId,      0, 0, kOutDsvFl| kUIntDsvFl,                    "Current score index."},
859
+    { "dyn",   kDynSfId,      0, 0, kOutDsvFl| kDoubleDsvFl,                  "Dynamic value."},
860
+    { "even",  kEvenSfId,     0, 0, kOutDsvFl| kDoubleDsvFl,                  "Evenness value."},
861
+    { "tempo", kTempoSfId,    0, 0, kOutDsvFl| kDoubleDsvFl,                  "Tempo value."},
847 862
     { NULL,    0,             0, 0, 0, NULL }
848 863
   };
849 864
 
@@ -852,18 +867,22 @@ cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
852 867
   if((p = cmDspInstAlloc(cmDspScFol_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl)) == NULL )
853 868
     return NULL;
854 869
   
855
-
856
-  p->sfp = cmScTrkAlloc(ctx->cmProcCtx, NULL, 0, cmScNullHandle, 0, 0, 0, 0 );
870
+  p->sfp        = cmScMatcherAlloc(ctx->cmProcCtx, NULL, 0, cmScNullHandle, 0, 0, NULL, NULL );
871
+  p->smp        = cmScMeasAlloc(   ctx->cmProcCtx, NULL, cmScNullHandle, 0, NULL, 0 );
857 872
   p->printSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"print");
858 873
   p->quietSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"quiet");
859 874
 
860
-  cmDspSetDefaultUInt( ctx, &p->inst,  kBufCntSfId,     0,     7);
861
-  cmDspSetDefaultUInt( ctx, &p->inst,  kMinLkAhdSfId,   0,    10);
862
-  cmDspSetDefaultUInt( ctx, &p->inst,  kMaxWndCntSfId,  0,    25);
863
-  cmDspSetDefaultUInt( ctx, &p->inst,  kMinVelSfId,     0,     5);
864
-  cmDspSetDefaultUInt( ctx, &p->inst,  kIndexSfId,      0,     0);  
865
-  cmDspSetDefaultUInt( ctx, &p->inst,  kOutSfId,        0,     0);
866
-  cmDspSetDefaultSymbol(ctx,&p->inst,  kCmdSfId,         p->quietSymId );
875
+  cmDspSetDefaultUInt(   ctx, &p->inst,  kBufCntSfId,     0,     7);
876
+  cmDspSetDefaultUInt(   ctx, &p->inst,  kMaxWndCntSfId,  0,    10);
877
+  cmDspSetDefaultUInt(   ctx, &p->inst,  kMinLkAhdSfId,   0,     3);
878
+  cmDspSetDefaultUInt(   ctx, &p->inst,  kMinVelSfId,     0,     5);
879
+  cmDspSetDefaultUInt(   ctx, &p->inst,  kIndexSfId,      0,     0);  
880
+  cmDspSetDefaultUInt(   ctx, &p->inst,  kOutSfId,        0,     0);
881
+  cmDspSetDefaultDouble( ctx, &p->inst,  kDynSfId,        0,     0);
882
+  cmDspSetDefaultDouble( ctx, &p->inst,  kEvenSfId,       0,     0);
883
+  cmDspSetDefaultDouble( ctx, &p->inst,  kTempoSfId,      0,     0);
884
+  
885
+  cmDspSetDefaultSymbol(ctx,&p->inst,  kCmdSfId, p->quietSymId );
867 886
 
868 887
   return &p->inst;
869 888
 }
@@ -871,49 +890,90 @@ cmDspInst_t*  _cmDspScFolAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned
871 890
 cmDspRC_t _cmDspScFolFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
872 891
 {
873 892
   cmDspScFol_t* p = (cmDspScFol_t*)inst;
874
-  cmScTrkFree(&p->sfp);
893
+  cmScMatcherFree(&p->sfp);
894
+  cmScMeasFree(&p->smp);
875 895
   cmScoreFinalize(&p->scH);
876 896
   return kOkDspRC;
877 897
 }
878 898
 
899
+void _cmScFolMatcherCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
900
+{
901
+  cmDspScFolCbArg_t* ap = (cmDspScFolCbArg_t*)arg;
902
+
903
+  if( cmScMeasExec(ap->sfp->smp, rp->mni, rp->locIdx, rp->scEvtIdx, rp->flags, rp->smpIdx, rp->pitch, rp->vel ) == cmOkRC )
904
+  {
905
+    cmDspInst_t*  inst = (cmDspInst_t*)ap->sfp;
906
+
907
+    unsigned i;
908
+    for(i=ap->sfp->smp->vsi; i<ap->sfp->smp->nsi; i++)
909
+    {
910
+      switch( ap->sfp->smp->set[i].sp->varId )
911
+      {
912
+        case kEvenVarScId:
913
+          cmDspSetDouble(ap->ctx,inst,kEvenSfId,ap->sfp->smp->set[i].value);
914
+          break;
915
+
916
+        case kDynVarScId:
917
+          cmDspSetDouble(ap->ctx,inst,kDynSfId,ap->sfp->smp->set[i].value);
918
+          break;
919
+
920
+        case kTempoVarScId:
921
+          cmDspSetDouble(ap->ctx,inst,kTempoSfId,ap->sfp->smp->set[i].value);
922
+          break;
923
+
924
+        default:
925
+          { assert(0); }
926
+      }           
927
+    }
928
+  }
929
+}
930
+
931
+
879 932
 cmDspRC_t _cmDspScFolOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
880 933
 {
881
-  cmDspRC_t       rc          = kOkDspRC;
882
-  cmDspScFol_t*   p           = (cmDspScFol_t*)inst;
883
-  unsigned*       dynRefArray = NULL;
884
-  unsigned        dynRefCnt   = 0;
934
+  cmDspRC_t       rc = kOkDspRC;
935
+  cmDspScFol_t*   p  = (cmDspScFol_t*)inst;
885 936
   const cmChar_t* fn;
886 937
 
887 938
   if((fn = cmDspStrcz(inst,kFnSfId)) == NULL || strlen(fn)==0 )
888 939
     return cmErrMsg(&inst->classPtr->err, kInvalidArgDspRC, "No score file name supplied.");
889 940
 
890
-  if( cmDspRsrcUIntArray(ctx->dspH, &dynRefCnt, &dynRefArray, "dynRef", NULL ) != kOkDspRC )
891
-  {
892
-    rc = cmErrMsg(&inst->classPtr->err, kRsrcNotFoundDspRC, "The dynamics reference array resource was not found.");
893
-    goto errLabel;
894
-  }
895
-
896 941
   if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, cmDspSampleRate(ctx), NULL, 0, NULL, NULL ) != kOkScRC )
897 942
     return cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
898 943
 
944
+  if( cmScoreIsValid(p->scH) )
945
+  {
946
+    unsigned*       dynRefArray = NULL;
947
+    unsigned        dynRefCnt   = 0;
948
+
949
+    // initialize the cmScMatcher
950
+    if( cmScMatcherInit(p->sfp, cmDspSampleRate(ctx),  p->scH, cmDspUInt(inst,kMaxWndCntSfId), cmDspUInt(inst,kBufCntSfId), _cmScFolMatcherCb, p->smp ) != cmOkRC )
951
+      rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Internal score follower allocation failed.");
952
+
953
+    // read the dynamics reference array
954
+    if( cmDspRsrcUIntArray(ctx->dspH, &dynRefCnt, &dynRefArray, "dynRef", NULL ) != kOkDspRC )
955
+    {
956
+      rc = cmErrMsg(&inst->classPtr->err, kRsrcNotFoundDspRC, "The dynamics reference array resource was not found.");
957
+      goto errLabel;
958
+    }
959
+
960
+    // initialize the cmScMeas object.
961
+    if( cmScMeasInit(p->smp, p->scH, cmDspSampleRate(ctx), dynRefArray, dynRefCnt ) != cmOkRC )
962
+      rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Internal scMeas object initialization failed.");
963
+
964
+  }
965
+
899 966
  errLabel:
900 967
   return rc;
901 968
 }
902 969
 
903 970
 cmDspRC_t _cmDspScFolReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
904 971
 {
905
-  cmDspRC_t     rc = kOkDspRC;
906
-  cmDspScFol_t* p  = (cmDspScFol_t*)inst;
907
-  rc               = cmDspApplyAllDefaults(ctx,inst);
908
-
909
-  if((rc = _cmDspScFolOpenScore(ctx,inst)) != kOkDspRC )
972
+  cmDspRC_t     rc;
973
+  if((rc = cmDspApplyAllDefaults(ctx,inst)) != kOkDspRC )
910 974
     return rc;
911 975
 
912
-  if( cmScoreIsValid(p->scH) )
913
-    if( cmScTrkInit(p->sfp, cmDspSampleRate(ctx),  p->scH, cmDspUInt(inst,kBufCntSfId), cmDspUInt(inst,kMinLkAhdSfId), cmDspUInt(inst,kMaxWndCntSfId), cmDspUInt(inst,kMinVelSfId) ) != cmOkRC )
914
-      rc = cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Internal score follower allocation failed.");
915
-
916
-  return rc;  
976
+  return _cmDspScFolOpenScore(ctx,inst);
917 977
 }
918 978
 
919 979
 
@@ -928,16 +988,29 @@ cmDspRC_t _cmDspScFolRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
928 988
     {
929 989
       case kIndexSfId:
930 990
         if( cmScoreIsValid(p->scH) )
931
-          if( cmScTrkReset( p->sfp, cmDspUInt(inst,kIndexSfId) ) != cmOkRC )
991
+        {
992
+          if( cmScMeasReset( p->smp ) != cmOkRC )
993
+            cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Score measure unit reset to score index '%i' failed.");
994
+
995
+          if( cmScMatcherReset( p->sfp, cmDspUInt(inst,kIndexSfId) ) != cmOkRC )
932 996
             cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Score follower reset to score index '%i' failed.");
997
+        }
933 998
         break;
934 999
 
935 1000
       case kStatusSfId:
936 1001
         if( cmScoreIsValid(p->scH))
937 1002
         {
938
-          unsigned idx = cmScTrkExec(p->sfp, ctx->cycleCnt, cmDspUInt(inst,kStatusSfId), cmDspUInt(inst,kD0SfId), cmDspUInt(inst,kD1SfId));
939
-          if( idx != cmInvalidIdx )
940
-            cmDspSetUInt(ctx,inst,kOutSfId,idx);
1003
+          unsigned scLocIdx = cmInvalidIdx;
1004
+
1005
+          // setup the cmScMeas() callback arg.
1006
+          p->arg.ctx    = ctx;
1007
+          p->arg.sfp    = p;
1008
+          p->sfp->cbArg = &p->arg;
1009
+
1010
+          // this call may result in a callback to _cmScFolMatcherCb()
1011
+          if( cmScMatcherExec(p->sfp, cmDspUInt(inst,kSmpIdxSfId), cmDspUInt(inst,kStatusSfId), cmDspUInt(inst,kD0SfId), cmDspUInt(inst,kD1SfId), &scLocIdx) == cmOkRC )
1012
+            if( scLocIdx != cmInvalidIdx )
1013
+              cmDspSetUInt(ctx,inst,kOutSfId,scLocIdx);
941 1014
         }
942 1015
         break;
943 1016
 

Loading…
Annulla
Salva