Bladeren bron

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

master
kevin 8 jaren geleden
bovenliggende
commit
1bc5d4dc65
1 gewijzigde bestanden met toevoegingen van 52 en 25 verwijderingen
  1. 52
    25
      app/cmXScore.c

+ 52
- 25
app/cmXScore.c Bestand weergeven

56
 
56
 
57
 typedef struct cmXsNote_str
57
 typedef struct cmXsNote_str
58
 {
58
 {
59
+  unsigned                    uid;      // unique id of this note record
59
   unsigned                    flags;    // See k???XsFl 
60
   unsigned                    flags;    // See k???XsFl 
60
   unsigned                    pitch;    // midi pitch
61
   unsigned                    pitch;    // midi pitch
61
   unsigned                    velocity; // midi velocity
62
   unsigned                    velocity; // midi velocity
126
   cmCsvH_t    csvH;
127
   cmCsvH_t    csvH;
127
   
128
   
128
   cmXsSpan_t* spanL;
129
   cmXsSpan_t* spanL;
130
+  unsigned    nextUid;
129
 } cmXScore_t;
131
 } cmXScore_t;
130
 
132
 
131
 cmXScore_t* _cmXScoreHandleToPtr( cmXsH_t h )
133
 cmXScore_t* _cmXScoreHandleToPtr( cmXsH_t h )
210
   }
212
   }
211
 
213
 
212
   note->voice = v;
214
   note->voice = v;
215
+  note->uid   = p->nextUid++;
213
 
216
 
214
   return kOkXsRC;
217
   return kOkXsRC;
215
 }
218
 }
982
           {
985
           {
983
             onset_secs += (np->tick - tick0) / ticks_per_sec;
986
             onset_secs += (np->tick - tick0) / ticks_per_sec;
984
             tick0       = np->tick;
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
 
1010
 
1008
   for(i=0; i<mN; ++i)
1011
   for(i=0; i<mN; ++i)
1009
     if( (m[i]!=NULL) && cmMidiIsChStatus(m[i]->status) && cmMidiIsNoteOn(m[i]->status) && (m[i]->u.chMsgPtr->d1>0) )
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
   cmFileClose(&fH);
1016
   cmFileClose(&fH);
1028
   if( cmMidiFileOpen(ctx, &mfH, midiFn ) != kOkMfRC )
1031
   if( cmMidiFileOpen(ctx, &mfH, midiFn ) != kOkMfRC )
1029
     return cmErrMsg(&p->err,kMidiFailXsRC,"The MIDI file object could not be opened from '%s'.",cmStringNullGuard(midiFn));
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
   if( (m = cmMidiFileMsgArray(mfH)) == NULL || (mN = cmMidiFileMsgCount(mfH)) == 0 )
1036
   if( (m = cmMidiFileMsgArray(mfH)) == NULL || (mN = cmMidiFileMsgCount(mfH)) == 0 )
1034
   {
1037
   {
1256
   unsigned i;
1259
   unsigned i;
1257
   for(i=1; s[i]!=NULL; ++i)
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
       return cmErrMsg(&p->err,kCsvFailXsRC,"CSV error inserting CSV title %i.\n",i);
1263
       return cmErrMsg(&p->err,kCsvFailXsRC,"CSV error inserting CSV title %i.\n",i);
1261
 
1264
 
1262
   }
1265
   }
1268
 {
1271
 {
1269
   unsigned i;
1272
   unsigned i;
1270
   for(i=0; i<cnt; ++i)
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
       return cmErrMsg(&p->err,kCsvFailXsRC,"CSV output failed on blank column.");
1275
       return cmErrMsg(&p->err,kCsvFailXsRC,"CSV output failed on blank column.");
1273
 
1276
 
1274
   return kOkCsvRC;    
1277
   return kOkCsvRC;    
1277
 cmXsRC_t _cmXScoreWriteCsvRow(
1280
 cmXsRC_t _cmXScoreWriteCsvRow(
1278
   cmXScore_t*     p,
1281
   cmXScore_t*     p,
1279
   unsigned        rowIdx,
1282
   unsigned        rowIdx,
1283
+  unsigned        uid,
1280
   unsigned        bar,
1284
   unsigned        bar,
1281
   const cmChar_t* sectionStr,
1285
   const cmChar_t* sectionStr,
1282
   const cmChar_t* opCodeStr,
1286
   const cmChar_t* opCodeStr,
1284
   double          secs,
1288
   double          secs,
1285
   unsigned        d0,
1289
   unsigned        d0,
1286
   unsigned        d1,
1290
   unsigned        d1,
1287
-  unsigned        pitch,
1291
+  unsigned        pitch,   // set to -1 if the pitch is not valid
1288
   double          frac,
1292
   double          frac,
1289
   unsigned        flags )
1293
   unsigned        flags )
1290
 {
1294
 {
1306
     goto errLabel;
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
     goto errLabel;
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
   // col 3 : output the opcode
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
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on opcode label.");
1337
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on opcode label.");
1318
     goto errLabel;
1338
     goto errLabel;
1351
   }
1371
   }
1352
 
1372
 
1353
   // col 11 : pitch
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
   // col 12 : blanks
1388
   // col 12 : blanks
1374
   // col 14 : skip (blank for now)
1402
   // col 14 : skip (blank for now)
1375
   if((rc = _cmXScoreWriteCsvBlankCols(p,1,&lcp)) != kOkXsRC )
1403
   if((rc = _cmXScoreWriteCsvBlankCols(p,1,&lcp)) != kOkXsRC )
1376
     goto errLabel;
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
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1409
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1382
     goto errLabel;
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
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1416
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1389
     goto errLabel;
1417
     goto errLabel;
1390
   }
1418
   }
1391
   
1419
   
1392
   // col 17: tempo
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
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1423
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1396
     goto errLabel;
1424
     goto errLabel;
1416
     goto errLabel;
1444
     goto errLabel;
1417
   
1445
   
1418
   // col 20: section
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
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1449
     rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV insert failed on eveness flag label.");
1422
     goto errLabel;
1450
     goto errLabel;
1423
   }
1451
   }
1424
   
1452
   
1425
-
1426
   // col 21, 22 : recd-play, remark (blank for now)
1453
   // col 21, 22 : recd-play, remark (blank for now)
1427
   if((rc = _cmXScoreWriteCsvBlankCols(p,2,&lcp)) != kOkXsRC )
1454
   if((rc = _cmXScoreWriteCsvBlankCols(p,2,&lcp)) != kOkXsRC )
1428
     goto errLabel;
1455
     goto errLabel;
1485
         // if this is a bar event
1512
         // if this is a bar event
1486
         if( cmIsFlag(np->flags,kBarXsFl) )
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
         else
1517
         else
1491
           
1518
           
1494
         {
1521
         {
1495
           unsigned d0 = 64; // pedal MIDI ctl id
1522
           unsigned d0 = 64; // pedal MIDI ctl id
1496
           unsigned d1 = cmIsFlag(np->flags,kPedalDnXsFl) ? 64 : 0; // pedal-dn: d1>=64 pedal-up:<64
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
         else 
1526
         else 
1500
 
1527
 
1501
 
1528
 
1502
           // if this is a sounding note event
1529
           // if this is a sounding note event
1503
-          if( cmIsNotFlag(np->flags,kRestXsFl) )
1530
+          if( cmIsFlag(np->flags,kOnsetXsFl) )
1504
           {
1531
           {
1505
             double frac = np->rvalue + (cmIsFlag(np->flags,kDotXsFl) ? (np->rvalue/2) : 0);
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
             sectionIdStr = NULL;
1536
             sectionIdStr = NULL;
1510
           }
1537
           }
1511
         
1538
         

Laden…
Annuleren
Opslaan