Browse Source

cmMidiFile.c : cmMidiFileCalcNoteDuration() now update the durTicks field of

sustain pedal messages with the length of time the sustain pedal is held down.
master
Kevin Larke 9 years ago
parent
commit
ec6c2d8593
1 changed files with 24 additions and 4 deletions
  1. 24
    4
      cmMidiFile.c

+ 24
- 4
cmMidiFile.c View File

1212
   if( p->msgN == 0 )
1212
   if( p->msgN == 0 )
1213
     return;
1213
     return;
1214
 
1214
 
1215
-  unsigned        mi   = cmInvalidId;
1216
-  _cmMidiVoice_t* list = NULL;             // list of active voices
1217
-  _cmMidiVoice_t* vp   = NULL;
1218
-  bool            sustainFlagV[ kMidiChCnt ];
1215
+  unsigned          mi                  = cmInvalidId;
1216
+  _cmMidiVoice_t*   list                = NULL; // list of active voices
1217
+  _cmMidiVoice_t*   vp                  = NULL;
1218
+  cmMidiTrackMsg_t* sustainPedalDownMsg = NULL;
1219
+  bool              sustainFlagV[ kMidiChCnt ];
1219
 
1220
 
1220
   // clear the sustain pedal flag
1221
   // clear the sustain pedal flag
1221
   for(mi=0; mi<kMidiChCnt; ++mi)
1222
   for(mi=0; mi<kMidiChCnt; ++mi)
1229
     for(vp = list; vp!=NULL; vp=vp->link)
1230
     for(vp = list; vp!=NULL; vp=vp->link)
1230
       vp->durTicks += mp->dtick;    
1231
       vp->durTicks += mp->dtick;    
1231
 
1232
 
1233
+    // update the sustain pedal duration
1234
+    if( sustainPedalDownMsg != NULL )
1235
+      ((cmMidiChMsg_t*)(sustainPedalDownMsg->u.chMsgPtr))->durTicks += mp->dtick;  // cast away const
1236
+
1232
     //
1237
     //
1233
     // If this is sustain pedal msg
1238
     // If this is sustain pedal msg
1234
     //
1239
     //
1243
       // if the pedal went down ...
1248
       // if the pedal went down ...
1244
       if( sustainFlagV[chIdx]  )
1249
       if( sustainFlagV[chIdx]  )
1245
       {
1250
       {
1251
+
1252
+        if( sustainPedalDownMsg != NULL )
1253
+        {
1254
+          // TODO:  the correct way to handle this is to maintain multiple sustain pedals 
1255
+          cmErrMsg(&p->err,kSustainPedalMfRC,"Sustain pedal down with no intervening sustain pedal up.");
1256
+        }
1257
+        else
1258
+        {
1259
+          sustainPedalDownMsg = mp;
1260
+          ((cmMidiChMsg_t*)(sustainPedalDownMsg->u.chMsgPtr))->durTicks = 0;  // cast away const
1261
+        }
1262
+
1246
         _cmMidiFileCalcNoteDurationsAllocVoice( &list, mp, true );
1263
         _cmMidiFileCalcNoteDurationsAllocVoice( &list, mp, true );
1247
       }
1264
       }
1248
       else // ... if the pedal went up
1265
       else // ... if the pedal went up
1249
       {
1266
       {
1267
+
1268
+        sustainPedalDownMsg = NULL;
1269
+
1250
         // ... then release sustaining notes
1270
         // ... then release sustaining notes
1251
         _cmMidiVoice_t* pp = NULL;
1271
         _cmMidiVoice_t* pp = NULL;
1252
         for(vp=list; vp != NULL; )
1272
         for(vp=list; vp != NULL; )

Loading…
Cancel
Save