浏览代码

cmMidiFile.c : Added _cmMidiFileCalcNoteDurationsAllocVoice() to modularize

note duration tracking.
master
kevin 10 年前
父节点
当前提交
c21c04e2ca
共有 1 个文件被更改,包括 20 次插入8 次删除
  1. 20
    8
      cmMidiFile.c

+ 20
- 8
cmMidiFile.c 查看文件

@@ -1193,6 +1193,15 @@ void _cmMidFileCalcNoteDurationReleaseNote( _cmMidiVoice_t** listPtrPtr, _cmMidi
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 1205
 void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1197 1206
 {
1198 1207
   _cmMidiFile_t* p;
@@ -1231,8 +1240,12 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1231 1240
       // set the state of the sustain pedal flags
1232 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 1250
         // ... then release sustaining notes
1238 1251
         _cmMidiVoice_t* pp = NULL;
@@ -1254,11 +1267,7 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1254 1267
     //
1255 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 1272
     else
1264 1273
       //
@@ -1298,7 +1307,10 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
1298 1307
   while( vp != NULL )
1299 1308
   {
1300 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 1314
     cmMemFree(vp);
1303 1315
     vp = np;
1304 1316
   }

正在加载...
取消
保存