Bläddra i källkod

cmMidiFile.h/c : Added cmMidiFileSetVelocity().

master
kevin 8 år sedan
förälder
incheckning
bdc1bdb61c
2 ändrade filer med 38 tillägg och 1 borttagningar
  1. 32
    0
      cmMidiFile.c
  2. 6
    1
      cmMidiFile.h

+ 32
- 0
cmMidiFile.c Visa fil

@@ -1109,6 +1109,38 @@ const cmMidiTrackMsg_t** cmMidiFileMsgArray(    cmMidiFileH_t h )
1109 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 1144
 unsigned  cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned long long offsUSecs, unsigned* msgUsecsPtr, unsigned* microsPerTickPtr )
1113 1145
 {
1114 1146
   _cmMidiFile_t* p;

+ 6
- 1
cmMidiFile.h Visa fil

@@ -111,7 +111,9 @@ extern "C" {
111 111
     kInvalidStatusMfRC,  //  9
112 112
     kSustainPedalMfRC,   // 10
113 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 119
   extern cmMidiFileH_t cmMidiFileNullHandle;
@@ -156,6 +158,9 @@ extern "C" {
156 158
   // Returns NULL if 'h' is invalid.
157 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 164
   // Return a pointer to the first msg at or after 'usecsOffs' or kInvalidIdx if no
160 165
   // msg exists after 'usecsOffs'.  Note that 'usecOffs' is an offset from the beginning
161 166
   // of the file.

Laddar…
Avbryt
Spara