From f69fd6dcb037a0b1135250360b75ff1f77c6912c Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 7 Apr 2016 19:02:47 -0400 Subject: [PATCH] cmMidiFile.c : Added header to MIDI file report. Fixed rounding inaccuracy on atick in cmMidiFileOpen() --- cmMidiFile.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cmMidiFile.c b/cmMidiFile.c index 0a8cf5f..d9b2aa5 100644 --- a/cmMidiFile.c +++ b/cmMidiFile.c @@ -533,11 +533,9 @@ cmMfRC_t cmMidiFileOpen( cmCtx_t* ctx, cmMidiFileH_t* hPtr, const char* fn ) { unsigned tick = 0; cmMidiTrackMsg_t* tmp = mfp->trkV[ trkIdx ].base; - microsPerTick = microsPerQN / mfp->ticksPerQN; - - + while( tmp != NULL ) { assert( i < mfp->msgN); @@ -559,13 +557,16 @@ cmMfRC_t cmMidiFileOpen( cmCtx_t* ctx, cmMidiFileH_t* hPtr, const char* fn ) } } + + + // sort msgV[] in ascending order on atick qsort( mfp->msgV, mfp->msgN, sizeof(cmMidiTrackMsg_t*), _cmMidiFileSortFunc ); // set the amicro field of each midi message to the // absolute time offset in microseconds unsigned mi; - unsigned amicro = 0; + double amicro = 0; microsPerTick = microsPerQN / mfp->ticksPerQN; for(mi=0; mimsgN; ++mi) @@ -583,8 +584,8 @@ cmMfRC_t cmMidiFileOpen( cmCtx_t* ctx, cmMidiFileH_t* hPtr, const char* fn ) dtick = mp->atick - mfp->msgV[mi-1]->atick; } - amicro += round(microsPerTick*dtick); - mp->amicro = amicro; + amicro += microsPerTick * dtick; + mp->amicro = round(amicro); } //for(i=0; i<25; ++i) @@ -1376,11 +1377,15 @@ void _cmMidiFilePrintHdr( const _cmMidiFile_t* mfp, cmRpt_t* rpt ) cmRptPrintf(rpt,"%s ",mfp->fn); cmRptPrintf(rpt,"fmt:%i ticksPerQN:%i tracks:%i\n",mfp->fmtId,mfp->ticksPerQN,mfp->trkN); + + cmRptPrintf(rpt," UID dtick dmicro atick amicro type ch D0 D1\n"); + cmRptPrintf(rpt,"----- ---------- ---------- ---------- ---------- : ---- --- --- ---\n"); + } void _cmMidiFilePrintMsg( cmRpt_t* rpt, const cmMidiTrackMsg_t* tmp ) { - cmRptPrintf(rpt,"%5i %8i %8i %8i %8i : ", + cmRptPrintf(rpt,"%5i %10u %10u %10u %10u : ", tmp->uid, tmp->dtick, tmp->dmicro, @@ -1530,6 +1535,8 @@ void cmMidiFileTest( const char* fn, cmCtx_t* ctx ) return; } + //cmMidiFileCalcNoteDurations( h ); + if( 1 ) { //cmMidiFileTickToMicros( h );