Browse Source

cmMidiFile.c : Added _cmMidiFileCalcNoteDurationsAllocVoice() to modularize

note duration tracking.
master
kevin 10 years ago
parent
commit
c21c04e2ca
1 changed files with 20 additions and 8 deletions
  1. 20
    8
      cmMidiFile.c

+ 20
- 8
cmMidiFile.c View File

1193
   
1193
   
1194
 }
1194
 }
1195
 
1195
 
1196
+void  _cmMidiFileCalcNoteDurationsAllocVoice( _cmMidiVoice_t** listPtrPtr, cmMidiTrackMsg_t* mp, bool sustainFl )
1197
+{
1198
+  _cmMidiVoice_t* vp = cmMemAllocZ(_cmMidiVoice_t,1);
1199
+  vp->mp        = mp;
1200
+  vp->sustainFl = sustainFl;
1201
+  vp->link      = *listPtrPtr;
1202
+  *listPtrPtr   = vp;
1203
+}
1204
+
1196
 void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1205
 void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1197
 {
1206
 {
1198
   _cmMidiFile_t* p;
1207
   _cmMidiFile_t* p;
1231
       // set the state of the sustain pedal flags
1240
       // set the state of the sustain pedal flags
1232
       sustainFlagV[chIdx] = mp->u.chMsgPtr->d1 >= 64;
1241
       sustainFlagV[chIdx] = mp->u.chMsgPtr->d1 >= 64;
1233
 
1242
 
1234
-      // if the pedal went up ...
1235
-      if( sustainFlagV[chIdx] == false )
1243
+      // if the pedal went down ...
1244
+      if( sustainFlagV[chIdx]  )
1245
+      {
1246
+        _cmMidiFileCalcNoteDurationsAllocVoice( &list, mp, true );
1247
+      }
1248
+      else // ... if the pedal went up
1236
       {
1249
       {
1237
         // ... then release sustaining notes
1250
         // ... then release sustaining notes
1238
         _cmMidiVoice_t* pp = NULL;
1251
         _cmMidiVoice_t* pp = NULL;
1254
     //
1267
     //
1255
     if( mp->status==kNoteOnMdId && mp->u.chMsgPtr->d1>0 )
1268
     if( mp->status==kNoteOnMdId && mp->u.chMsgPtr->d1>0 )
1256
     {
1269
     {
1257
-      vp = cmMemAllocZ(_cmMidiVoice_t,1);
1258
-      vp->mp        = mp;
1259
-      vp->sustainFl = false;
1260
-      vp->link      = list;
1261
-      list          = vp;
1270
+      _cmMidiFileCalcNoteDurationsAllocVoice( &list, mp, false );
1262
     }
1271
     }
1263
     else
1272
     else
1264
       //
1273
       //
1298
   while( vp != NULL )
1307
   while( vp != NULL )
1299
   {
1308
   {
1300
     np = vp->link;    
1309
     np = vp->link;    
1301
-    cmErrMsg(&p->err,kMissingNoteOffMfRC,"Missing note-off for note-on:%s",cmMidiToSciPitch(vp->mp->u.chMsgPtr->d0,NULL,0));
1310
+
1311
+    if( cmMidiIsNoteOn(vp->mp->status) == false )
1312
+      cmErrMsg(&p->err,kMissingNoteOffMfRC,"Missing note-off for note-on:%s",cmMidiToSciPitch(vp->mp->u.chMsgPtr->d0,NULL,0));
1313
+
1302
     cmMemFree(vp);
1314
     cmMemFree(vp);
1303
     vp = np;
1315
     vp = np;
1304
   }
1316
   }

Loading…
Cancel
Save