Browse Source

cmXScore.c : Finalized and debugged _cmScoreReorder() processing.

master
kevin 8 years ago
parent
commit
670edcaec7
1 changed files with 158 additions and 251 deletions
  1. 158
    251
      app/cmXScore.c

+ 158
- 251
app/cmXScore.c View File

@@ -33,26 +33,28 @@ cmXsH_t cmXsNullHandle = cmSTATIC_NULL_HANDLE;
33 33
 
34 34
 enum
35 35
 {
36
-  kSectionXsFl   = 0x00001,  // rvalue holds section number
37
-  kBarXsFl       = 0x00002,
38
-  kRestXsFl      = 0x00004,
39
-  kGraceXsFl     = 0x00008,
40
-  kDotXsFl       = 0x00010,
41
-  kChordXsFl     = 0x00020,
42
-  kDynXsFl       = 0x00040,
43
-  kEvenXsFl      = 0x00080,
44
-  kTempoXsFl     = 0x00100,
45
-  kHeelXsFl      = 0x00200,
46
-  kTieBegXsFl    = 0x00400,
47
-  kTieEndXsFl    = 0x00800,
48
-  kTieProcXsFl   = 0x01000,
49
-  kPedalDnXsFl   = 0x02000,
50
-  kPedalUpXsFl   = 0x04000,
51
-  kPedalUpDnXsFl = 0x08000,
52
-  kMetronomeXsFl = 0x10000,  // duration holds BPM
53
-  kOnsetXsFl     = 0x20000,  // this is a sounding note
54
-  kBegGroupXsFl  = 0x40000,
55
-  kEndGroupXsFl  = 0x80000
36
+  kSectionXsFl   = 0x000001,  // rvalue holds section number
37
+  kBarXsFl       = 0x000002,
38
+  kRestXsFl      = 0x000004,
39
+  kGraceXsFl     = 0x000008,
40
+  kDotXsFl       = 0x000010,
41
+  kChordXsFl     = 0x000020,
42
+  kDynXsFl       = 0x000040,
43
+  kEvenXsFl      = 0x000080,
44
+  kTempoXsFl     = 0x000100,
45
+  kHeelXsFl      = 0x000200,
46
+  kTieBegXsFl    = 0x000400,
47
+  kTieEndXsFl    = 0x000800,
48
+  kTieProcXsFl   = 0x001000,
49
+  kPedalDnXsFl   = 0x002000,
50
+  kPedalUpXsFl   = 0x004000,
51
+  kPedalUpDnXsFl = 0x008000,
52
+  kSostDnXsFl    = 0x010000,
53
+  kSostUpXsFl    = 0x020000,
54
+  kMetronomeXsFl = 0x040000,  // duration holds BPM
55
+  kOnsetXsFl     = 0x080000,  // this is a sounding note
56
+  kBegGroupXsFl  = 0x100000,
57
+  kEndGroupXsFl  = 0x200000
56 58
 };
57 59
 
58 60
 struct cmXsMeas_str;
@@ -65,6 +67,7 @@ typedef struct cmXsNote_str
65 67
   unsigned                    pitch;    // midi pitch
66 68
   unsigned                    velocity; // midi velocity
67 69
   unsigned                    dynamics; // dynamic level 1=pppp 9=fff
70
+  unsigned                    vel;      // score specified MIDI velocity 
68 71
   cmChar_t                    step;     // A-G
69 72
   unsigned                    octave;   // sci pitch octave
70 73
   int                         alter;    // +n=sharps,-n=flats
@@ -952,6 +955,7 @@ void _cmXScoreSpreadGraceNotes( cmXScore_t* p )
952 955
          tick1 = _cmXsSpreadGraceNotes(a,ai);
953 956
     }
954 957
   }
958
+
955 959
 }
956 960
 
957 961
 
@@ -1240,6 +1244,35 @@ cmXsRC_t _cmXScoreWriteScorePlotFile( cmXScore_t* p, const cmChar_t* fn )
1240 1244
   return rc;
1241 1245
 }
1242 1246
 
1247
+// Force the bar event to be the first event in the measure.
1248
+void _cmXScoreFixBarLines( cmXScore_t* p )
1249
+{
1250
+  cmXsPart_t* pp = p->partL;
1251
+  for(; pp!=NULL; pp=pp->link)
1252
+  {
1253
+    cmXsMeas_t* mp   = pp->measL;
1254
+    for(; mp!=NULL; mp=mp->link)
1255
+    {
1256
+      cmXsNote_t* np  = mp->noteL;
1257
+      cmXsNote_t* ep  = NULL;
1258
+        
1259
+      for(; np!=NULL; np=np->slink )
1260
+      {
1261
+        if( cmIsFlag(np->flags,kBarXsFl) )
1262
+        {
1263
+          if( ep != NULL )
1264
+            np->tick = ep->tick;
1265
+          break;
1266
+        }
1267
+          
1268
+        if( ep == NULL )
1269
+          ep = np;
1270
+      }
1271
+      
1272
+    }
1273
+  }
1274
+}
1275
+
1243 1276
 cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn, const cmChar_t* midiFn )
1244 1277
 {
1245 1278
   cmXsRC_t rc = kOkXsRC;
@@ -1331,22 +1364,62 @@ bool     cmXScoreIsValid( cmXsH_t h )
1331 1364
 
1332 1365
 typedef struct
1333 1366
 {
1334
-  unsigned    idx;
1335
-  unsigned    voice;
1336
-  unsigned    locIdx;
1337
-  unsigned    tick;
1338
-  unsigned    durtn;
1339
-  float       rval;
1340
-  unsigned    midi;
1341
-  unsigned    flags;
1342
-  cmXsNote_t* note;
1343
-  int         index;
1344
-  unsigned    dynId;  // 0=ignore >0 dynamic level marking
1345
-  unsigned    sostId; // 0=ignore 1=down 2=up
1367
+  unsigned    idx;      // Fields from the reordering input file which are
1368
+  unsigned    voice;    // used to match the reorder record to 
1369
+  unsigned    locIdx;   // the associated a cmXsNode_t record.
1370
+  unsigned    tick;     //
1371
+  unsigned    durtn;    //
1372
+  float       rval;     //
1373
+  unsigned    midi;     //
1374
+  
1375
+  cmXsNote_t* note;     // The cmXsNode_t* associated with this cmXsReorder_t record
1376
+  
1377
+  unsigned    dynIdx;    // cmInvalidIdx=ignore otherwise index into _cmXScoreDynMarkArray[]
1378
+  unsigned    sostFl;    // 0=ignore | kSostDnXsFl | kSostUpXsFl
1346 1379
   unsigned    newTick;   // 0=ignore >0 new tick value
1347 1380
 } cmXsReorder_t;
1348 1381
 
1349
-cmXsNote_t*  _cmXsReorderFindNote( cmXScore_t* p, unsigned measNumb, const cmXsReorder_t* r, unsigned iii, int* indexRef )
1382
+typedef struct _cmXScoreDynMark_str
1383
+{
1384
+  const cmChar_t* mark;   //
1385
+  unsigned        id;     // (1-17) maps to velocity
1386
+  unsigned        dyn;    // pppp - fff (1-9) as used by cmScore
1387
+  int             adjust; // {-1,0,+1}
1388
+  unsigned        vel;    // associated MIDI velocity
1389
+} _cmXScoreDynMark_t;
1390
+
1391
+_cmXScoreDynMark_t _cmXScoreDynMarkArray[] =
1392
+{
1393
+  {"pppp-", 1,  1, -1,   3},
1394
+  {"pppp",  2,  1,  0,  10},
1395
+  {"pppp+", 3,  1,  1,  22},
1396
+  {"ppp-",  3,  2, -1,  22},
1397
+  {"ppp",   4,  2,  0,  29},
1398
+  {"ppp+",  5,  2,  1,  36},
1399
+  {"pp-",   5,  3, -1,  36},
1400
+  {"pp",    6,  3,  0,  43},
1401
+  {"pp+",   7,  3,  1,  50},
1402
+  {"p-",    7,  4, -1,  50},
1403
+  {"p",     8,  4,  0,  57},
1404
+  {"p+",    9,  4,  1,  64},
1405
+  {"mp-",   9,  5, -1,  64},
1406
+  {"mp",   10,  5,  0,  71},
1407
+  {"mp+",  11,  5,  1,  78},
1408
+  {"mf-",  11,  6, -1,  78},
1409
+  {"mf",   12,  6,  0,  85},
1410
+  {"mf+",  13,  6,  1,  92},
1411
+  {"f-",   13,  7, -1,  92},
1412
+  {"f",    14,  7,  0,  99},
1413
+  {"f+",   15,  7,  1, 106}, 
1414
+  {"ff",   16,  8,  0, 113},
1415
+  {"ff+",  17,  8,  1, 120},
1416
+  {"fff",  18,  9,  0, 127},
1417
+  {NULL,0,0,0,0}
1418
+  
1419
+};
1420
+
1421
+
1422
+cmXsNote_t*  _cmXsReorderFindNote( cmXScore_t* p, unsigned measNumb, const cmXsReorder_t* r, unsigned iii )
1350 1423
 {
1351 1424
   cmXsPart_t* pp = p->partL;
1352 1425
   for(; pp!=NULL; pp=pp->link)
@@ -1360,31 +1433,17 @@ cmXsNote_t*  _cmXsReorderFindNote( cmXScore_t* p, unsigned measNumb, const cmXsR
1360 1433
         int         index = 0;
1361 1434
         for(; np!=NULL; np=np->slink,++index)
1362 1435
         {
1363
-          // Set 'mask' to the flags which should be ignored in the comparision
1364
-          // unsigned mask    = kTieProcXsFl | kMetronomeXsFl | kBegGroupXsFl | kEndGroupXsFl; 
1365
-          // unsigned npFlags = cmClrFlag(np->flags,mask);
1366
-
1367
-          //if( measNumb==56 && iii == 13 )
1368
-          //  printf("voc:%i loc:%i tick:%i dur:%i rval:%f pitch:%i index:%i\n",np->voice->id,np->locIdx,np->tick,np->duration,np->rvalue,np->pitch,index);
1369
-
1370
-          
1371 1436
           if( np->voice->id == r->voice &&
1372 1437
             np->locIdx == r->locIdx &&
1373 1438
             np->tick == r->tick &&
1374 1439
             np->duration == r->durtn &&
1375 1440
             np->rvalue == r->rval &&
1376 1441
             np->pitch == r->midi &&
1377
-            index == r->idx // &&
1378
-            //npFlags == r->flags
1379
-              )
1442
+            index == r->idx )
1380 1443
           {
1381
-            *indexRef = index;
1382 1444
             return np;
1383 1445
           }
1384 1446
         }
1385
-
1386
-        printf("blah");
1387
-        
1388 1447
       }
1389 1448
   }
1390 1449
 
@@ -1392,59 +1451,6 @@ cmXsNote_t*  _cmXsReorderFindNote( cmXScore_t* p, unsigned measNumb, const cmXsR
1392 1451
   return NULL;
1393 1452
 }
1394 1453
 
1395
-//  moved forward
1396
-//  x 0 0 0 1 0 0 0
1397
-//  0 0 0 1 0 0 0 x
1398
-//  1 2 3 4 2 5 6 7
1399
-//  0 0 0 1 2 1 0 0  = mm_cnt
1400
-//
1401
-//  moved backward
1402
-//  x 0 0 0 0 1 1 0 0
1403
-//  0 0 0 0 1 1 0 0 x
1404
-//  1 2 3 4 7 6 5 6 7
1405
-//  0 0 0 1 1 2 1 0 0 = mm_cnt
1406
-
1407
-// 1. Iterate through rV[] and assign an index corresponding to the associated
1408
-//    cmXsNote_t record in the un-reordered mp->noteL.
1409
-//
1410
-// 2. Iterate through rV[] and assign a mismatch count based equal to:
1411
-//     mm_cnt = rV[i-1].index+1 == rV[i].index + rV[i].index == rV[i+1].index-1
1412
-//
1413
-// 3. Mis-match sequences should always begin and end with 1.
1414
-//    
1415
-// 4. Iterate through rV[] and update the 'dsecs' of all non-zero mis-match
1416
-//    records (except for the leading and trailing) records.
1417
-//
1418
-// 5. Iterate through rV[] and update the 'secs'  of all non-zero mis-match
1419
-//    records (except for the leading and trailing) records.
1420
-//
1421
-
1422
-
1423
-void _cmXScoreReorderFixTimes( cmXScore_t* p, unsigned measNumb, cmXsReorder_t* rV, unsigned rN )
1424
-{
1425
-  int i;
1426
-  
1427
-  printf("Meas:%i\n",measNumb);
1428
-
1429
-  for(i=0; i<rN; ++i)
1430
-  {
1431
-    bool fl = true;
1432
-    int mm_cnt = 0;
1433
-    if( i-1 > 0 )
1434
-    {
1435
-      mm_cnt += rV[i-1].index+1 == rV[i].index;
1436
-      fl = rV[i].note->secs >= rV[i-1].note->secs || rV[i].note->secs == 0;
1437
-    }
1438
-    
1439
-    if( i+1 < rN )
1440
-      mm_cnt += rV[i].index == rV[i+1].index-1;
1441
-
1442
-    
1443
-    //printf("%i %i %10.3f %s\n",i,mm_cnt,rV[i].note->secs,fl?" ":"*");
1444
-    
1445
-  }
1446
-}
1447
-
1448 1454
 cmXsRC_t _cmXScoreReorderMeas( cmXScore_t* p, unsigned measNumb, cmXsReorder_t* rV, unsigned rN )
1449 1455
 {
1450 1456
   unsigned i;
@@ -1455,12 +1461,10 @@ cmXsRC_t _cmXScoreReorderMeas( cmXScore_t* p, unsigned measNumb, cmXsReorder_t*
1455 1461
   // set the 'note' field on each cmXsReorder_t record
1456 1462
   for(i=0; i<rN; ++i)
1457 1463
   {
1458
-    if((rV[i].note = _cmXsReorderFindNote(p,measNumb,rV+i,i,&rV[i].index)) == NULL )
1464
+    if((rV[i].note = _cmXsReorderFindNote(p,measNumb,rV+i,i)) == NULL )
1459 1465
       return kSyntaxErrorXsRC;
1460 1466
   }
1461 1467
 
1462
-  //_cmXScoreReorderFixTimes(p, measNumb, rV, rN );
1463
-  
1464 1468
   cmXsMeas_t* mp  = rV[0].note->meas;
1465 1469
   cmXsNote_t* n0p = NULL;
1466 1470
 
@@ -1475,9 +1479,19 @@ cmXsRC_t _cmXScoreReorderMeas( cmXScore_t* p, unsigned measNumb, cmXsReorder_t*
1475 1479
     else
1476 1480
       n0p->slink = rV[i].note;
1477 1481
 
1482
+    // if a new tick was specified 
1478 1483
     if( rV[i].newTick != 0 )
1479 1484
       rV[i].note->tick = rV[i].newTick;
1480 1485
 
1486
+    // if a sostenuto was specified
1487
+    rV[i].note->flags |= rV[i].sostFl;
1488
+
1489
+    if( rV[i].dynIdx != cmInvalidIdx )
1490
+    {
1491
+      rV[i].note->dynamics = _cmXScoreDynMarkArray[ rV[i].dynIdx ].dyn;
1492
+      rV[i].note->vel      = _cmXScoreDynMarkArray[ rV[i].dynIdx ].vel;
1493
+    }
1494
+    
1481 1495
     n0p = rV[i].note;
1482 1496
     n0p->slink = NULL;
1483 1497
   }
@@ -1486,54 +1500,25 @@ cmXsRC_t _cmXScoreReorderMeas( cmXScore_t* p, unsigned measNumb, cmXsReorder_t*
1486 1500
 
1487 1501
 }
1488 1502
 
1489
-typedef struct _cmXScoreDynMark_str
1490
-{
1491
-  const cmChar_t* mark;
1492
-  unsigned        id;
1493
-} _cmXScoreDynMark_t;
1494
-
1495
-_cmXScoreDynMark_t _cmXScoreDynMarkArray[] =
1496
-{
1497
-  {"pppp",  1},
1498
-  {"pppp+", 2},
1499
-  {"ppp-",  2},
1500
-  {"ppp",   4},
1501
-  {"ppp+",  5},
1502
-  {"pp-",   5},
1503
-  {"pp",    7},
1504
-  {"pp+",   8},
1505
-  {"p-",    8},
1506
-  {"p",     9},
1507
-  {"mp",   10},
1508
-  {"mp+",  11},
1509
-  {"mf-",  11},
1510
-  {"mf",   12},
1511
-  {"f",    13},
1512
-  {"f+",   14},
1513
-  {"ff",   15},
1514
-  {"ff+",  16},
1515
-  {"fff",  17},
1516
-  {NULL,0}
1517
-  
1518
-};
1519
-
1520
-cmXsRC_t _cmXScoreReorderParseDyn(cmXScore_t* p, const cmChar_t* b, unsigned lineNumb, unsigned* dynIdRef )
1503
+cmXsRC_t _cmXScoreReorderParseDyn(cmXScore_t* p, const cmChar_t* b, unsigned lineNumb, unsigned* dynIdxRef )
1521 1504
 {
1522 1505
   cmXsRC_t rc = kOkXsRC;
1523 1506
   const cmChar_t* s;
1524 1507
 
1525
-  *dynIdRef = 0;
1526
-  
1508
+  *dynIdxRef = cmInvalidIdx;
1509
+
1510
+  // locate the '!' which indicates the start of a dynamic marking
1527 1511
   if( (s = strchr(b,'!')) == NULL )
1528 1512
     return rc;
1529 1513
   
1530
-  ++s;
1514
+  ++s; // increment past the '!'
1531 1515
   
1532 1516
   if( *s == 0 )
1533 1517
     return cmErrMsg(&p->err,kSyntaxErrorXsRC,"Unexpected end-of-line on dynamics parsing on line:%i.",lineNumb);
1534 1518
 
1519
+  // some dynamic markings are surrounded by parenthesis (to indicate a dynamic level with greater uncertainty)
1535 1520
   if( *s == '(' )
1536
-    ++s;
1521
+    ++s;  // skip the paren.
1537 1522
 
1538 1523
   if( *s == 0 )
1539 1524
     return cmErrMsg(&p->err,kSyntaxErrorXsRC,"Unexpected end-of-line on dynamics parsing on line:%i.",lineNumb);
@@ -1545,7 +1530,7 @@ cmXsRC_t _cmXScoreReorderParseDyn(cmXScore_t* p, const cmChar_t* b, unsigned lin
1545 1530
   cmChar_t mark[n+1];
1546 1531
   memset(mark,0,n+1);
1547 1532
   
1548
-  for(i=0; i<n && doneFl==false; ++i)
1533
+  for(i=0; j<n && doneFl==false; ++i)
1549 1534
   {
1550 1535
     switch(s[i])
1551 1536
     {
@@ -1557,11 +1542,11 @@ cmXsRC_t _cmXScoreReorderParseDyn(cmXScore_t* p, const cmChar_t* b, unsigned lin
1557 1542
         mark[j++] = s[i];
1558 1543
         break;
1559 1544
         
1560
-      case ')':
1561
-      case 0:
1562
-      case ' ':        
1563
-      case '\n':
1564
-      default:
1545
+      case ')':   // ending paren.
1546
+      case 0:     // end of string
1547
+      case ' ':   // end of mark       
1548
+      case '\n':  // end of line
1549
+      default:    // anything else
1565 1550
         doneFl = true;
1566 1551
         break;
1567 1552
         
@@ -1571,25 +1556,26 @@ cmXsRC_t _cmXScoreReorderParseDyn(cmXScore_t* p, const cmChar_t* b, unsigned lin
1571 1556
   if( !doneFl )
1572 1557
     return cmErrMsg(&p->err,kSyntaxErrorXsRC,"Illegal dynamic mark (%s) syntax on line:%i.",mark,lineNumb);
1573 1558
 
1559
+  // look up the dynamic mark in the reference table
1574 1560
   for(j=0; _cmXScoreDynMarkArray[j].mark!=NULL; ++j)
1575
-    if( strcmp(mark,_cmXScoreDynMarkArray[i].mark) == 0 )
1561
+    if( strcmp(mark,_cmXScoreDynMarkArray[j].mark) == 0 )
1576 1562
       break;
1577 1563
 
1578
-  if( _cmXScoreDynMarkArray[i].mark == NULL )
1564
+  if( _cmXScoreDynMarkArray[j].mark == NULL )
1579 1565
     return cmErrMsg(&p->err,kSyntaxErrorXsRC,"The dynamic mark '%s' is not legal on line:%i.",mark,lineNumb);
1580 1566
 
1581 1567
 
1582
-  *dynIdRef = _cmXScoreDynMarkArray[i].id;
1568
+  *dynIdxRef = j;
1583 1569
       
1584 1570
   return rc;
1585 1571
 }
1586 1572
 
1587 1573
 
1588
-cmXsRC_t  _cmXScoreReorderParseSost(cmXScore_t* p, const cmChar_t* b, unsigned line, unsigned* sostIdRef )
1574
+cmXsRC_t  _cmXScoreReorderParseSost(cmXScore_t* p, const cmChar_t* b, unsigned line, unsigned* sostFlRef )
1589 1575
 {
1590 1576
   cmXsRC_t rc = kOkXsRC;
1591 1577
   const cmChar_t* s;
1592
-  *sostIdRef = 0;
1578
+  *sostFlRef = 0;
1593 1579
 
1594 1580
   if((s = strchr(b,'~')) == NULL )
1595 1581
     return rc;
@@ -1599,11 +1585,11 @@ cmXsRC_t  _cmXScoreReorderParseSost(cmXScore_t* p, const cmChar_t* b, unsigned l
1599 1585
   switch( *s )
1600 1586
   {
1601 1587
     case 'd':
1602
-      *sostIdRef = 1;  // pedal down just after this note onset
1588
+      *sostFlRef = kSostDnXsFl;  // pedal down just after this note onset
1603 1589
       break;
1604 1590
 
1605 1591
     case 'u':
1606
-      *sostIdRef = 2; // pedal up
1592
+      *sostFlRef = kSostUpXsFl; // pedal up
1607 1593
       break;
1608 1594
             
1609 1595
     default:
@@ -1707,14 +1693,15 @@ cmXsRC_t cmXScoreReorder( cmXsH_t h, const cmChar_t* fn )
1707 1693
             }
1708 1694
 
1709 1695
             
1710
-            // parse the dynamic marking
1711
-            if((rc = _cmXScoreReorderParseDyn(p,b,ln+1,&r.dynId)) != kOkXsRC )
1696
+            // parse the dynamic marking following a '!'
1697
+            if((rc = _cmXScoreReorderParseDyn(p,b,ln+1,&r.dynIdx)) != kOkXsRC )
1712 1698
               goto errLabel;
1713 1699
             
1714
-            // parse the sostenuto pedal marking
1715
-            if((rc = _cmXScoreReorderParseSost(p,b,ln+1, &r.sostId)) != kOkXsRC )
1700
+            // parse the sostenuto pedal marking 
1701
+            if((rc = _cmXScoreReorderParseSost(p,b,ln+1, &r.sostFl)) != kOkXsRC )
1716 1702
               goto errLabel;
1717 1703
 
1704
+            // parse the @newtick marker
1718 1705
             if((rc = _cmXScoreReorderParseTick(p, b, ln+1, &r.newTick)) != kOkXsRC )
1719 1706
               goto errLabel;            
1720 1707
 
@@ -1751,110 +1738,24 @@ cmXsRC_t cmXScoreReorder( cmXsH_t h, const cmChar_t* fn )
1751 1738
 
1752 1739
   }
1753 1740
 
1754
- errLabel:
1755
-  cmFileClose(&fH);
1756
-  cmMemFree(b);
1757
-  return rc;
1758
-}
1759
-
1741
+  // the ticks may have changed so the 'secs' and 'dsecs' must be updated
1742
+  _cmXScoreSetAbsoluteTime( p );
1760 1743
 
1761
-cmXsRC_t cmXScoreReorder1( cmXsH_t h, const cmChar_t* fn )
1762
-{
1763
-  typedef enum { kFindMeasStId, kFindEventStId, kReadEventStId } stateId_t;
1744
+  // the bar lines should be the first event in the measure
1745
+  _cmXScoreFixBarLines(p);
1764 1746
 
1765
-  cmXsRC_t      rc      = kOkXsRC;
1766
-  cmXScore_t*   p       = _cmXScoreHandleToPtr(h);
1767
-  cmFileH_t     fH      = cmFileNullHandle;
1768
-  cmFileH_t     ofH     = cmFileNullHandle;
1769
-  cmChar_t*     b       = NULL;
1770
-  unsigned      bN      = 0;
1771
-  unsigned      ln      = 0;
1772
-  unsigned      measNumb = 0;
1773
-  stateId_t     stateId = kFindMeasStId;
1774
-  const cmChar_t* ofn   = "/Users/kevin/temp/orig_reorder.txt";
1775
-  unsigned t0 = 0;
1776
-  
1777
-  if( cmFileOpen(&fH,fn,kReadFileFl,p->err.rpt) != kOkFileRC )
1778
-  {
1779
-    rc = cmErrMsg(&p->err,kFileFailXsRC,"The reordering file '%s' could not be opened.",cmStringNullGuard(fn));
1780
-    return rc;
1781
-  }
1782
-
1783
-  if( cmFileOpen(&ofH,ofn,kWriteFileFl,p->err.rpt) != kOkFileRC )
1784
-  {
1785
-    rc = cmErrMsg(&p->err,kFileFailXsRC,"The reordering file '%s' could not be opened.",cmStringNullGuard(ofn));
1786
-    goto errLabel;
1787
-  }
1747
+  // resort to force the links to be correct
1748
+  _cmXScoreSort(p);
1788 1749
   
1789
-
1790
-  for(; cmFileGetLineAuto(fH,&b,&bN)==kOkFileRC; ++ln)
1791
-  {
1792
-    bool fl = false;
1793
-    
1794
-    switch( stateId )
1795
-    {
1796
-      case kFindEventStId:  // scanning past labels to an event line
1797
-        {
1798
-          unsigned voice,loc;
1799
-          if( sscanf(b,"%i %i",&voice,&loc) != 2 )
1800
-            continue;
1801
-
1802
-          stateId = kReadEventStId;
1803
-          t0 = 0;
1804
-        }
1805
-        // fall through
1806
-
1807
-      case kReadEventStId:
1808
-        {
1809
-          cmXsReorder_t r;
1810
-          memset(&r,0,sizeof(r));
1811
-          
1812
-          // parse an event line
1813
-          if( sscanf(b,"%i %i %i %i %f",&r.voice,&r.locIdx,&r.tick,&r.durtn,&r.rval) == 5 )
1814
-          {
1815
-            if( r.tick < t0 )
1816
-              fl = true;
1817
-            t0 = r.tick; 
1818
-            break;
1819
-          }
1820
-          else
1821
-          {
1822
-          // the end of the measure was encountered -
1823
-          // reorder the measure based on the cmXsReorder_t in rV[ri]
1824
-            stateId = kFindMeasStId;
1825
-          }
1826
-          
1827
-          // fall through
1828
-        }
1829
-
1830
-      case kFindMeasStId:  // scanning for a bar-line
1831
-        {
1832
-          char colon;
1833
-          if( sscanf(b,"%i %c",&measNumb,&colon) == 2 && colon == ':' )
1834
-          {
1835
-            //printf("meas: %i \n",measNumb);
1836
-            stateId = kFindEventStId;
1837
-
1838
-          }
1839
-        }
1840
-        break;
1841
-    }
1842
-
1843
-    if( fl )
1844
-      b = cmTextInsertS(b,b+strlen(b)-1," <-----");
1845
-    
1846
-    cmFileWriteChar(ofH,b,strlen(b));
1847
-  }
1848
-
1849 1750
  errLabel:
1850 1751
   cmFileClose(&fH);
1851
-  cmFileClose(&ofH);
1852 1752
   cmMemFree(b);
1853 1753
   return rc;
1854 1754
 }
1855 1755
 
1856 1756
 
1857 1757
 
1758
+
1858 1759
 /*-------------------------------------------------------------------------------------------
1859 1760
 Dynamics File Format:
1860 1761
 <blk>*
@@ -2367,9 +2268,10 @@ cmXsRC_t cmXScoreWriteCsv( cmXsH_t h, const cmChar_t* csvFn )
2367 2268
               
2368 2269
               double          frac  = np->rvalue + (cmIsFlag(np->flags,kDotXsFl) ? (np->rvalue/2) : 0);
2369 2270
               const cmChar_t* dyn   = _cmXScoreTranslateDynamics( p,  np, dbuf, bufN );
2271
+              unsigned        vel   = np->vel==0 ? 60 : np->vel;
2370 2272
 
2371 2273
               //
2372
-              _cmXScoreWriteCsvRow(p,rowIdx,np->uid,mp->number,sectionIdStr,"non",np->dsecs,np->secs,np->pitch,60,np->pitch,frac,dyn,np->flags,
2274
+              _cmXScoreWriteCsvRow(p,rowIdx,np->uid,mp->number,sectionIdStr,"non",np->dsecs,np->secs,np->pitch,vel,np->pitch,frac,dyn,np->flags,
2373 2275
                 cmXsFormatMeasurementCsvField(np->flags, kEvenXsFl, 'e', np->evenGroupId,  ebuf, bufN ),
2374 2276
                 cmXsFormatMeasurementCsvField(np->flags, kTempoXsFl,'t', np->tempoGroupId, tbuf, bufN ));
2375 2277
               
@@ -2565,8 +2467,13 @@ cmXsRC_t cmXScoreTest(
2565 2467
   //  cmXScoreInsertDynamics(h, dynFn );
2566 2468
 
2567 2469
   if( reorderFn != NULL )
2470
+  {
2568 2471
     cmXScoreReorder(h,reorderFn);
2569 2472
 
2473
+      
2474
+
2475
+  }
2476
+  
2570 2477
   if( outFn != NULL )
2571 2478
   {
2572 2479
     cmScH_t scH = cmScNullHandle;

Loading…
Cancel
Save