Просмотр исходного кода

cmXScore.c : Added the 'uid' field to cmXScoreNote_t to hold a unique id for each note record.

master
kevin 8 лет назад
Родитель
Сommit
1bc5d4dc65
1 измененных файлов: 52 добавлений и 25 удалений
  1. 52
    25
      app/cmXScore.c

+ 52
- 25
app/cmXScore.c Просмотреть файл

@@ -56,6 +56,7 @@ struct cmXsVoice_str;
56 56
 
57 57
 typedef struct cmXsNote_str
58 58
 {
59
+  unsigned                    uid;      // unique id of this note record
59 60
   unsigned                    flags;    // See k???XsFl 
60 61
   unsigned                    pitch;    // midi pitch
61 62
   unsigned                    velocity; // midi velocity
@@ -126,6 +127,7 @@ typedef struct
126 127
   cmCsvH_t    csvH;
127 128
   
128 129
   cmXsSpan_t* spanL;
130
+  unsigned    nextUid;
129 131
 } cmXScore_t;
130 132
 
131 133
 cmXScore_t* _cmXScoreHandleToPtr( cmXsH_t h )
@@ -210,6 +212,7 @@ cmXsRC_t _cmXScorePushNote( cmXScore_t* p, cmXsMeas_t* meas, unsigned voiceId, c
210 212
   }
211 213
 
212 214
   note->voice = v;
215
+  note->uid   = p->nextUid++;
213 216
 
214 217
   return kOkXsRC;
215 218
 }
@@ -982,7 +985,7 @@ cmXsRC_t _cmXScoreWriteScorePlotFile( cmXScore_t* p, const cmChar_t* fn )
982 985
           {
983 986
             onset_secs += (np->tick - tick0) / ticks_per_sec;
984 987
             tick0       = np->tick;
985
-            cmFilePrintf(fH,"n %f %f %s %s\n",onset_secs,np->duration/ticks_per_sec,cmMidiToSciPitch(np->pitch,NULL,0),cmIsFlag(np->flags,kGraceXsFl)?"G":"N");
988
+            cmFilePrintf(fH,"n %f %f %i %s %s\n",onset_secs,np->duration/ticks_per_sec,np->uid,cmMidiToSciPitch(np->pitch,NULL,0),cmIsFlag(np->flags,kGraceXsFl)?"G":"N");
986 989
           }
987 990
         }
988 991
       }
@@ -1007,7 +1010,7 @@ cmXsRC_t _cmXScoreWriteMidiPlotFile( cmXScore_t* p, cmChar_t* fn, const cmMidiTr
1007 1010
 
1008 1011
   for(i=0; i<mN; ++i)
1009 1012
     if( (m[i]!=NULL) && cmMidiIsChStatus(m[i]->status) && cmMidiIsNoteOn(m[i]->status) && (m[i]->u.chMsgPtr->d1>0) )
1010
-      cmFilePrintf(fH,"n %f %f %s\n",m[i]->amicro/1000000.0,m[i]->u.chMsgPtr->durMicros/1000000.0,cmMidiToSciPitch(m[i]->u.chMsgPtr->d0,NULL,0));
1013
+      cmFilePrintf(fH,"n %f %f %i %s\n",m[i]->amicro/1000000.0,m[i]->u.chMsgPtr->durMicros/1000000.0,m[i]->uid,cmMidiToSciPitch(m[i]->u.chMsgPtr->d0,NULL,0));
1011 1014
 
1012 1015
   
1013 1016
   cmFileClose(&fH);
@@ -1028,7 +1031,7 @@ cmXsRC_t    _cmXScoreProcessMidi(cmXScore_t* p, cmCtx_t* ctx, const cmChar_t* mi
1028 1031
   if( cmMidiFileOpen(ctx, &mfH, midiFn ) != kOkMfRC )
1029 1032
     return cmErrMsg(&p->err,kMidiFailXsRC,"The MIDI file object could not be opened from '%s'.",cmStringNullGuard(midiFn));
1030 1033
 
1031
-  cmMidiFilePrintMsgs(mfH, p->err.rpt );
1034
+  //cmMidiFilePrintMsgs(mfH, p->err.rpt );
1032 1035
   
1033 1036
   if( (m = cmMidiFileMsgArray(mfH)) == NULL || (mN = cmMidiFileMsgCount(mfH)) == 0 )
1034 1037
   {
@@ -1256,7 +1259,7 @@ cmXsRC_t _cmXScoreWriteCsvHdr( cmXScore_t* p )
1256 1259
   unsigned i;
1257 1260
   for(i=1; s[i]!=NULL; ++i)
1258 1261
   {
1259
-    if( cmCsvInsertTextColAfter(p->csvH, lcp, &lcp, s[i], 0 ) != kOkCsvRC )
1262
+    if( cmCsvInsertIdentColAfter(p->csvH, lcp, &lcp, s[i], 0 ) != kOkCsvRC )
1260 1263
       return cmErrMsg(&p->err,kCsvFailXsRC,"CSV error inserting CSV title %i.\n",i);
1261 1264
 
1262 1265
   }
@@ -1268,7 +1271,7 @@ cmXsRC_t _cmXScoreWriteCsvBlankCols( cmXScore_t* p, unsigned cnt, cmCsvCell_t**
1268 1271
 {
1269 1272
   unsigned i;
1270 1273
   for(i=0; i<cnt; ++i)
1271
-    if( cmCsvInsertTextColAfter(p->csvH,*leftCellPtrPtr,leftCellPtrPtr,0,0) != kOkCsvRC )
1274
+    if( cmCsvInsertIdentColAfter(p->csvH,*leftCellPtrPtr,leftCellPtrPtr,"",0) != kOkCsvRC )
1272 1275
       return cmErrMsg(&p->err,kCsvFailXsRC,"CSV output failed on blank column.");
1273 1276
 
1274 1277
   return kOkCsvRC;    
@@ -1277,6 +1280,7 @@ cmXsRC_t _cmXScoreWriteCsvBlankCols( cmXScore_t* p, unsigned cnt, cmCsvCell_t**
1277 1280
 cmXsRC_t _cmXScoreWriteCsvRow(
1278 1281
   cmXScore_t*     p,
1279 1282
   unsigned        rowIdx,
1283
+  unsigned        uid,
1280 1284
   unsigned        bar,
1281 1285
   const cmChar_t* sectionStr,
1282 1286
   const cmChar_t* opCodeStr,
@@ -1284,7 +1288,7 @@ cmXsRC_t _cmXScoreWriteCsvRow(
1284 1288
   double          secs,
1285 1289
   unsigned        d0,
1286 1290
   unsigned        d1,
1287
-  unsigned        pitch,
1291
+  unsigned        pitch,   // set to -1 if the pitch is not valid
1288 1292
   double          frac,
1289 1293
   unsigned        flags )
1290 1294
 {
@@ -1306,13 +1310,29 @@ cmXsRC_t _cmXScoreWriteCsvRow(
1306 1310
     goto errLabel;
1307 1311
   }
1308 1312
   */
1309
-  
1310
-  // cols 1,2
1311
-  if((rc = _cmXScoreWriteCsvBlankCols(p,2,&lcp)) != kOkXsRC )
1313
+
1314
+  // col 1 : track (always 1)
1315
+  if( cmCsvInsertUIntColAfter(p->csvH,lcp,&lcp,1,0) != kOkCsvRC )
1316
+  {
1317
+    rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on 'd0'.");
1312 1318
     goto errLabel;
1319
+  }
1313 1320
 
1321
+  // col 2 : evt (set to event uid, or blank if uid == -1)
1322
+  if( uid == -1 )
1323
+  {
1324
+    if((rc = _cmXScoreWriteCsvBlankCols(p,1,&lcp)) != kOkXsRC )
1325
+      goto errLabel;
1326
+  } 
1327
+  else
1328
+  if( cmCsvInsertUIntColAfter(p->csvH,lcp,&lcp,uid,0) != kOkCsvRC )
1329
+  {
1330
+    rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on 'd0'.");
1331
+    goto errLabel;
1332
+  }
1333
+  
1314 1334
   // col 3 : output the opcode
1315
-  if( cmCsvInsertTextColAfter(p->csvH,lcp,&lcp,opCodeStr,0) != kOkCsvRC )
1335
+  if( cmCsvInsertIdentColAfter(p->csvH,lcp,&lcp,opCodeStr,0) != kOkCsvRC )
1316 1336
   {
1317 1337
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on opcode label.");
1318 1338
     goto errLabel;
@@ -1351,10 +1371,18 @@ cmXsRC_t _cmXScoreWriteCsvRow(
1351 1371
   }
1352 1372
 
1353 1373
   // col 11 : pitch
1354
-  if( cmCsvInsertUIntColAfter(p->csvH,lcp,&lcp,pitch,0) != kOkCsvRC )
1374
+  if( pitch == -1 )
1355 1375
   {
1356
-    rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on 'pitch'.");
1357
-    goto errLabel;
1376
+    if((rc = _cmXScoreWriteCsvBlankCols(p,1,&lcp)) != kOkXsRC )
1377
+      goto errLabel;
1378
+  }
1379
+  else
1380
+  {
1381
+    if( cmCsvInsertIdentColAfter(p->csvH,lcp,&lcp,cmMidiToSciPitch(pitch,NULL,0),0) != kOkCsvRC )
1382
+    {
1383
+      rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on 'pitch'.");
1384
+      goto errLabel;
1385
+    }
1358 1386
   }
1359 1387
   
1360 1388
   // col 12 : blanks
@@ -1374,23 +1402,23 @@ cmXsRC_t _cmXScoreWriteCsvRow(
1374 1402
   // col 14 : skip (blank for now)
1375 1403
   if((rc = _cmXScoreWriteCsvBlankCols(p,1,&lcp)) != kOkXsRC )
1376 1404
     goto errLabel;
1377
-
1378
-  // col 15: even
1379
-  if( cmCsvInsertTextColAfter(p->csvH,lcp,&lcp,cmIsFlag(flags,kEvenXsFl) ? "e" : "",0) != kOkCsvRC )
1405
+  
1406
+  // col 15: even (all grace notes are 'even' notes
1407
+  if( cmCsvInsertIdentColAfter(p->csvH,lcp,&lcp, cmIsFlag(flags,kGraceXsFl) | cmIsFlag(flags,kEvenXsFl) ? "e" : "",0) != kOkCsvRC )
1380 1408
   {
1381 1409
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1382 1410
     goto errLabel;
1383 1411
   }
1384 1412
 
1385
-  // col 16: grace
1386
-  if( cmCsvInsertTextColAfter(p->csvH,lcp,&lcp,cmIsFlag(flags,kGraceXsFl) ? "g" : "",0) != kOkCsvRC )
1413
+  // col 16: grace  
1414
+  if( cmCsvInsertIdentColAfter(p->csvH,lcp,&lcp,cmIsFlag(flags,kGraceXsFl) ? "g" : "",0) != kOkCsvRC )
1387 1415
   {
1388 1416
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1389 1417
     goto errLabel;
1390 1418
   }
1391 1419
   
1392 1420
   // col 17: tempo
1393
-  if( cmCsvInsertTextColAfter(p->csvH,lcp,&lcp,cmIsFlag(flags,kTempoXsFl) ? "t" : "",0) != kOkCsvRC )
1421
+  if( cmCsvInsertIdentColAfter(p->csvH,lcp,&lcp,cmIsFlag(flags,kTempoXsFl) ? "t" : "",0) != kOkCsvRC )
1394 1422
   {
1395 1423
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1396 1424
     goto errLabel;
@@ -1416,13 +1444,12 @@ cmXsRC_t _cmXScoreWriteCsvRow(
1416 1444
     goto errLabel;
1417 1445
   
1418 1446
   // col 20: section
1419
-  if( cmCsvInsertTextColAfter(p->csvH,lcp,&lcp,cmIsFlag(flags,kSectionXsFl) ? sectionStr : "",0) != kOkCsvRC )
1447
+  if( cmCsvInsertIdentColAfter(p->csvH,lcp,&lcp,cmIsFlag(flags,kSectionXsFl) ? sectionStr : "",0) != kOkCsvRC )
1420 1448
   {
1421 1449
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1422 1450
     goto errLabel;
1423 1451
   }
1424 1452
   
1425
-
1426 1453
   // col 21, 22 : recd-play, remark (blank for now)
1427 1454
   if((rc = _cmXScoreWriteCsvBlankCols(p,2,&lcp)) != kOkXsRC )
1428 1455
     goto errLabel;
@@ -1485,7 +1512,7 @@ cmXsRC_t cmXScoreWriteCsv( cmXsH_t h, const cmChar_t* csvFn )
1485 1512
         // if this is a bar event
1486 1513
         if( cmIsFlag(np->flags,kBarXsFl) )
1487 1514
         {
1488
-          _cmXScoreWriteCsvRow(p,rowIdx,mp->number,NULL,"bar",dsecs,sec1,0,0,0,0,np->flags);
1515
+          _cmXScoreWriteCsvRow(p,rowIdx,-1,mp->number,NULL,"bar",dsecs,sec1,0,0,-1,0,np->flags);
1489 1516
         }
1490 1517
         else
1491 1518
           
@@ -1494,18 +1521,18 @@ cmXsRC_t cmXScoreWriteCsv( cmXsH_t h, const cmChar_t* csvFn )
1494 1521
         {
1495 1522
           unsigned d0 = 64; // pedal MIDI ctl id
1496 1523
           unsigned d1 = cmIsFlag(np->flags,kPedalDnXsFl) ? 64 : 0; // pedal-dn: d1>=64 pedal-up:<64
1497
-          _cmXScoreWriteCsvRow(p,rowIdx,mp->number,NULL,"ctl",dsecs,sec1,d0,d1,0,0,np->flags);
1524
+          _cmXScoreWriteCsvRow(p,rowIdx,-1,mp->number,NULL,"ctl",dsecs,sec1,d0,d1,-1,0,np->flags);
1498 1525
         }
1499 1526
         else 
1500 1527
 
1501 1528
 
1502 1529
           // if this is a sounding note event
1503
-          if( cmIsNotFlag(np->flags,kRestXsFl) )
1530
+          if( cmIsFlag(np->flags,kOnsetXsFl) )
1504 1531
           {
1505 1532
             double frac = np->rvalue + (cmIsFlag(np->flags,kDotXsFl) ? (np->rvalue/2) : 0);
1506 1533
         
1507 1534
             // 
1508
-            _cmXScoreWriteCsvRow(p,rowIdx,mp->number,sectionIdStr,"non",dsecs,sec1,0,0,np->pitch,frac,np->flags);
1535
+            _cmXScoreWriteCsvRow(p,rowIdx,np->uid,mp->number,sectionIdStr,"non",dsecs,sec1,np->pitch,60,np->pitch,frac,np->flags);
1509 1536
             sectionIdStr = NULL;
1510 1537
           }
1511 1538
         

Загрузка…
Отмена
Сохранить