|
@@ -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
|
{
|