cmMidiFile.h/c Added cmMIdiFileTickToSamples()

This commit is contained in:
kevin 2012-11-17 17:32:21 -08:00
parent bf8fceead1
commit 37c2599982
2 changed files with 165 additions and 137 deletions

View File

@ -796,6 +796,30 @@ void cmMidiFileTickToMicros( cmMidiFileH_t h )
} }
void cmMidiFileTickToSamples( cmMidiFileH_t h, double srate, bool absFl )
{
_cmMidiFile_t* p;
unsigned mi;
//bool fl = true;
if((p = _cmMidiFileHandleToPtr(h)) == NULL )
return;
cmMidiFileTickToMicros(h);
unsigned absSmp = 0;
for(mi=0; mi<p->msgN; ++mi)
{
cmMidiTrackMsg_t* mp = p->msgV[mi];
unsigned delta = floor((mp->dtick*srate)/1000000.0);
mp->dtick = absFl ? absSmp : delta;
absSmp += delta;
}
}
typedef struct _cmMidiVoice_str typedef struct _cmMidiVoice_str
{ {
const cmMidiTrackMsg_t* mp; const cmMidiTrackMsg_t* mp;

View File

@ -152,6 +152,10 @@ double cmMidiFileDurSecs( cmMidiFileH_t h );
// Convert the track message 'dtick' field to delta-microseconds. // Convert the track message 'dtick' field to delta-microseconds.
void cmMidiFileTickToMicros( cmMidiFileH_t h ); void cmMidiFileTickToMicros( cmMidiFileH_t h );
// Convert the track message 'dtick' field to samples.
// If the absFl is set then the delta times are converted to absolute time.
void cmMidiFileTickToSamples( cmMidiFileH_t h, double srate, bool absFl );
// Calculate Note Duration // Calculate Note Duration
void cmMidiFileCalcNoteDurations( cmMidiFileH_t h ); void cmMidiFileCalcNoteDurations( cmMidiFileH_t h );