Browse Source

cmMidiFile.h/c : Added cmMidiFileSetVelocity().

master
kevin 8 years ago
parent
commit
bdc1bdb61c
2 changed files with 38 additions and 1 deletions
  1. 32
    0
      cmMidiFile.c
  2. 6
    1
      cmMidiFile.h

+ 32
- 0
cmMidiFile.c View File

1109
   return (const cmMidiTrackMsg_t**)mfp->msgV;
1109
   return (const cmMidiTrackMsg_t**)mfp->msgV;
1110
 }
1110
 }
1111
 
1111
 
1112
+
1113
+cmMidiTrackMsg_t*  _cmMidiFileUidToMsg( _cmMidiFile_t* mfp, unsigned uid )
1114
+{
1115
+  unsigned i;
1116
+
1117
+  for(i=0; i<mfp->msgN; ++i)
1118
+    if( mfp->msgV[i]->uid == uid )
1119
+      return mfp->msgV[i];
1120
+
1121
+  return NULL;
1122
+}
1123
+
1124
+cmMfRC_t cmMidiFileSetVelocity( cmMidiFileH_t h, unsigned uid, cmMidiByte_t vel )
1125
+{
1126
+  cmMidiTrackMsg_t* r;
1127
+  _cmMidiFile_t* mfp = _cmMidiFileHandleToPtr(h);
1128
+
1129
+  assert( mfp != NULL );
1130
+
1131
+  if((r = _cmMidiFileUidToMsg(mfp,uid)) == NULL )
1132
+    return cmErrMsg(&mfp->err,kUidNotFoundMfRC,"The MIDI file uid %i could not be found.",uid);
1133
+
1134
+  if( cmMidiIsNoteOn(r->status)==false && cmMidiIsNoteOff(r->status,0)==false )
1135
+    return cmErrMsg(&mfp->err,kUidNotANoteMsgMfRC,"Cannot set velocity on a non-Note-On/Off msg.");
1136
+  
1137
+  cmMidiChMsg_t* chm = (cmMidiChMsg_t*)r->u.chMsgPtr;
1138
+
1139
+  chm->d1 = vel;
1140
+
1141
+  return kOkMfRC;
1142
+}
1143
+
1112
 unsigned  cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned long long offsUSecs, unsigned* msgUsecsPtr, unsigned* microsPerTickPtr )
1144
 unsigned  cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned long long offsUSecs, unsigned* msgUsecsPtr, unsigned* microsPerTickPtr )
1113
 {
1145
 {
1114
   _cmMidiFile_t* p;
1146
   _cmMidiFile_t* p;

+ 6
- 1
cmMidiFile.h View File

111
     kInvalidStatusMfRC,  //  9
111
     kInvalidStatusMfRC,  //  9
112
     kSustainPedalMfRC,   // 10
112
     kSustainPedalMfRC,   // 10
113
     kSostenutoPedalMfRC, // 11
113
     kSostenutoPedalMfRC, // 11
114
-    kLargeDeltaTickMfRC  // 12 (a large delta tick value was filtered)
114
+    kLargeDeltaTickMfRC, // 12 (a large delta tick value was filtered)
115
+    kUidNotFoundMfRC,    // 13
116
+    kUidNotANoteMsgMfRC  // 14
115
   };
117
   };
116
 
118
 
117
   extern cmMidiFileH_t cmMidiFileNullHandle;
119
   extern cmMidiFileH_t cmMidiFileNullHandle;
156
   // Returns NULL if 'h' is invalid.
158
   // Returns NULL if 'h' is invalid.
157
   const cmMidiTrackMsg_t** cmMidiFileMsgArray( cmMidiFileH_t h );
159
   const cmMidiTrackMsg_t** cmMidiFileMsgArray( cmMidiFileH_t h );
158
 
160
 
161
+  // Set the velocity of a note-on/off msg identified by 'uid'.
162
+  cmMfRC_t             cmMidiFileSetVelocity( cmMidiFileH_t h, unsigned uid, cmMidiByte_t vel );
163
+
159
   // Return a pointer to the first msg at or after 'usecsOffs' or kInvalidIdx if no
164
   // Return a pointer to the first msg at or after 'usecsOffs' or kInvalidIdx if no
160
   // msg exists after 'usecsOffs'.  Note that 'usecOffs' is an offset from the beginning
165
   // msg exists after 'usecsOffs'.  Note that 'usecOffs' is an offset from the beginning
161
   // of the file.
166
   // of the file.

Loading…
Cancel
Save