cmMidiFile.c : cmMidiFileCalcNoteDuration() now update the durTicks field of

sustain pedal messages with the length of time the sustain pedal is held down.
This commit is contained in:
Kevin Larke 2015-02-24 15:39:38 -08:00
parent 1a0b88016e
commit ec6c2d8593

View File

@ -1215,6 +1215,7 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
unsigned mi = cmInvalidId;
_cmMidiVoice_t* list = NULL; // list of active voices
_cmMidiVoice_t* vp = NULL;
cmMidiTrackMsg_t* sustainPedalDownMsg = NULL;
bool sustainFlagV[ kMidiChCnt ];
// clear the sustain pedal flag
@ -1229,6 +1230,10 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
for(vp = list; vp!=NULL; vp=vp->link)
vp->durTicks += mp->dtick;
// update the sustain pedal duration
if( sustainPedalDownMsg != NULL )
((cmMidiChMsg_t*)(sustainPedalDownMsg->u.chMsgPtr))->durTicks += mp->dtick; // cast away const
//
// If this is sustain pedal msg
//
@ -1243,10 +1248,25 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
// if the pedal went down ...
if( sustainFlagV[chIdx] )
{
if( sustainPedalDownMsg != NULL )
{
// TODO: the correct way to handle this is to maintain multiple sustain pedals
cmErrMsg(&p->err,kSustainPedalMfRC,"Sustain pedal down with no intervening sustain pedal up.");
}
else
{
sustainPedalDownMsg = mp;
((cmMidiChMsg_t*)(sustainPedalDownMsg->u.chMsgPtr))->durTicks = 0; // cast away const
}
_cmMidiFileCalcNoteDurationsAllocVoice( &list, mp, true );
}
else // ... if the pedal went up
{
sustainPedalDownMsg = NULL;
// ... then release sustaining notes
_cmMidiVoice_t* pp = NULL;
for(vp=list; vp != NULL; )