Explorar el Código

cmProc4.c:

 1. cmScMeasCalcVal(): changed method of calculating the first and last
MIDI event in p->midiBuf[] and first and the score location window area
defined by 'bli' and 'ln'.

2. cmScMeasExec(): Set p->vsi and p->vsli to indicate that no new 'sets'
are available prior to the early return when locIdx==cmInvalidIdx.
master
kpl hace 11 años
padre
commit
7b84ae7bfb
Se han modificado 1 ficheros con 46 adiciones y 11 borrados
  1. 46
    11
      cmProc4.c

+ 46
- 11
cmProc4.c Ver fichero

@@ -1277,7 +1277,9 @@ cmRC_t  _cmScMatchInitMtx( cmScMatch* p, unsigned rn, unsigned cn )
1277 1277
 {
1278 1278
   //if( rn >p->mrn && cn > p->mcn )
1279 1279
   if( rn*cn > p->mrn*p->mcn )
1280
+  {
1280 1281
     return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "MIDI sequence length must be less than %i. Score sequence length must be less than %i.",p->mmn,p->msn); 
1282
+  }
1281 1283
 
1282 1284
   // if the size of the mtx is not changing then there is nothing to do
1283 1285
   if( rn == p->rn && cn == p->cn )
@@ -1990,10 +1992,26 @@ cmRC_t cmScMatcherReset( cmScMatcher* p, unsigned scLocIdx )
1990 1992
   p->ili           = 0;
1991 1993
 
1992 1994
   // convert scLocIdx to an index into p->mp->loc[]
1993
-  unsigned i;
1994
-  for(i=0; i<p->mp->locN; ++i)
1995
-    if( p->mp->loc[i].scLocIdx == scLocIdx )
1996
-      p->ili = i;
1995
+  unsigned i = 0;
1996
+  while(1)
1997
+  {
1998
+    for(i=0; i<p->mp->locN; ++i)
1999
+      if( p->mp->loc[i].scLocIdx == scLocIdx )
2000
+      {
2001
+        p->ili = i;
2002
+        break;
2003
+      }
2004
+
2005
+    assert(p->mp->locN>0);
2006
+    if( i!=p->mp->locN || scLocIdx==p->mp->loc[p->mp->locN-1].scLocIdx)
2007
+      break;
2008
+
2009
+    scLocIdx += 1;
2010
+  }
2011
+
2012
+  if( i==p->mp->locN)
2013
+    return cmCtxRtCondition( &p->obj, cmSubSysFailRC, "Score matcher reset failed."); 
2014
+
1997 2015
 
1998 2016
   return cmOkRC;
1999 2017
 }
@@ -2240,7 +2258,9 @@ cmRC_t     cmScMatcherExec(  cmScMatcher* p, unsigned smpIdx, unsigned status, c
2240 2258
   if( fl && p->mbi == 0 )
2241 2259
   {
2242 2260
     if( (p->begSyncLocIdx = cmScMatcherScan(p,p->ili,p->initHopCnt)) == cmInvalidIdx )
2261
+    {
2243 2262
       rc = cmInvalidArgRC; // signal init. scan sync. fail
2263
+    }
2244 2264
     else
2245 2265
     {
2246 2266
       //cmScMatcherPrintPath(p);
@@ -2314,6 +2334,7 @@ typedef struct cmScMatcherPrint_str
2314 2334
   unsigned                     mni; 
2315 2335
   unsigned                     pitch;
2316 2336
   unsigned                     vel; 
2337
+  unsigned                     barNumb;
2317 2338
 } cmScMatcherPrint_t;
2318 2339
 
2319 2340
 void  _cmScMatcherInsertPrint(cmScMatcherPrint_t* a, unsigned i, unsigned* anp, unsigned aan, const cmScMatcherResult_t* rp, unsigned scLocIdx )
@@ -2389,6 +2410,7 @@ void cmScMatcherPrint( cmScMatcher* p )
2389 2410
       pp->mni      = cmInvalidIdx;
2390 2411
       pp->pitch    = ep->pitch;
2391 2412
       pp->vel      = kInvalidMidiVelocity;
2413
+      pp->barNumb  = ep->barNumb;
2392 2414
     }
2393 2415
 
2394 2416
   }
@@ -2487,7 +2509,7 @@ void cmScMatcherPrint( cmScMatcher* p )
2487 2509
   
2488 2510
   for(i=0; i<an; ++i)
2489 2511
   {
2490
-    printf("%4i %4i %4s %c%c%c\n",a[i].scLocIdx,a[i].mni,
2512
+    printf("%4i %4i %4i %4s %c%c%c\n",a[i].scLocIdx,a[i].barNumb,a[i].mni,
2491 2513
       cmIsFlag(a[i].flags,kSmBarFl)   ? "|" : cmMidiToSciPitch(a[i].pitch,NULL,0),
2492 2514
       cmIsFlag(a[i].flags,kSmNoteFl)  ? 'n' : ' ',
2493 2515
       cmIsFlag(a[i].flags,kSmMatchFl) ? 'm' : (cmIsFlag(a[i].flags,kSmTransFl) ? 't' : ' '),
@@ -2495,6 +2517,9 @@ void cmScMatcherPrint( cmScMatcher* p )
2495 2517
            );
2496 2518
   }
2497 2519
   
2520
+
2521
+  cmMemFree(a);
2522
+
2498 2523
 }
2499 2524
 
2500 2525
 
@@ -2992,7 +3017,7 @@ void _cmScMeasPrintResult( cmScMeas* p,  cmScMeasSet_t* sp, _cmScMeasResult_t* r
2992 3017
 void _cmScMeasCalcVal( cmScMeas* p, cmScMeasSet_t* sp, int n_mii )
2993 3018
 {
2994 3019
   unsigned mn = 0;
2995
-  int      i;
3020
+  int      i,k = cmInvalidIdx;
2996 3021
 
2997 3022
   if( n_mii == 0 )
2998 3023
     return;
@@ -3003,18 +3028,20 @@ void _cmScMeasCalcVal( cmScMeas* p, cmScMeasSet_t* sp, int n_mii )
3003 3028
   //  prior to the set's begScLocIdx.
3004 3029
   for(i=n_mii; i>=0; --i)
3005 3030
   {
3006
-    ++mn;
3007
-
3008 3031
     if( p->midiBuf[i].locIdx != cmInvalidIdx )
3009 3032
     {
3033
+      k = i;
3010 3034
       unsigned scLocIdx = p->mp->loc[ p->midiBuf[i].locIdx ].scLocIdx;
3011 3035
       if( scLocIdx < sp->bsli )
3012 3036
         break;
3013 3037
     }
3014 3038
   }
3015 3039
 
3016
-  i = cmMax(0,i);
3040
+  assert(k != cmInvalidIdx);
3041
+  mn = n_mii - k + 1;
3042
+  i  = k;
3017 3043
 
3044
+  assert(i>=0);
3018 3045
   assert(mn>0);
3019 3046
 
3020 3047
   // Create a copy of the the MIDI buffer to prevent the
@@ -3032,8 +3059,11 @@ void _cmScMeasCalcVal( cmScMeas* p, cmScMeasSet_t* sp, int n_mii )
3032 3059
   // event's prior to the one at p->midiBuf[n_mii] were assigned.
3033 3060
   assert( (i==0 || p->midiBuf[i].locIdx!=cmInvalidIdx) && p->midiBuf[i+mn-1].locIdx != cmInvalidIdx);
3034 3061
 
3035
-  unsigned          bli      = p->midiBuf[i].locIdx;
3036
-  unsigned          ln       = p->midiBuf[i+mn-1].locIdx - bli + 1;
3062
+  unsigned          l0i      = cmMin(p->midiBuf[i].locIdx,p->midiBuf[i+mn-1].locIdx);
3063
+  unsigned          l1i      = cmMax(p->midiBuf[i].locIdx,p->midiBuf[i+mn-1].locIdx);
3064
+
3065
+  unsigned          bli      = l0i;
3066
+  unsigned          ln       = l1i - bli + 1;
3037 3067
   double            min_cost = DBL_MAX;
3038 3068
   _cmScMeasResult_t r;
3039 3069
   memset(&r,0,sizeof(r));
@@ -3112,6 +3142,11 @@ cmRC_t cmScMeasExec( cmScMeas* p, unsigned mni, unsigned locIdx, unsigned scEvtI
3112 3142
   p->midiBuf[n_mii].pitch    = pitch;
3113 3143
   p->midiBuf[n_mii].vel      = vel;
3114 3144
 
3145
+  // setting vsi=nsi and vsli=nsli will indicate to the calling
3146
+  // program that no new sets are ready.
3147
+  p->vsi  = p->nsi;
3148
+  p->vsli = p->nsli;
3149
+
3115 3150
   if( locIdx == cmInvalidIdx )
3116 3151
     return cmOkRC;
3117 3152
 

Loading…
Cancelar
Guardar