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:
parent
1a0b88016e
commit
ec6c2d8593
20
cmMidiFile.c
20
cmMidiFile.c
@ -1215,6 +1215,7 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
|
|||||||
unsigned mi = cmInvalidId;
|
unsigned mi = cmInvalidId;
|
||||||
_cmMidiVoice_t* list = NULL; // list of active voices
|
_cmMidiVoice_t* list = NULL; // list of active voices
|
||||||
_cmMidiVoice_t* vp = NULL;
|
_cmMidiVoice_t* vp = NULL;
|
||||||
|
cmMidiTrackMsg_t* sustainPedalDownMsg = NULL;
|
||||||
bool sustainFlagV[ kMidiChCnt ];
|
bool sustainFlagV[ kMidiChCnt ];
|
||||||
|
|
||||||
// clear the sustain pedal flag
|
// clear the sustain pedal flag
|
||||||
@ -1229,6 +1230,10 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
|
|||||||
for(vp = list; vp!=NULL; vp=vp->link)
|
for(vp = list; vp!=NULL; vp=vp->link)
|
||||||
vp->durTicks += mp->dtick;
|
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
|
// If this is sustain pedal msg
|
||||||
//
|
//
|
||||||
@ -1243,10 +1248,25 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
|
|||||||
// if the pedal went down ...
|
// if the pedal went down ...
|
||||||
if( sustainFlagV[chIdx] )
|
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 );
|
_cmMidiFileCalcNoteDurationsAllocVoice( &list, mp, true );
|
||||||
}
|
}
|
||||||
else // ... if the pedal went up
|
else // ... if the pedal went up
|
||||||
{
|
{
|
||||||
|
|
||||||
|
sustainPedalDownMsg = NULL;
|
||||||
|
|
||||||
// ... then release sustaining notes
|
// ... then release sustaining notes
|
||||||
_cmMidiVoice_t* pp = NULL;
|
_cmMidiVoice_t* pp = NULL;
|
||||||
for(vp=list; vp != NULL; )
|
for(vp=list; vp != NULL; )
|
||||||
|
Loading…
Reference in New Issue
Block a user