From bdc1bdb61cf9a1163b10ff67a42e378dee8ab68c Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 16 Jun 2016 12:50:43 -0400 Subject: [PATCH] cmMidiFile.h/c : Added cmMidiFileSetVelocity(). --- cmMidiFile.c | 32 ++++++++++++++++++++++++++++++++ cmMidiFile.h | 7 ++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/cmMidiFile.c b/cmMidiFile.c index 672b2f9..873295f 100644 --- a/cmMidiFile.c +++ b/cmMidiFile.c @@ -1109,6 +1109,38 @@ const cmMidiTrackMsg_t** cmMidiFileMsgArray( cmMidiFileH_t h ) return (const cmMidiTrackMsg_t**)mfp->msgV; } + +cmMidiTrackMsg_t* _cmMidiFileUidToMsg( _cmMidiFile_t* mfp, unsigned uid ) +{ + unsigned i; + + for(i=0; imsgN; ++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 ) { _cmMidiFile_t* p; diff --git a/cmMidiFile.h b/cmMidiFile.h index 6155476..34d3377 100644 --- a/cmMidiFile.h +++ b/cmMidiFile.h @@ -111,7 +111,9 @@ extern "C" { kInvalidStatusMfRC, // 9 kSustainPedalMfRC, // 10 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; @@ -156,6 +158,9 @@ extern "C" { // Returns NULL if 'h' is invalid. 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 // msg exists after 'usecsOffs'. Note that 'usecOffs' is an offset from the beginning // of the file.