From 780abd5e74f88583e1b83670dacec9edc573efbe Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 14 Sep 2016 15:47:13 -0400 Subject: [PATCH] cmMidiFile.h/c : Added cmMidiFileNoteTimeDensity(). --- cmMidiFile.c | 32 ++++++++++++++++++++++++++++++++ cmMidiFile.h | 13 ++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/cmMidiFile.c b/cmMidiFile.c index fb26f63..8a18e8a 100644 --- a/cmMidiFile.c +++ b/cmMidiFile.c @@ -1907,6 +1907,38 @@ void cmMidiFilePrintTracks( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt ) void cmMidiFileTestPrint( void* printDataPtr, const char* fmt, va_list vl ) { vprintf(fmt,vl); } +cmMidiFileDensity_t* cmMidiFileNoteDensity( cmMidiFileH_t h, unsigned* cntRef ) +{ + int msgN = cmMidiFileMsgCount(h); + const cmMidiTrackMsg_t** msgs = cmMidiFileMsgArray(h); + cmMidiFileDensity_t* dV = cmMemAllocZ(cmMidiFileDensity_t,msgN); + + int i,j,k; + for(i=0,k=0; istatus == kNoteOnMdId && msgs[i]->u.chMsgPtr->d1 > 0 ) + { + dV[k].uid = msgs[i]->uid; + dV[k].amicro = msgs[i]->amicro; + + for(j=i; j>=0; --j) + { + if( msgs[i]->amicro - msgs[j]->amicro > 1000000 ) + break; + + dV[k].density += 1; + } + + k += 1; + + } + + if( cntRef != NULL ) + *cntRef = k; + + return dV; +} + + cmMfRC_t cmMidiFileGenPlotFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outFn ) { cmMfRC_t rc = kOkMfRC; diff --git a/cmMidiFile.h b/cmMidiFile.h index 55b8ef7..d54d1be 100644 --- a/cmMidiFile.h +++ b/cmMidiFile.h @@ -212,11 +212,22 @@ extern "C" { void cmMidiFilePrintMsgs( cmMidiFileH_t h, cmRpt_t* rpt ); void cmMidiFilePrintTrack( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt ); - void cmMidiFileTest( const char* fn, cmCtx_t* ctx ); + + typedef struct + { + unsigned uid; + unsigned long long amicro; + unsigned density; + + } cmMidiFileDensity_t; + cmMidiFileDensity_t* cmMidiFileNoteTimeDensity( cmMidiFileH_t h, unsigned* cntRef ); // Generate a piano-roll plot description file which can be displayed with cmXScore.m cmMfRC_t cmMidiFileGenPlotFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outFn ); + void cmMidiFileTest( const char* fn, cmCtx_t* ctx ); + + //)