cmMidiFile.c : Added header to MIDI file report. Fixed rounding inaccuracy on atick in cmMidiFileOpen()

This commit is contained in:
kevin 2016-04-07 19:02:47 -04:00
parent c07d5fbc8d
commit f69fd6dcb0

View File

@ -533,11 +533,9 @@ cmMfRC_t cmMidiFileOpen( cmCtx_t* ctx, cmMidiFileH_t* hPtr, const char* fn )
{ {
unsigned tick = 0; unsigned tick = 0;
cmMidiTrackMsg_t* tmp = mfp->trkV[ trkIdx ].base; cmMidiTrackMsg_t* tmp = mfp->trkV[ trkIdx ].base;
microsPerTick = microsPerQN / mfp->ticksPerQN; microsPerTick = microsPerQN / mfp->ticksPerQN;
while( tmp != NULL ) while( tmp != NULL )
{ {
assert( i < mfp->msgN); 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 // sort msgV[] in ascending order on atick
qsort( mfp->msgV, mfp->msgN, sizeof(cmMidiTrackMsg_t*), _cmMidiFileSortFunc ); qsort( mfp->msgV, mfp->msgN, sizeof(cmMidiTrackMsg_t*), _cmMidiFileSortFunc );
// set the amicro field of each midi message to the // set the amicro field of each midi message to the
// absolute time offset in microseconds // absolute time offset in microseconds
unsigned mi; unsigned mi;
unsigned amicro = 0; double amicro = 0;
microsPerTick = microsPerQN / mfp->ticksPerQN; microsPerTick = microsPerQN / mfp->ticksPerQN;
for(mi=0; mi<mfp->msgN; ++mi) for(mi=0; mi<mfp->msgN; ++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; dtick = mp->atick - mfp->msgV[mi-1]->atick;
} }
amicro += round(microsPerTick*dtick); amicro += microsPerTick * dtick;
mp->amicro = amicro; mp->amicro = round(amicro);
} }
//for(i=0; i<25; ++i) //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,"%s ",mfp->fn);
cmRptPrintf(rpt,"fmt:%i ticksPerQN:%i tracks:%i\n",mfp->fmtId,mfp->ticksPerQN,mfp->trkN); 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 ) 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->uid,
tmp->dtick, tmp->dtick,
tmp->dmicro, tmp->dmicro,
@ -1530,6 +1535,8 @@ void cmMidiFileTest( const char* fn, cmCtx_t* ctx )
return; return;
} }
//cmMidiFileCalcNoteDurations( h );
if( 1 ) if( 1 )
{ {
//cmMidiFileTickToMicros( h ); //cmMidiFileTickToMicros( h );