瀏覽代碼

cmMidiFile.h/c : Added cmMIdiFIlePrintMsgs(). Removed dead code in cmMidiFileTickToMicros() and cmMIdiFIleTickToSamples().

master
kevin 9 年之前
父節點
當前提交
04bfa83e38
共有 2 個檔案被更改,包括 57 行新增25 行删除
  1. 55
    24
      cmMidiFile.c
  2. 2
    1
      cmMidiFile.h

+ 55
- 24
cmMidiFile.c 查看文件

@@ -1112,8 +1112,7 @@ void cmMidiFileTickToMicros( cmMidiFileH_t h )
1112 1112
     return;
1113 1113
 
1114 1114
   unsigned mi;
1115
-  double r             = 1.0; //1000.0/(1000-.8);
1116
-  double microsPerQN   = r*60000000/120; // default tempo
1115
+  double microsPerQN   = 60000000/120; // default tempo
1117 1116
   double microsPerTick = microsPerQN / p->ticksPerQN;
1118 1117
 
1119 1118
   for(mi=0; mi<p->msgN; ++mi)
@@ -1121,8 +1120,8 @@ void cmMidiFileTickToMicros( cmMidiFileH_t h )
1121 1120
     cmMidiTrackMsg_t* mp = p->msgV[mi];
1122 1121
 
1123 1122
     if( mp->status == kMetaStId && mp->metaId == kTempoMdId )
1124
-      microsPerTick = r*mp->u.iVal / p->ticksPerQN;
1125
-
1123
+      microsPerTick = mp->u.iVal / p->ticksPerQN;
1124
+    
1126 1125
     mp->dtick = round(microsPerTick*mp->dtick);
1127 1126
   }
1128 1127
   
@@ -1139,8 +1138,7 @@ void cmMidiFileTickToSamples( cmMidiFileH_t h, double srate, bool absFl )
1139 1138
     return;
1140 1139
 
1141 1140
   unsigned mi;
1142
-  double r             = 1.0; //1000.0/(1000-.8);
1143
-  double microsPerQN   = r*60000000/120; // default tempo
1141
+  double microsPerQN   = 60000000/120; // default tempo
1144 1142
   double microsPerTick = microsPerQN / p->ticksPerQN;
1145 1143
   double absSmp = 0;
1146 1144
 
@@ -1149,7 +1147,7 @@ void cmMidiFileTickToSamples( cmMidiFileH_t h, double srate, bool absFl )
1149 1147
     cmMidiTrackMsg_t* mp = p->msgV[mi];
1150 1148
 
1151 1149
     if( mp->status == kMetaStId && mp->metaId == kTempoMdId )
1152
-      microsPerTick = r*mp->u.iVal / p->ticksPerQN;
1150
+      microsPerTick = mp->u.iVal / p->ticksPerQN;
1153 1151
 
1154 1152
     double delta = microsPerTick*mp->dtick*srate/1000000.0;
1155 1153
 
@@ -1389,16 +1387,52 @@ cmMidiTrackMsg_t*     cmMidiFilePackTrackMsg( const cmMidiTrackMsg_t* m, void* b
1389 1387
   return (cmMidiTrackMsg_t*)buf;
1390 1388
 }
1391 1389
 
1392
-
1393
-
1394
-void cmMidiFilePrint( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt )
1390
+void _cmMidiFilePrintHdr( const _cmMidiFile_t* mfp, cmRpt_t* rpt )
1395 1391
 {
1396
-  const _cmMidiFile_t* mfp = _cmMidiFileHandleToPtr(h);
1397
-
1398 1392
   if( mfp->fn != NULL )
1399 1393
     cmRptPrintf(rpt,"%s ",mfp->fn);
1400 1394
 
1401 1395
   cmRptPrintf(rpt,"fmt:%i ticksPerQN:%i tracks:%i\n",mfp->fmtId,mfp->ticksPerQN,mfp->trkN);
1396
+}
1397
+
1398
+void _cmMidiFilePrintMsg( cmRpt_t* rpt, const cmMidiTrackMsg_t* tmp )
1399
+{
1400
+  //cmRptPrintf(rpt,"%5.5f ", tmp->dtick/1000000.0 );
1401
+  cmRptPrintf(rpt,"%f ",    (double)tmp->dtick );
1402
+
1403
+  if( tmp->status == kMetaStId )
1404
+    cmRptPrintf(rpt,"%s ", cmMidiMetaStatusToLabel(tmp->metaId)); 
1405
+  else
1406
+  {
1407
+    cmRptPrintf(rpt,"%4s %3i %3i %3i", cmMidiStatusToLabel(tmp->status),tmp->u.chMsgPtr->ch,tmp->u.chMsgPtr->d0,tmp->u.chMsgPtr->d1);
1408
+    
1409
+  }
1410
+  
1411
+  cmRptPrintf(rpt,"\n");
1412
+}
1413
+
1414
+void cmMidiFilePrintMsgs( cmMidiFileH_t h, cmRpt_t* rpt )
1415
+{
1416
+  const _cmMidiFile_t* p = _cmMidiFileHandleToPtr(h);
1417
+  unsigned mi;
1418
+  
1419
+  _cmMidiFilePrintHdr(p,rpt);
1420
+
1421
+  for(mi=0; mi<p->msgN; ++mi)
1422
+  {
1423
+    cmMidiTrackMsg_t* mp = p->msgV[mi];
1424
+
1425
+    if( mp != NULL )
1426
+      _cmMidiFilePrintMsg(rpt,mp);
1427
+  }
1428
+  
1429
+}
1430
+
1431
+void cmMidiFilePrintTracks( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt )
1432
+{
1433
+  const _cmMidiFile_t* mfp = _cmMidiFileHandleToPtr(h);
1434
+
1435
+  _cmMidiFilePrintHdr(mfp,rpt);
1402 1436
 
1403 1437
   int i = trkIdx == cmInvalidIdx ? 0         : trkIdx;
1404 1438
   int n = trkIdx == cmInvalidIdx ? mfp->trkN : trkIdx+1;
@@ -1410,17 +1444,7 @@ void cmMidiFilePrint( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt )
1410 1444
     cmMidiTrackMsg_t* tmp = mfp->trkV[i].base;
1411 1445
     while( tmp != NULL )
1412 1446
     {
1413
-      cmRptPrintf(rpt,"%5i ", tmp->dtick );
1414
-
1415
-      if( tmp->status == kMetaStId )
1416
-        cmRptPrintf(rpt,"%s ", cmMidiMetaStatusToLabel(tmp->metaId)); 
1417
-      else
1418
-      {
1419
-        cmRptPrintf(rpt,"%4s %3i %3i %3i", cmMidiStatusToLabel(tmp->status),tmp->u.chMsgPtr->ch,tmp->u.chMsgPtr->d0,tmp->u.chMsgPtr->d1);
1420
-        
1421
-      }
1422
-
1423
-      cmRptPrintf(rpt,"\n");
1447
+      _cmMidiFilePrintMsg(rpt,tmp);
1424 1448
       tmp = tmp->link;
1425 1449
     }
1426 1450
   }  
@@ -1475,7 +1499,14 @@ void cmMidiFileTest( const char* fn, cmCtx_t* ctx )
1475 1499
     return;
1476 1500
   }
1477 1501
 
1478
-  if(1)
1502
+  if( 1 )
1503
+  {
1504
+    //cmMidiFileTickToMicros( h );
1505
+    cmMidiFileTickToSamples(h,96000,false);
1506
+    cmMidiFilePrintMsgs(h,&ctx->rpt);
1507
+  }
1508
+
1509
+  if( 0 )
1479 1510
   {
1480 1511
     //cmMidiFilePrint(h,cmMidiFileTrackCount(h)-1,&ctx->rpt);
1481 1512
     //cmMidiFilePrint(h,cmInvalidIdx,&ctx->rpt);

+ 2
- 1
cmMidiFile.h 查看文件

@@ -172,7 +172,8 @@ extern "C" {
172 172
   cmMidiTrackMsg_t*     cmMidiFilePackTrackMsg( const cmMidiTrackMsg_t* m, void* buf, unsigned bufByteCnt );
173 173
   unsigned              cmMidiFilePackTrackMsgBufByteCount( const cmMidiTrackMsg_t* m );
174 174
 
175
-  void                  cmMidiFilePrint( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt );
175
+  void                  cmMidiFilePrintMsgs( cmMidiFileH_t h, cmRpt_t* rpt );
176
+  void                  cmMidiFilePrintTrack( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt );
176 177
   bool                  cmMidiFileIsNull( cmMidiFileH_t h );
177 178
   void                  cmMidiFileTest( const char* fn, cmCtx_t* ctx );
178 179
 

Loading…
取消
儲存