Переглянути джерело

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 роки тому
джерело
коміт
ec6c2d8593
1 змінених файлів з 24 додано та 4 видалено
  1. 24
    4
      cmMidiFile.c

+ 24
- 4
cmMidiFile.c Переглянути файл

@@ -1212,10 +1212,11 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1212 1212
   if( p->msgN == 0 )
1213 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 1221
   // clear the sustain pedal flag
1221 1222
   for(mi=0; mi<kMidiChCnt; ++mi)
@@ -1229,6 +1230,10 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1229 1230
     for(vp = list; vp!=NULL; vp=vp->link)
1230 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 1238
     // If this is sustain pedal msg
1234 1239
     //
@@ -1243,10 +1248,25 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1243 1248
       // if the pedal went down ...
1244 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 1263
         _cmMidiFileCalcNoteDurationsAllocVoice( &list, mp, true );
1247 1264
       }
1248 1265
       else // ... if the pedal went up
1249 1266
       {
1267
+
1268
+        sustainPedalDownMsg = NULL;
1269
+
1250 1270
         // ... then release sustaining notes
1251 1271
         _cmMidiVoice_t* pp = NULL;
1252 1272
         for(vp=list; vp != NULL; )

Завантаження…
Відмінити
Зберегти