cmMidiFile.h/c : Added cmMidiFileSetVelocity().

This commit is contained in:
kevin 2016-06-16 12:50:43 -04:00
parent 2a6739ab0f
commit bdc1bdb61c
2 changed files with 38 additions and 1 deletions

View File

@ -1109,6 +1109,38 @@ const cmMidiTrackMsg_t** cmMidiFileMsgArray( cmMidiFileH_t h )
return (const cmMidiTrackMsg_t**)mfp->msgV; return (const cmMidiTrackMsg_t**)mfp->msgV;
} }
cmMidiTrackMsg_t* _cmMidiFileUidToMsg( _cmMidiFile_t* mfp, unsigned uid )
{
unsigned i;
for(i=0; i<mfp->msgN; ++i)
if( mfp->msgV[i]->uid == uid )
return mfp->msgV[i];
return NULL;
}
cmMfRC_t cmMidiFileSetVelocity( cmMidiFileH_t h, unsigned uid, cmMidiByte_t vel )
{
cmMidiTrackMsg_t* r;
_cmMidiFile_t* mfp = _cmMidiFileHandleToPtr(h);
assert( mfp != NULL );
if((r = _cmMidiFileUidToMsg(mfp,uid)) == NULL )
return cmErrMsg(&mfp->err,kUidNotFoundMfRC,"The MIDI file uid %i could not be found.",uid);
if( cmMidiIsNoteOn(r->status)==false && cmMidiIsNoteOff(r->status,0)==false )
return cmErrMsg(&mfp->err,kUidNotANoteMsgMfRC,"Cannot set velocity on a non-Note-On/Off msg.");
cmMidiChMsg_t* chm = (cmMidiChMsg_t*)r->u.chMsgPtr;
chm->d1 = vel;
return kOkMfRC;
}
unsigned cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned long long offsUSecs, unsigned* msgUsecsPtr, unsigned* microsPerTickPtr ) unsigned cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned long long offsUSecs, unsigned* msgUsecsPtr, unsigned* microsPerTickPtr )
{ {
_cmMidiFile_t* p; _cmMidiFile_t* p;

View File

@ -111,7 +111,9 @@ extern "C" {
kInvalidStatusMfRC, // 9 kInvalidStatusMfRC, // 9
kSustainPedalMfRC, // 10 kSustainPedalMfRC, // 10
kSostenutoPedalMfRC, // 11 kSostenutoPedalMfRC, // 11
kLargeDeltaTickMfRC // 12 (a large delta tick value was filtered) kLargeDeltaTickMfRC, // 12 (a large delta tick value was filtered)
kUidNotFoundMfRC, // 13
kUidNotANoteMsgMfRC // 14
}; };
extern cmMidiFileH_t cmMidiFileNullHandle; extern cmMidiFileH_t cmMidiFileNullHandle;
@ -156,6 +158,9 @@ extern "C" {
// Returns NULL if 'h' is invalid. // Returns NULL if 'h' is invalid.
const cmMidiTrackMsg_t** cmMidiFileMsgArray( cmMidiFileH_t h ); const cmMidiTrackMsg_t** cmMidiFileMsgArray( cmMidiFileH_t h );
// Set the velocity of a note-on/off msg identified by 'uid'.
cmMfRC_t cmMidiFileSetVelocity( cmMidiFileH_t h, unsigned uid, cmMidiByte_t vel );
// Return a pointer to the first msg at or after 'usecsOffs' or kInvalidIdx if no // Return a pointer to the first msg at or after 'usecsOffs' or kInvalidIdx if no
// msg exists after 'usecsOffs'. Note that 'usecOffs' is an offset from the beginning // msg exists after 'usecsOffs'. Note that 'usecOffs' is an offset from the beginning
// of the file. // of the file.