cmTimeLine.h/c Added cmTimeLineSeqToLocalSampleIndex()
This commit is contained in:
parent
0e06db1593
commit
bf8fceead1
@ -635,9 +635,9 @@ cmTlRC_t _cmTlProcMidiFile( _cmTl_t* p, _cmTlObj_t* op, cmMidiFileH_t mfH )
|
|||||||
unsigned mn = cmMidiFileMsgCount(mfH);
|
unsigned mn = cmMidiFileMsgCount(mfH);
|
||||||
const cmMidiTrackMsg_t** mapp = cmMidiFileMsgArray(mfH);
|
const cmMidiTrackMsg_t** mapp = cmMidiFileMsgArray(mfH);
|
||||||
unsigned mi = 0;
|
unsigned mi = 0;
|
||||||
double accum = 0;
|
//double accum = 0;
|
||||||
_cmTlObj_t* refOp = op;
|
_cmTlObj_t* refOp = op;
|
||||||
bool fl = false;
|
//bool fl = false;
|
||||||
unsigned dtick = 0;
|
unsigned dtick = 0;
|
||||||
mfp->noteOnCnt = 0;
|
mfp->noteOnCnt = 0;
|
||||||
|
|
||||||
@ -649,16 +649,16 @@ cmTlRC_t _cmTlProcMidiFile( _cmTl_t* p, _cmTlObj_t* op, cmMidiFileH_t mfH )
|
|||||||
|
|
||||||
dtick = mp->dtick;
|
dtick = mp->dtick;
|
||||||
|
|
||||||
if( fl )
|
//if( fl )
|
||||||
{
|
//{
|
||||||
dtick = 0;
|
// dtick = 0;
|
||||||
fl = mp->dtick == 0;
|
// fl = mp->dtick == 0;
|
||||||
}
|
//}
|
||||||
|
|
||||||
accum += dtick * p->srate / 1000000;
|
//accum += dtick * p->srate / 1000000;
|
||||||
|
|
||||||
//int begSmpIdx = floor(accum_micros * p->srate / 1000000);
|
//int begSmpIdx = floor(accum_micros * p->srate / 1000000);
|
||||||
int begSmpIdx = floor( dtick * p->srate / 1000000 );
|
int begSmpIdx = dtick; //floor( dtick * p->srate / 1000000.0 );
|
||||||
int durSmpCnt = 0;
|
int durSmpCnt = 0;
|
||||||
unsigned midiTrkMsgByteCnt = cmMidiFilePackTrackMsgBufByteCount( mp );
|
unsigned midiTrkMsgByteCnt = cmMidiFilePackTrackMsgBufByteCount( mp );
|
||||||
unsigned recdByteCnt = sizeof(cmTlMidiEvt_t) + midiTrkMsgByteCnt;
|
unsigned recdByteCnt = sizeof(cmTlMidiEvt_t) + midiTrkMsgByteCnt;
|
||||||
@ -669,7 +669,8 @@ cmTlRC_t _cmTlProcMidiFile( _cmTl_t* p, _cmTlObj_t* op, cmMidiFileH_t mfH )
|
|||||||
// count the note-on messages
|
// count the note-on messages
|
||||||
if( mp->status == kNoteOnMdId )
|
if( mp->status == kNoteOnMdId )
|
||||||
{
|
{
|
||||||
durSmpCnt = floor(mp->u.chMsgPtr->durTicks * p->srate / 1000000 );
|
//durSmpCnt = floor(mp->u.chMsgPtr->durTicks * p->srate / 1000000.0 );
|
||||||
|
durSmpCnt = mp->u.chMsgPtr->durTicks;
|
||||||
++mfp->noteOnCnt;
|
++mfp->noteOnCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,7 +728,7 @@ cmTlRC_t _cmTlAllocMidiFileRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmCh
|
|||||||
unsigned durSmpCnt = floor(cmMidiFileDurSecs(mfH)*p->srate);
|
unsigned durSmpCnt = floor(cmMidiFileDurSecs(mfH)*p->srate);
|
||||||
|
|
||||||
// convert the midi file from ticks to microseconds
|
// convert the midi file from ticks to microseconds
|
||||||
cmMidiFileTickToMicros(mfH);
|
cmMidiFileTickToSamples(mfH,p->srate,false);
|
||||||
|
|
||||||
// assign note durations to all note-on msg's
|
// assign note durations to all note-on msg's
|
||||||
cmMidiFileCalcNoteDurations(mfH);
|
cmMidiFileCalcNoteDurations(mfH);
|
||||||
@ -957,6 +958,11 @@ double cmTimeLineSampleRate( cmTlH_t h )
|
|||||||
return p->srate;
|
return p->srate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cmTimeLineSeqToLocalSampleIndex( int seqSmpIdx, cmTlObj_t* localObjPtr )
|
||||||
|
{
|
||||||
|
return seqSmpIdx - localObjPtr->seqSmpIdx;
|
||||||
|
}
|
||||||
|
|
||||||
cmTlObj_t* _cmTimeLineIdToObj( _cmTl_t* p, unsigned seqId, unsigned id )
|
cmTlObj_t* _cmTimeLineIdToObj( _cmTl_t* p, unsigned seqId, unsigned id )
|
||||||
{
|
{
|
||||||
assert( seqId < p->seqCnt );
|
assert( seqId < p->seqCnt );
|
||||||
|
@ -111,6 +111,9 @@ extern "C" {
|
|||||||
bool cmTimeLineIsValid( cmTlH_t h );
|
bool cmTimeLineIsValid( cmTlH_t h );
|
||||||
double cmTimeLineSampleRate( cmTlH_t h );
|
double cmTimeLineSampleRate( cmTlH_t h );
|
||||||
|
|
||||||
|
// Convert global (sequence) time to a time relative to an object.
|
||||||
|
int cmTimeLineSeqToLocalSampleIndex( int seqSmpIdx, cmTlObj_t* localObjPtr );
|
||||||
|
|
||||||
// Given cmTlObj_t.uid return a pointer to the associated record.
|
// Given cmTlObj_t.uid return a pointer to the associated record.
|
||||||
// seqId is optional (dflt:cmInvalidId)
|
// seqId is optional (dflt:cmInvalidId)
|
||||||
cmTlObj_t* cmTimeLineIdToObj( cmTlH_t h, unsigned seqId, unsigned uid );
|
cmTlObj_t* cmTimeLineIdToObj( cmTlH_t h, unsigned seqId, unsigned uid );
|
||||||
|
Loading…
Reference in New Issue
Block a user