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
       return rc;
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
   tmp->u.chMsgPtr = p;
273
   tmp->u.chMsgPtr = p;
270
   
274
   
271
   return rc;
275
   return rc;
833
   _cmMidiVoice_t* vp;
837
   _cmMidiVoice_t* vp;
834
   bool            sustainFlagV[ kMidiChCnt ];
838
   bool            sustainFlagV[ kMidiChCnt ];
835
 
839
 
840
+  for(mi=0; mi<kMidiChCnt; ++mi)
841
+    sustainFlagV[mi]=false;
842
+
836
   for(mi=0; mi<p->msgN; ++mi)
843
   for(mi=0; mi<p->msgN; ++mi)
837
   {
844
   {
838
     cmMidiTrackMsg_t* mp = p->msgV[mi];
845
     cmMidiTrackMsg_t* mp = p->msgV[mi];
839
 
846
 
840
     // update the duration of the sounding notes
847
     // update the duration of the sounding notes
848
+    //int ii=0;
849
+    //printf("---- %i ------\n",mi);
841
     for(vp = list; vp!=NULL; vp=vp->link)
850
     for(vp = list; vp!=NULL; vp=vp->link)
851
+    {
842
       vp->durTicks += mp->dtick;
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
     // If this is sustain pedal msg
859
     // If this is sustain pedal msg
894
           // if this active voice ch/pitch matches the note-off msg ch pitch 
908
           // if this active voice ch/pitch matches the note-off msg ch pitch 
895
           if( (vp->mp->u.chMsgPtr->d0==mp->u.chMsgPtr->d0) && (vp->mp->u.chMsgPtr->ch==mp->u.chMsgPtr->ch) )
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
             if( sustainFlagV[mp->u.chMsgPtr->ch] )
913
             if( sustainFlagV[mp->u.chMsgPtr->ch] )
898
               vp->sustainFl = true;
914
               vp->sustainFl = true;
899
             else
915
             else

+ 12
- 0
cmMidiFile.h View File

1
 #ifndef cmMidiFile_h
1
 #ifndef cmMidiFile_h
2
 #define cmMidiFile_h
2
 #define cmMidiFile_h
3
 
3
 
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
4
 // MIDI file timing:
8
 // MIDI file timing:
5
 // Messages in the MIDI file are time tagged with a delta offset in 'ticks'
9
 // Messages in the MIDI file are time tagged with a delta offset in 'ticks'
6
 // from the previous message in the same track.
10
 // from the previous message in the same track.
15
 // MpQN is given as the value of the MIDI file tempo message.
19
 // MpQN is given as the value of the MIDI file tempo message.
16
 //
20
 //
17
 // See cmMidiFileSeekUSecs() for an example of converting ticks to milliseconds.
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
 typedef cmHandle_t cmMidiFileH_t;
28
 typedef cmHandle_t cmMidiFileH_t;
159
 void                  cmMidiFilePrint( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt );
167
 void                  cmMidiFilePrint( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t* rpt );
160
 bool                  cmMidiFileIsNull( cmMidiFileH_t h );
168
 bool                  cmMidiFileIsNull( cmMidiFileH_t h );
161
 void                  cmMidiFileTest( const char* fn, cmCtx_t* ctx );
169
 void                  cmMidiFileTest( const char* fn, cmCtx_t* ctx );
170
+
171
+#ifdef __cplusplus
172
+}
173
+#endif
162
  
174
  
163
 #endif
175
 #endif

Loading…
Cancel
Save