Browse Source

cmMidiFile.h/c : Added cmMidiFileGenPlotFile().

master
kevin 8 years ago
parent
commit
7f84595d08
2 changed files with 39 additions and 0 deletions
  1. 35
    0
      cmMidiFile.c
  2. 4
    0
      cmMidiFile.h

+ 35
- 0
cmMidiFile.c View File

@@ -1453,6 +1453,41 @@ bool cmMidiFileIsNull( cmMidiFileH_t h )
1453 1453
 void cmMidiFileTestPrint( void* printDataPtr, const char* fmt, va_list vl )
1454 1454
 { vprintf(fmt,vl); }
1455 1455
 
1456
+cmMfRC_t cmMidiFileGenPlotFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outFn )
1457
+{
1458
+  cmMfRC_t                 rc  = kOkMfRC;
1459
+  cmMidiFileH_t            mfH = cmMidiFileNullHandle;  
1460
+  cmFileH_t                fH  = cmFileNullHandle;
1461
+  unsigned                 i   = 0;
1462
+  const cmMidiTrackMsg_t** m   = NULL;
1463
+  unsigned                 mN  = 0;
1464
+
1465
+  if((rc = cmMidiFileOpen(ctx, &mfH, midiFn )) != kOkMfRC )
1466
+    return cmErrMsg(&ctx->err,rc,"The MIDI file object could not be opened from '%s'.",cmStringNullGuard(midiFn));
1467
+
1468
+  _cmMidiFile_t* p = _cmMidiFileHandleToPtr(mfH);
1469
+  
1470
+  if( (m = cmMidiFileMsgArray(mfH)) == NULL || (mN = cmMidiFileMsgCount(mfH)) == 0 )
1471
+  {
1472
+    rc = cmErrMsg(&p->err,kFileFailMfRC,"The MIDI file object appears to be empty.");
1473
+    goto errLabel;
1474
+  }
1475
+  
1476
+  cmMidiFileCalcNoteDurations( mfH );
1477
+  
1478
+  if( cmFileOpen(&fH,outFn,kWriteFileFl,p->err.rpt) != kOkFileRC )
1479
+    return cmErrMsg(&p->err,kFileFailMfRC,"Unable to create the file '%s'.",cmStringNullGuard(outFn));
1480
+
1481
+  for(i=0; i<mN; ++i)
1482
+    if( (m[i]!=NULL) && cmMidiIsChStatus(m[i]->status) && cmMidiIsNoteOn(m[i]->status) && (m[i]->u.chMsgPtr->d1>0) )
1483
+      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));
1484
+
1485
+ errLabel:
1486
+  
1487
+  cmMidiFileClose(&mfH);
1488
+  cmFileClose(&fH);
1489
+  return rc;
1490
+}
1456 1491
 
1457 1492
 void cmMidiFilePrintControlNumbers( cmCtx_t* ctx, const char* fn )
1458 1493
 {

+ 4
- 0
cmMidiFile.h View File

@@ -172,6 +172,10 @@ extern "C" {
172 172
   bool                  cmMidiFileIsNull( cmMidiFileH_t h );
173 173
   void                  cmMidiFileTest( const char* fn, cmCtx_t* ctx );
174 174
 
175
+  // Generate a piano-roll plot description file which can be displayed with cmXScore.m
176
+  cmMfRC_t             cmMidiFileGenPlotFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outFn );
177
+
178
+  
175 179
   //)
176 180
   
177 181
 #ifdef __cplusplus

Loading…
Cancel
Save