Browse Source

cmMidiFile.c/h Added __cplusplus guards. Convert Note-on 0 vel. to Note-Off

master
kpl 11 years ago
parent
commit
41a33a0333
2 changed files with 28 additions and 0 deletions
  1. 16
    0
      cmMidiFile.c
  2. 12
    0
      cmMidiFile.h

+ 16
- 0
cmMidiFile.c View File

@@ -266,6 +266,10 @@ cmMfRC_t _cmMidiFileReadChannelMsg( _cmMidiFile_t* mfp, cmMidiByte_t* rsPtr, cmM
266 266
       return rc;
267 267
   }
268 268
 
269
+  // convert note-on velocity=0 to note off
270
+  if( tmp->status == kNoteOnMdId && p->d1==0 )
271
+    tmp->status = kNoteOffMdId;
272
+
269 273
   tmp->u.chMsgPtr = p;
270 274
   
271 275
   return rc;
@@ -833,13 +837,23 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
833 837
   _cmMidiVoice_t* vp;
834 838
   bool            sustainFlagV[ kMidiChCnt ];
835 839
 
840
+  for(mi=0; mi<kMidiChCnt; ++mi)
841
+    sustainFlagV[mi]=false;
842
+
836 843
   for(mi=0; mi<p->msgN; ++mi)
837 844
   {
838 845
     cmMidiTrackMsg_t* mp = p->msgV[mi];
839 846
 
840 847
     // update the duration of the sounding notes
848
+    //int ii=0;
849
+    //printf("---- %i ------\n",mi);
841 850
     for(vp = list; vp!=NULL; vp=vp->link)
851
+    {
842 852
       vp->durTicks += mp->dtick;
853
+      //printf("%i %i %p %p\n",ii,vp->sustainFl,vp,vp->link);
854
+      //++ii;
855
+    }
856
+    
843 857
 
844 858
     //
845 859
     // If this is sustain pedal msg
@@ -894,6 +908,8 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
894 908
           // if this active voice ch/pitch matches the note-off msg ch pitch 
895 909
           if( (vp->mp->u.chMsgPtr->d0==mp->u.chMsgPtr->d0) && (vp->mp->u.chMsgPtr->ch==mp->u.chMsgPtr->ch) )
896 910
           {
911
+            assert( mp->u.chMsgPtr->ch < kMidiChCnt );
912
+
897 913
             if( sustainFlagV[mp->u.chMsgPtr->ch] )
898 914
               vp->sustainFl = true;
899 915
             else

+ 12
- 0
cmMidiFile.h View File

@@ -1,6 +1,10 @@
1 1
 #ifndef cmMidiFile_h
2 2
 #define cmMidiFile_h
3 3
 
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
4 8
 // MIDI file timing:
5 9
 // Messages in the MIDI file are time tagged with a delta offset in 'ticks'
6 10
 // from the previous message in the same track.
@@ -15,6 +19,10 @@
15 19
 // MpQN is given as the value of the MIDI file tempo message.
16 20
 //
17 21
 // See cmMidiFileSeekUSecs() for an example of converting ticks to milliseconds.
22
+//
23
+// As part of the file reading process, the status byte of note-on messages 
24
+// with velocity=0 are is changed to a note-off message. See _cmMidiFileReadChannelMsg().
25
+
18 26
 
19 27
 
20 28
 typedef cmHandle_t cmMidiFileH_t;
@@ -159,5 +167,9 @@ unsigned              cmMidiFilePackTrackMsgBufByteCount( const cmMidiTrackMsg_t
159 167
 void                  cmMidiFilePrint( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt );
160 168
 bool                  cmMidiFileIsNull( cmMidiFileH_t h );
161 169
 void                  cmMidiFileTest( const char* fn, cmCtx_t* ctx );
170
+
171
+#ifdef __cplusplus
172
+}
173
+#endif
162 174
  
163 175
 #endif

Loading…
Cancel
Save