Browse Source

cmMidiFile.h/c : In cmMIdiFileInsertTrack???() return the 'uid' of the new event record.

master
kevin 8 years ago
parent
commit
3ef0c6fd3a
2 changed files with 16 additions and 8 deletions
  1. 13
    5
      cmMidiFile.c
  2. 3
    3
      cmMidiFile.h

+ 13
- 5
cmMidiFile.c View File

1368
 
1368
 
1369
 }
1369
 }
1370
 
1370
 
1371
-cmMfRC_t  cmMidiFileInsertTrackMsg( cmMidiFileH_t h, unsigned trkIdx, const cmMidiTrackMsg_t* msg )
1371
+cmMfRC_t  cmMidiFileInsertTrackMsg( cmMidiFileH_t h, unsigned trkIdx, const cmMidiTrackMsg_t* msg, unsigned* uidRef )
1372
 {
1372
 {
1373
   _cmMidiFile_t* p = _cmMidiFileHandleToPtr(h);
1373
   _cmMidiFile_t* p = _cmMidiFileHandleToPtr(h);
1374
 
1374
 
1375
+  if( uidRef != NULL )
1376
+    *uidRef = cmInvalidId;
1377
+
1375
   // validate the track index
1378
   // validate the track index
1376
   if( trkIdx >= p->trkN )
1379
   if( trkIdx >= p->trkN )
1377
     return cmErrMsg(&p->err,kInvalidTrkIndexMfRC,"The track index (%i) is invalid.",trkIdx);
1380
     return cmErrMsg(&p->err,kInvalidTrkIndexMfRC,"The track index (%i) is invalid.",trkIdx);
1395
     memcpy((void*)m->u.voidPtr,msg->u.voidPtr,msg->byteCnt);
1398
     memcpy((void*)m->u.voidPtr,msg->u.voidPtr,msg->byteCnt);
1396
   }
1399
   }
1397
 
1400
 
1401
+  if( uidRef != NULL )
1402
+    *uidRef = m->uid;
1403
+  
1398
   cmMidiTrackMsg_t* m0 = NULL;                  // msg before insertion
1404
   cmMidiTrackMsg_t* m0 = NULL;                  // msg before insertion
1399
   cmMidiTrackMsg_t* m1 = p->trkV[trkIdx].base;  // msg after insertion
1405
   cmMidiTrackMsg_t* m1 = p->trkV[trkIdx].base;  // msg after insertion
1400
 
1406
 
1448
 
1454
 
1449
   p->trkV[trkIdx].cnt += 1;  
1455
   p->trkV[trkIdx].cnt += 1;  
1450
   p->msgVDirtyFl = true;
1456
   p->msgVDirtyFl = true;
1457
+
1458
+
1451
   
1459
   
1452
   return kOkMfRC;
1460
   return kOkMfRC;
1453
    
1461
    
1454
 }
1462
 }
1455
 
1463
 
1456
-cmMfRC_t  cmMidiFileInsertTrackChMsg( cmMidiFileH_t h, unsigned trkIdx, unsigned atick, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 )
1464
+cmMfRC_t  cmMidiFileInsertTrackChMsg( cmMidiFileH_t h, unsigned trkIdx, unsigned atick, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1, unsigned* uidRef )
1457
 {
1465
 {
1458
   cmMidiTrackMsg_t m;
1466
   cmMidiTrackMsg_t m;
1459
   cmMidiChMsg_t   cm;
1467
   cmMidiChMsg_t   cm;
1472
 
1480
 
1473
   assert( m.status >= kNoteOffMdId && m.status <= kPbendMdId );
1481
   assert( m.status >= kNoteOffMdId && m.status <= kPbendMdId );
1474
   
1482
   
1475
-  return cmMidiFileInsertTrackMsg(h,trkIdx,&m);
1483
+  return cmMidiFileInsertTrackMsg(h,trkIdx,&m,uidRef);
1476
 }
1484
 }
1477
 
1485
 
1478
-cmMfRC_t  cmMidFileInsertTrackTempoMsg( cmMidiFileH_t h, unsigned trkIdx, unsigned atick, unsigned bpm )
1486
+cmMfRC_t  cmMidFileInsertTrackTempoMsg( cmMidiFileH_t h, unsigned trkIdx, unsigned atick, unsigned bpm, unsigned* uidRef )
1479
 {
1487
 {
1480
   cmMidiTrackMsg_t m;
1488
   cmMidiTrackMsg_t m;
1481
 
1489
 
1486
   m.metaId     = kTempoMdId;
1494
   m.metaId     = kTempoMdId;
1487
   m.u.iVal     = 60000000/bpm;  // convert BPM to microsPerQN
1495
   m.u.iVal     = 60000000/bpm;  // convert BPM to microsPerQN
1488
   
1496
   
1489
-  return cmMidiFileInsertTrackMsg(h,trkIdx,&m);
1497
+  return cmMidiFileInsertTrackMsg(h,trkIdx,&m,uidRef);
1490
 }
1498
 }
1491
 
1499
 
1492
 
1500
 

+ 3
- 3
cmMidiFile.h View File

185
   //   byteCnt  - used to allocate storage for the data element in 'cmMidiTrackMsg_t.u'
185
   //   byteCnt  - used to allocate storage for the data element in 'cmMidiTrackMsg_t.u'
186
   //   u        - the message data
186
   //   u        - the message data
187
   //
187
   //
188
-  cmMfRC_t             cmMidiFileInsertTrackMsg(     cmMidiFileH_t h, unsigned trkIdx, const cmMidiTrackMsg_t* msg );
189
-  cmMfRC_t             cmMidiFileInsertTrackChMsg(   cmMidiFileH_t h, unsigned trkIdx, unsigned atick, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 );
190
-  cmMfRC_t             cmMidFileInsertTrackTempoMsg( cmMidiFileH_t h, unsigned trkIdx, unsigned atick, unsigned bpm );
188
+  cmMfRC_t             cmMidiFileInsertTrackMsg(     cmMidiFileH_t h, unsigned trkIdx, const cmMidiTrackMsg_t* msg, unsigned* uidRef );
189
+  cmMfRC_t             cmMidiFileInsertTrackChMsg(   cmMidiFileH_t h, unsigned trkIdx, unsigned atick, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1, unsigned* uidRef );
190
+  cmMfRC_t             cmMidFileInsertTrackTempoMsg( cmMidiFileH_t h, unsigned trkIdx, unsigned atick, unsigned bpm, unsigned* uidRef );
191
   
191
   
192
   // Return a pointer to the first msg at or after 'usecsOffs' or kInvalidIdx if no
192
   // Return a pointer to the first msg at or after 'usecsOffs' or kInvalidIdx if no
193
   // msg exists after 'usecsOffs'.  Note that 'usecOffs' is an offset from the beginning
193
   // msg exists after 'usecsOffs'.  Note that 'usecOffs' is an offset from the beginning

Loading…
Cancel
Save