Browse Source

cmMidiFile.h/c : Added cmMidiFileNoteTimeDensity().

master
kevin 7 years ago
parent
commit
780abd5e74
2 changed files with 44 additions and 1 deletions
  1. 32
    0
      cmMidiFile.c
  2. 12
    1
      cmMidiFile.h

+ 32
- 0
cmMidiFile.c View File

@@ -1907,6 +1907,38 @@ void cmMidiFilePrintTracks( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt )
1907 1907
 void cmMidiFileTestPrint( void* printDataPtr, const char* fmt, va_list vl )
1908 1908
 { vprintf(fmt,vl); }
1909 1909
 
1910
+cmMidiFileDensity_t* cmMidiFileNoteDensity( cmMidiFileH_t h, unsigned* cntRef )
1911
+{
1912
+  int                      msgN = cmMidiFileMsgCount(h);
1913
+  const cmMidiTrackMsg_t** msgs = cmMidiFileMsgArray(h);
1914
+  cmMidiFileDensity_t*     dV   = cmMemAllocZ(cmMidiFileDensity_t,msgN);
1915
+  
1916
+  int i,j,k;
1917
+  for(i=0,k=0; i<msgN && k<msgN; ++i)
1918
+    if( msgs[i]->status == kNoteOnMdId && msgs[i]->u.chMsgPtr->d1 > 0 )
1919
+    {
1920
+      dV[k].uid    = msgs[i]->uid;
1921
+      dV[k].amicro = msgs[i]->amicro;
1922
+      
1923
+      for(j=i; j>=0; --j)
1924
+      {
1925
+        if( msgs[i]->amicro - msgs[j]->amicro > 1000000 )
1926
+          break;
1927
+
1928
+        dV[k].density += 1;
1929
+      }
1930
+      
1931
+      k += 1;
1932
+      
1933
+    }
1934
+
1935
+  if( cntRef != NULL )
1936
+    *cntRef = k;
1937
+
1938
+  return dV;
1939
+}
1940
+
1941
+
1910 1942
 cmMfRC_t cmMidiFileGenPlotFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outFn )
1911 1943
 {
1912 1944
   cmMfRC_t                 rc  = kOkMfRC;

+ 12
- 1
cmMidiFile.h View File

@@ -212,11 +212,22 @@ extern "C" {
212 212
 
213 213
   void                  cmMidiFilePrintMsgs( cmMidiFileH_t h, cmRpt_t* rpt );
214 214
   void                  cmMidiFilePrintTrack( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt );
215
-  void                  cmMidiFileTest( const char* fn, cmCtx_t* ctx );
215
+
216
+  typedef struct
217
+  {
218
+    unsigned           uid;
219
+    unsigned long long amicro;
220
+    unsigned           density;
221
+    
222
+  } cmMidiFileDensity_t;
223
+  cmMidiFileDensity_t* cmMidiFileNoteTimeDensity( cmMidiFileH_t h, unsigned* cntRef );
216 224
 
217 225
   // Generate a piano-roll plot description file which can be displayed with cmXScore.m
218 226
   cmMfRC_t             cmMidiFileGenPlotFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outFn );
219 227
 
228
+  void                  cmMidiFileTest( const char* fn, cmCtx_t* ctx );
229
+
230
+
220 231
   
221 232
   //)
222 233
   

Loading…
Cancel
Save