cmMidiFile.h/c : Added cmMidiFileNoteTimeDensity().

This commit is contained in:
kevin 2016-09-14 15:47:13 -04:00
parent 19b90719aa
commit 780abd5e74
2 changed files with 44 additions and 1 deletions

View File

@ -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; i<msgN && k<msgN; ++i)
if( msgs[i]->status == 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;

View File

@ -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 );
//)