cmTimeLine.c/h Removed unused fields from cmTlObj_t and added cmTimeLineIdToObjPtr()

This commit is contained in:
kpl 2012-11-14 20:08:18 -08:00
parent 9d4c82ae37
commit f025c621ce
2 changed files with 60 additions and 19 deletions

View File

@ -655,7 +655,6 @@ cmTlRC_t _cmTlProcMidiFile( _cmTl_t* p, _cmTlObj_t* op, cmMidiFileH_t mfH )
fl = mp->dtick == 0;
}
accum += dtick * p->srate / 1000000;
//int begSmpIdx = floor(accum_micros * p->srate / 1000000);
@ -958,6 +957,35 @@ double cmTimeLineSampleRate( cmTlH_t h )
return p->srate;
}
cmTlObj_t* _cmTimeLineIdToObj( _cmTl_t* p, unsigned seqId, unsigned id )
{
assert( seqId < p->seqCnt );
_cmTlObj_t* op = p->seq[seqId].first;
for(; op != NULL; op=op->next )
if( op->obj->uid == id )
return op->obj;
return NULL;
}
cmTlObj_t* cmTimeLineIdToObj( cmTlH_t h, unsigned seqId, unsigned id )
{
_cmTl_t* p = _cmTlHandleToPtr(h);
cmTlObj_t* op = NULL;
if( seqId != cmInvalidId )
op = _cmTimeLineIdToObj(p,seqId,id);
else
{
for(seqId=0; seqId<p->seqCnt; ++seqId)
if((op = _cmTimeLineIdToObj(p,seqId,id) ) != NULL )
break;
}
return op;
}
cmTlObj_t* cmTimeLineNextObj( cmTlH_t h, cmTlObj_t* tp, unsigned seqId )
{
_cmTl_t* p = _cmTlHandleToPtr(h);
@ -1036,6 +1064,22 @@ cmTlMarker_t* cmTlNextMarkerObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seq
return cmTimeLineMarkerObjPtr(h,op);
}
cmTlObj_t* cmTlIdToObjPtr( cmTlH_t h, unsigned uid )
{
_cmTl_t* p = _cmTlHandleToPtr(h);
unsigned i;
for(i=0; i<p->seqCnt; ++i)
//if( p->seq[i].first->obj->uid <= uid && uid <= p->seq[i].last->obj->uid )
{
_cmTlObj_t* op = p->seq[i].first;
for(; op != NULL; op=op->next )
if( op->obj->uid == uid )
return op->obj;
}
return NULL;
}
cmTlMidiFile_t* cmTimeLineMidiFileObjPtr( cmTlH_t h, cmTlObj_t* op )
{
@ -1474,16 +1518,16 @@ cmTlRC_t _cmTimeLineDecodeObj( const void* msg, unsigned msgByteCnt, cmTlUiMsg_
r->msgId = kInsertMsgTlId;
r->objId = tp->uid;
r->parentObjId = *parentIdPtr;
//r->parentObjId = *parentIdPtr;
r->seqId = tp->seqId;
r->typeId = tp->typeId;
r->begSmpIdx = tp->begSmpIdx;
r->durSmpCnt = tp->durSmpCnt;
r->label = strlen(text)==0 ? NULL : text;
//r->typeId = tp->typeId;
//r->begSmpIdx = tp->begSmpIdx;
//r->durSmpCnt = tp->durSmpCnt;
//r->label = strlen(text)==0 ? NULL : text;
r->srate = 0;
r->midiTrkMsg = NULL;
r->textStr = NULL;
//r->midiTrkMsg = NULL;
//r->textStr = NULL;
/*
switch( tp->typeId )
{
case kMidiFileTlId:
@ -1515,7 +1559,7 @@ cmTlRC_t _cmTimeLineDecodeObj( const void* msg, unsigned msgByteCnt, cmTlUiMsg_
default:
{ assert(0); }
}
*/
return rc;
}

View File

@ -111,6 +111,10 @@ extern "C" {
bool cmTimeLineIsValid( cmTlH_t h );
double cmTimeLineSampleRate( cmTlH_t h );
// Given cmTlObj_t.uid return a pointer to the associated record.
// seqId is optional (dflt:cmInvalidId)
cmTlObj_t* cmTimeLineIdToObj( cmTlH_t h, unsigned seqId, unsigned uid );
// Return the object following 'p' assigned to 'seqId'.
// If 'p' is NULL then return the first object assigned to seqId.
// If 'seqId' is set to cmInvalidId then return the next object on any seq.
@ -126,6 +130,7 @@ extern "C" {
cmTlAudioEvt_t* cmTlNextAudioEvtObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
cmTlMarker_t* cmTlNextMarkerObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
cmTlObj_t* cmTlIdToObjPtr( cmTlH_t h, unsigned uid );
// Cast a genereic cmTlObj_t pointer to a specificy type.
cmTlMidiFile_t* cmTimeLineMidiFileObjPtr( cmTlH_t h, cmTlObj_t* op );
@ -195,17 +200,9 @@ extern "C" {
{
cmTlUiMsgTypeId_t msgId; // See cmTlUiMsgTypeId_t.
unsigned objId; // Set to cmTlObj_t.uid
unsigned parentObjId; // cmTlObj_t.uid of the object this object's begSmpIdx is set relative to.
unsigned seqId; //
cmTlObjTypeId_t typeId; //
int begSmpIdx; // Time relative to parent.
unsigned durSmpCnt; // Duration of the object.
const char* label; // Object label (points to memory inside the serialized msg.)
unsigned seqId; // Sequence id
double srate; // Only valid with kInitMsgTlId.
unsigned seqCnt; // Only valid with kInitMsgTlId.
const cmMidiTrackMsg_t* midiTrkMsg; // Only valid for typeId == kMidiEvtTlId. Internal pointers refer to memory inside the serialzed msg. buffer.
unsigned midiFileObjId; // Only valid for typeId == kMidiEvtTlId
const char* textStr; // filename for kAudioFileTlId and kMidiFileTlId, marker text for kMarkerTlId
} cmTlUiMsg_t;
// Decode a serialized cmTlObj_t as passed to the cmTlCb_t listener