cmTimeLine.h/c Added the xxxAtTime() functions

This commit is contained in:
kevin 2012-11-16 11:56:40 -08:00
parent c80368a549
commit 6ab0660552
2 changed files with 88 additions and 1 deletions

View File

@ -1193,6 +1193,87 @@ cmTlMidiFile_t* cmTimeLineFindMidiFile( cmTlH_t h, const cmChar_t* fn )
return NULL; return NULL;
} }
_cmTlObj_t* _cmTimeLineObjAtTime( _cmTl_t* p, unsigned seqId, unsigned seqSmpIdx, unsigned typeId )
{
assert( seqId < p->seqCnt );
_cmTlObj_t* op = p->seq[seqId].first;
_cmTlObj_t* min_op = NULL;
unsigned minDist = UINT_MAX;
for(; op!=NULL; op=op->next)
if( typeId==cmInvalidId || op->obj->typeId == typeId )
{
// if seqSmpIdx is inside this object - then return it as the solution
if((op->obj->seqSmpIdx <= seqSmpIdx && seqSmpIdx < (op->obj->seqSmpIdx + op->obj->durSmpCnt)))
return op;
// measure the distance from seqSmpIdx to the begin and end of this object
unsigned d0 = op->obj->seqSmpIdx < seqSmpIdx ? seqSmpIdx - op->obj->seqSmpIdx : op->obj->seqSmpIdx - seqSmpIdx;
unsigned d1 = op->obj->seqSmpIdx+op->obj->durSmpCnt < seqSmpIdx ? seqSmpIdx - op->obj->seqSmpIdx+op->obj->durSmpCnt : op->obj->seqSmpIdx+op->obj->durSmpCnt - seqSmpIdx;
// d0 and d1 should decrease as the cur object approaches seqSmpIdx
// If they do not then the search is over - return the closest point.
if( d0>minDist && d1>minDist)
break;
// track the min dist and the assoc'd obj
if( d0 < minDist )
{
minDist = d0;
min_op = op;
}
if( d1 < minDist )
{
minDist = d1;
min_op = op;
}
}
return min_op;
}
cmTlAudioFile_t* cmTimeLineAudioFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx )
{
_cmTl_t* p = _cmTlHandleToPtr(h);
_cmTlObj_t* op;
if((op = _cmTimeLineObjAtTime(p,seqId,seqSmpIdx,kAudioFileTlId)) == NULL )
return NULL;
return _cmTlAudioFileObjPtr(p,op->obj,false);
}
cmTlMidiFile_t* cmTimeLineMidiFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx )
{
_cmTl_t* p = _cmTlHandleToPtr(h);
_cmTlObj_t* op;
if((op = _cmTimeLineObjAtTime(p,seqId,seqSmpIdx,kMidiFileTlId)) == NULL )
return NULL;
return _cmTlMidiFileObjPtr(p,op->obj,false);
}
cmTlMidiEvt_t* cmTimeLineMidiEvtAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx )
{
_cmTl_t* p = _cmTlHandleToPtr(h);
_cmTlObj_t* op;
if((op = _cmTimeLineObjAtTime(p,seqId,seqSmpIdx,kMidiEvtTlId)) == NULL )
return NULL;
return _cmTlMidiEvtObjPtr(p,op->obj,false);
}
cmTlMarker_t* cmTimeLineMarkerAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx )
{
_cmTl_t* p = _cmTlHandleToPtr(h);
_cmTlObj_t* op;
if((op = _cmTimeLineObjAtTime(p,seqId,seqSmpIdx,kMarkerTlId)) == NULL )
return NULL;
return _cmTlMarkerObjPtr(p,op->obj,false);
}
cmTlRC_t _cmTlParseErr( cmErr_t* err, const cmChar_t* errLabelPtr, unsigned idx, const cmChar_t* fn ) cmTlRC_t _cmTlParseErr( cmErr_t* err, const cmChar_t* errLabelPtr, unsigned idx, const cmChar_t* fn )
{ {

View File

@ -149,7 +149,13 @@ extern "C" {
cmTlMarker_t* cmTlMarkerObjPtr( cmTlH_t h, cmTlObj_t* op ); cmTlMarker_t* cmTlMarkerObjPtr( cmTlH_t h, cmTlObj_t* op );
cmTlAudioFile_t* cmTimeLineFindAudioFile( cmTlH_t h, const cmChar_t* fn ); cmTlAudioFile_t* cmTimeLineFindAudioFile( cmTlH_t h, const cmChar_t* fn );
cmTlMidiFile_t* cmTimeLineFindMidiFile( cmTlH_t h, const cmChar_t* fn ); cmTlMidiFile_t* cmTimeLineFindMidiFile( cmTlH_t h, const cmChar_t* fn );
cmTlAudioFile_t* cmTimeLineAudioFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
cmTlMidiFile_t* cmTimeLineMidiFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
cmTlMidiEvt_t* cmTimeLineMidiEvtAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
cmTlMarker_t* cmTimeLineMarkerAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
// 'typeId' = kAudioFileTlId, kMidiFileTId, kMarkerTlId. // 'typeId' = kAudioFileTlId, kMidiFileTId, kMarkerTlId.
// 'nameStr' and 'refObjNameStr' may be NULL. // 'nameStr' and 'refObjNameStr' may be NULL.