Bläddra i källkod

cmXScore.c : More failed experiments with cmXScoreReorder().

master
kevin 8 år sedan
förälder
incheckning
5a973bc98d
1 ändrade filer med 74 tillägg och 71 borttagningar
  1. 74
    71
      app/cmXScore.c

+ 74
- 71
app/cmXScore.c Visa fil

@@ -1337,10 +1337,10 @@ typedef struct
1337 1337
   unsigned    midi;
1338 1338
   unsigned    flags;
1339 1339
   cmXsNote_t* note;
1340
-
1340
+  int         index;
1341 1341
 } cmXsReorder_t;
1342 1342
 
1343
-cmXsNote_t*  _cmXsReorderFindNote( cmXScore_t* p, unsigned measNumb, const cmXsReorder_t* r )
1343
+cmXsNote_t*  _cmXsReorderFindNote( cmXScore_t* p, unsigned measNumb, const cmXsReorder_t* r, int* indexRef )
1344 1344
 {
1345 1345
   cmXsPart_t* pp = p->partL;
1346 1346
   for(; pp!=NULL; pp=pp->link)
@@ -1350,17 +1350,25 @@ cmXsNote_t*  _cmXsReorderFindNote( cmXScore_t* p, unsigned measNumb, const cmXsR
1350 1350
       if( mp->number == measNumb)
1351 1351
       {
1352 1352
         cmXsNote_t* np = mp->noteL;
1353
-        for(; np!=NULL; np=np->slink)
1353
+        int index = 0;
1354
+        for(; np!=NULL; np=np->slink,++index)
1355
+        {
1356
+          // Set 'mask' to the flags which should be ignored in the comparision
1357
+          unsigned mask    = kTieProcXsFl | kMetronomeXsFl | kBegGroupXsFl | kEndGroupXsFl; 
1358
+          unsigned npFlags = cmClrFlag(np->flags,mask);
1359
+          
1354 1360
           if( np->voice->id == r->voice &&
1355 1361
             np->locIdx == r->locIdx &&
1356 1362
             np->tick == r->tick &&
1357 1363
             np->duration == r->durtn &&
1358 1364
             np->rvalue == r->rval &&
1359 1365
             np->pitch == r->midi &&
1360
-            np->flags == r->flags )
1366
+            npFlags == r->flags )
1361 1367
           {
1368
+            *indexRef = index;
1362 1369
             return np;
1363 1370
           }
1371
+        }
1364 1372
       }
1365 1373
   }
1366 1374
 
@@ -1396,37 +1404,31 @@ cmXsNote_t*  _cmXsReorderFindNote( cmXScore_t* p, unsigned measNumb, const cmXsR
1396 1404
 //
1397 1405
 
1398 1406
 
1399
-void _cmXScoreReorderFixTimes( cmXScore_t* p, cmXsMeas_t* mp )
1407
+void _cmXScoreReorderFixTimes( cmXScore_t* p, unsigned measNumb, cmXsReorder_t* rV, unsigned rN )
1400 1408
 {
1401
-  cmXsNote_t* n0p = mp->noteL;
1402
-  cmXsNote_t* n1p = NULL;
1403
-  for(; n0p != NULL; n0p=n0p->slink)
1409
+  int i;
1410
+  
1411
+  printf("Meas:%i\n",measNumb);
1412
+
1413
+  for(i=0; i<rN; ++i)
1404 1414
   {
1405
-    if( n1p != NULL && n1p->tick < n0p->tick )
1415
+    bool fl = true;
1416
+    int mm_cnt = 0;
1417
+    if( i-1 > 0 )
1406 1418
     {
1407
-      // n1p->tick is before n0p->tick
1408
-      cmXsNote_t* n2p = n1p->slink;
1409
-      unsigned    n   = 1;
1410
-
1411
-      // advance n2p to the next note that is past n0p in time
1412
-      for(; n2p!=NULL; n2p=n2p->slink,++n)
1413
-        if( n2p->tick > n0p->tick )
1414
-          break;
1415
-
1416
-      double t0 = n0p->secs;
1417
-      double dt = 0;
1418
-      if( n2p!=NULL )
1419
-        dt = (n2p->secs - t0)/(n+1);
1420
-
1421
-      cmXsNOte_t* n3p = n0p->slink;
1422
-      for(i=0; i<n && n2p!=NULL; ++i,n2p=n2p->slink)
1423
-        n2p->secs = n0p->secs + (dt*i);
1424
-        
1425
-      
1419
+      mm_cnt += rV[i-1].index+1 == rV[i].index;
1420
+      fl = rV[i].note->secs > rV[i-1].note->secs;
1426 1421
     }
1422
+    
1423
+    if( i+1 < rN )
1424
+      mm_cnt += rV[i].index == rV[i+1].index-1;
1427 1425
 
1428
-    n1p = n0p;
1426
+    
1427
+    printf("%i %i %10.3f %s\n",i,mm_cnt,rV[i].note->secs,fl?" ":"*");
1428
+    
1429 1429
   }
1430
+
1431
+  
1430 1432
 }
1431 1433
 
1432 1434
 cmXsRC_t _cmXScoreReorderMeas( cmXScore_t* p, unsigned measNumb, cmXsReorder_t* rV, unsigned rN )
@@ -1438,10 +1440,13 @@ cmXsRC_t _cmXScoreReorderMeas( cmXScore_t* p, unsigned measNumb, cmXsReorder_t*
1438 1440
 
1439 1441
   // set the 'note' field on each cmXsReorder_t record
1440 1442
   for(i=0; i<rN; ++i)
1441
-    if((rV[i].note = _cmXsReorderFindNote(p,measNumb,rV+i)) == NULL )
1443
+  {
1444
+    if((rV[i].note = _cmXsReorderFindNote(p,measNumb,rV+i,&rV[i].index)) == NULL )
1442 1445
       return kSyntaxErrorXsRC;
1446
+  }
1443 1447
 
1444
-
1448
+  _cmXScoreReorderFixTimes(p, measNumb, rV, rN );
1449
+  
1445 1450
   cmXsMeas_t* mp  = rV[0].note->meas;
1446 1451
   cmXsNote_t* n0p = NULL;
1447 1452
 
@@ -1479,7 +1484,6 @@ cmXsRC_t cmXScoreReorder( cmXsH_t h, const cmChar_t* fn )
1479 1484
   unsigned      ri      = 0;
1480 1485
   unsigned     measNumb = 0;
1481 1486
   cmXsReorder_t rV[ rN ];
1482
-  cmChar_t      B,R,G,D,C,e,d,t,P,S,H,T0,T1,O;
1483 1487
   
1484 1488
   if( cmFileOpen(&fH,fn,kReadFileFl,p->err.rpt) != kOkFileRC )
1485 1489
   {
@@ -1505,41 +1509,37 @@ cmXsRC_t cmXScoreReorder( cmXsH_t h, const cmChar_t* fn )
1505 1509
         {
1506 1510
           cmXsReorder_t r;
1507 1511
           char     pitchStr[4];
1512
+
1513
+          memset(&r,0,sizeof(r));
1508 1514
           
1509 1515
           // parse an event line
1510
-          if( sscanf(b,"%i %i %i %i %f %c%c%c %c%c%c%c%c%c%c%c%c%c%c%c%c%c",&r.voice,&r.locIdx,&r.tick,&r.durtn,&r.rval,pitchStr,pitchStr+1,pitchStr+2,&B,&R,&G,&D,&C,&e,&d,&t,&P,&S,&H,&T0,&T1,&O) == 22 )
1516
+          if( sscanf(b,"%i %i %i %i %f",&r.voice,&r.locIdx,&r.tick,&r.durtn,&r.rval) == 5 )
1511 1517
           {
1512
-            pitchStr[3] = 0;
1513
-            if( !isdigit(pitchStr[2]) )
1514
-              r.midi = 0;
1515
-            else
1518
+            assert( strlen(b)>=52);
1519
+            if( b[35] != ' ')
1516 1520
             {
1517
-              if( pitchStr[1] == ' ')
1521
+              pitchStr[0] = b[35];
1522
+              pitchStr[1] = b[36];
1523
+              pitchStr[2] = b[37];              
1524
+              pitchStr[3] = 0;
1525
+              
1526
+              if( !isdigit(pitchStr[2]) )
1527
+                r.midi = 0;
1528
+              else
1518 1529
               {
1519
-                pitchStr[1] = pitchStr[2];
1520
-                pitchStr[2] = 0;
1521
-              }
1530
+                if( pitchStr[1] == ' ')
1531
+                {
1532
+                  pitchStr[1] = pitchStr[2];
1533
+                  pitchStr[2] = 0;
1534
+                }
1522 1535
 
1523
-              r.midi = cmSciPitchToMidi(pitchStr);
1536
+                r.midi = cmSciPitchToMidi(pitchStr);
1537
+              }
1538
+                           
1524 1539
             }
1525 1540
 
1526
-            r.flags = 0;
1527
-            if( B=='|')  r.flags += kBarXsFl;
1528
-            if( R=='R')  r.flags += kRestXsFl;
1529
-            if( G=='G')  r.flags += kGraceXsFl;
1530
-            if( D=='D')  r.flags += kDotXsFl;
1531
-            if( C=='C')  r.flags += kChordXsFl;
1532
-            if( e=='e')  r.flags += kEvenXsFl;
1533
-            if( d=='d')  r.flags += kDynXsFl;
1534
-            if( t=='t')  r.flags += kTempoXsFl;
1535
-            if( P=='V')  r.flags += kPedalDnXsFl;
1536
-            if( P=='^')  r.flags += kPedalUpXsFl;
1537
-            if( P=='X')  r.flags += kPedalUpDnXsFl;
1538
-            if( S=='S')  r.flags += kSectionXsFl;
1539
-            if( H=='H')  r.flags += kHeelXsFl;
1540
-            if( T0=='T') r.flags += kTieBegXsFl;
1541
-            if( T1=='_') r.flags += kTieEndXsFl;
1542
-            if( O=='*')  r.flags += kOnsetXsFl;
1541
+            
1542
+            
1543 1543
 
1544 1544
             // store the record
1545 1545
             assert( ri < rN );
@@ -1550,8 +1550,8 @@ cmXsRC_t cmXScoreReorder( cmXsH_t h, const cmChar_t* fn )
1550 1550
 
1551 1551
           // the end of the measure was encountered -
1552 1552
           // reorder the measure based on the cmXsReorder_t in rV[ri]
1553
-          if((rc =  _cmXScoreReorderMeas(p, measNumb, rV, ri )) != kOkXsRC )
1554
-            goto errLabel;
1553
+          //if((rc =  _cmXScoreReorderMeas(p, measNumb, rV, ri )) != kOkXsRC )
1554
+          //  goto errLabel;
1555 1555
 
1556 1556
           ri = 0;
1557 1557
 
@@ -1574,7 +1574,7 @@ cmXsRC_t cmXScoreReorder( cmXsH_t h, const cmChar_t* fn )
1574 1574
 
1575 1575
   }
1576 1576
 
1577
- errLabel:
1577
+  //errLabel:
1578 1578
   cmFileClose(&fH);
1579 1579
   cmMemFree(b);
1580 1580
   return rc;
@@ -2125,11 +2125,11 @@ cmXsRC_t cmXScoreWriteCsv( cmXsH_t h, const cmChar_t* csvFn )
2125 2125
 
2126 2126
 void _cmXScoreReportTitle( cmRpt_t* rpt )
2127 2127
 {
2128
-  cmRptPrintf(rpt,"      voc  loc    tick  durtn rval        flags\n");
2129
-  cmRptPrintf(rpt,"      --- ----- ------- ----- ---- --- --------------\n");
2128
+  cmRptPrintf(rpt,"      idx voc  loc    tick  durtn rval        flags\n");
2129
+  cmRptPrintf(rpt,"      --- --- ----- ------- ----- ---- --- --------------\n");
2130 2130
 }
2131 2131
 
2132
-void _cmXScoreReportNote( cmRpt_t* rpt, const cmXsNote_t* note )
2132
+void _cmXScoreReportNote( cmRpt_t* rpt, const cmXsNote_t* note,unsigned index )
2133 2133
 {
2134 2134
   const cmChar_t* B  = cmIsFlag(note->flags,kBarXsFl)       ? "|" : "-";
2135 2135
   const cmChar_t* R  = cmIsFlag(note->flags,kRestXsFl)      ? "R" : "-";
@@ -2153,7 +2153,8 @@ void _cmXScoreReportNote( cmRpt_t* rpt, const cmXsNote_t* note )
2153 2153
   cmChar_t acc = note->alter==-1?'b':(note->alter==1?'#':' ');
2154 2154
   snprintf(N,4,"%c%c%1i",note->step,acc,note->octave);
2155 2155
 
2156
-  cmRptPrintf(rpt,"      %3i %5i %7i %5i %4.1f %3s %s%s%s%s%s%s%s%s%s%s%s%s%s%s",
2156
+  cmRptPrintf(rpt,"      %3i %3i %5i %7i %5i %4.1f %3s %s%s%s%s%s%s%s%s%s%s%s%s%s%s",
2157
+    index,
2157 2158
     note->voice->id,
2158 2159
     note->locIdx,
2159 2160
     note->tick,
@@ -2191,6 +2192,8 @@ void  cmXScoreReport( cmXsH_t h, cmRpt_t* rpt, bool sortFl )
2191 2192
     const cmXsMeas_t* meas = pp->measL;
2192 2193
     for(; meas!=NULL; meas=meas->link)
2193 2194
     {
2195
+      unsigned idx = 0;
2196
+
2194 2197
       cmRptPrintf(rpt,"  %i : div:%i beat:%i beat-type:%i (%i)\n",meas->number,meas->divisions,meas->beats,meas->beat_type,meas->divisions*meas->beats);
2195 2198
 
2196 2199
       _cmXScoreReportTitle(rpt);
@@ -2201,9 +2204,9 @@ void  cmXScoreReport( cmXsH_t h, cmRpt_t* rpt, bool sortFl )
2201 2204
         const cmXsNote_t* note = meas->noteL;
2202 2205
         unsigned t0 = 0;
2203 2206
         unsigned t1 = 0;
2204
-        for(; note!=NULL; note=note->slink)
2207
+        for(; note!=NULL; note=note->slink,++idx)
2205 2208
         {
2206
-          _cmXScoreReportNote(rpt,note);
2209
+          _cmXScoreReportNote(rpt,note,idx);
2207 2210
 
2208 2211
           t1 = note->slink==NULL ? note->tick : note->slink->tick;
2209 2212
 
@@ -2234,7 +2237,7 @@ void  cmXScoreReport( cmXsH_t h, cmRpt_t* rpt, bool sortFl )
2234 2237
 
2235 2238
           for(; note!=NULL; note=note->mlink)
2236 2239
           {
2237
-            _cmXScoreReportNote(rpt,note);
2240
+            _cmXScoreReportNote(rpt,note,idx);
2238 2241
 
2239 2242
             if( note->mlink!=NULL || note->voice->id==0)
2240 2243
               cmRptPrintf(rpt,"\n");
@@ -2287,8 +2290,8 @@ cmXsRC_t cmXScoreTest(
2287 2290
   if( dynFn != NULL )
2288 2291
     cmXScoreInsertDynamics(h, dynFn );
2289 2292
 
2290
-  if( reorderFn != NULL )
2291
-    cmXScoreReorder(h,reorderFn);
2293
+  //if( reorderFn != NULL )
2294
+  //  cmXScoreReorder(h,reorderFn);
2292 2295
 
2293 2296
   if( outFn != NULL )
2294 2297
   {

Laddar…
Avbryt
Spara