cmMidiFile.c/h Added __cplusplus guards. Convert Note-on 0 vel. to Note-Off
This commit is contained in:
parent
e5c233132f
commit
41a33a0333
16
cmMidiFile.c
16
cmMidiFile.c
@ -266,6 +266,10 @@ cmMfRC_t _cmMidiFileReadChannelMsg( _cmMidiFile_t* mfp, cmMidiByte_t* rsPtr, cmM
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert note-on velocity=0 to note off
|
||||||
|
if( tmp->status == kNoteOnMdId && p->d1==0 )
|
||||||
|
tmp->status = kNoteOffMdId;
|
||||||
|
|
||||||
tmp->u.chMsgPtr = p;
|
tmp->u.chMsgPtr = p;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -833,13 +837,23 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
|
|||||||
_cmMidiVoice_t* vp;
|
_cmMidiVoice_t* vp;
|
||||||
bool sustainFlagV[ kMidiChCnt ];
|
bool sustainFlagV[ kMidiChCnt ];
|
||||||
|
|
||||||
|
for(mi=0; mi<kMidiChCnt; ++mi)
|
||||||
|
sustainFlagV[mi]=false;
|
||||||
|
|
||||||
for(mi=0; mi<p->msgN; ++mi)
|
for(mi=0; mi<p->msgN; ++mi)
|
||||||
{
|
{
|
||||||
cmMidiTrackMsg_t* mp = p->msgV[mi];
|
cmMidiTrackMsg_t* mp = p->msgV[mi];
|
||||||
|
|
||||||
// update the duration of the sounding notes
|
// update the duration of the sounding notes
|
||||||
|
//int ii=0;
|
||||||
|
//printf("---- %i ------\n",mi);
|
||||||
for(vp = list; vp!=NULL; vp=vp->link)
|
for(vp = list; vp!=NULL; vp=vp->link)
|
||||||
|
{
|
||||||
vp->durTicks += mp->dtick;
|
vp->durTicks += mp->dtick;
|
||||||
|
//printf("%i %i %p %p\n",ii,vp->sustainFl,vp,vp->link);
|
||||||
|
//++ii;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// If this is sustain pedal msg
|
// If this is sustain pedal msg
|
||||||
@ -894,6 +908,8 @@ void cmMidiFileCalcNoteDurations( cmMidiFileH_t h )
|
|||||||
// if this active voice ch/pitch matches the note-off msg ch pitch
|
// if this active voice ch/pitch matches the note-off msg ch pitch
|
||||||
if( (vp->mp->u.chMsgPtr->d0==mp->u.chMsgPtr->d0) && (vp->mp->u.chMsgPtr->ch==mp->u.chMsgPtr->ch) )
|
if( (vp->mp->u.chMsgPtr->d0==mp->u.chMsgPtr->d0) && (vp->mp->u.chMsgPtr->ch==mp->u.chMsgPtr->ch) )
|
||||||
{
|
{
|
||||||
|
assert( mp->u.chMsgPtr->ch < kMidiChCnt );
|
||||||
|
|
||||||
if( sustainFlagV[mp->u.chMsgPtr->ch] )
|
if( sustainFlagV[mp->u.chMsgPtr->ch] )
|
||||||
vp->sustainFl = true;
|
vp->sustainFl = true;
|
||||||
else
|
else
|
||||||
|
12
cmMidiFile.h
12
cmMidiFile.h
@ -1,6 +1,10 @@
|
|||||||
#ifndef cmMidiFile_h
|
#ifndef cmMidiFile_h
|
||||||
#define cmMidiFile_h
|
#define cmMidiFile_h
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// MIDI file timing:
|
// MIDI file timing:
|
||||||
// Messages in the MIDI file are time tagged with a delta offset in 'ticks'
|
// Messages in the MIDI file are time tagged with a delta offset in 'ticks'
|
||||||
// from the previous message in the same track.
|
// from the previous message in the same track.
|
||||||
@ -15,6 +19,10 @@
|
|||||||
// MpQN is given as the value of the MIDI file tempo message.
|
// MpQN is given as the value of the MIDI file tempo message.
|
||||||
//
|
//
|
||||||
// See cmMidiFileSeekUSecs() for an example of converting ticks to milliseconds.
|
// See cmMidiFileSeekUSecs() for an example of converting ticks to milliseconds.
|
||||||
|
//
|
||||||
|
// As part of the file reading process, the status byte of note-on messages
|
||||||
|
// with velocity=0 are is changed to a note-off message. See _cmMidiFileReadChannelMsg().
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef cmHandle_t cmMidiFileH_t;
|
typedef cmHandle_t cmMidiFileH_t;
|
||||||
@ -160,4 +168,8 @@ void cmMidiFilePrint( cmMidiFileH_t h, unsigned trkIdx, cmRpt_t
|
|||||||
bool cmMidiFileIsNull( cmMidiFileH_t h );
|
bool cmMidiFileIsNull( cmMidiFileH_t h );
|
||||||
void cmMidiFileTest( const char* fn, cmCtx_t* ctx );
|
void cmMidiFileTest( const char* fn, cmCtx_t* ctx );
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user