Browse Source

cmTimeLine.c : _cmTimeLineObjAtTime() changed such that when an object contains

the search point that the returned object also contains the search point.
The returned object will be the one containing the search point whose begin or
end point is closest to the search point.
master
kevin 8 years ago
parent
commit
caffeb4b0a
1 changed files with 20 additions and 14 deletions
  1. 20
    14
      app/cmTimeLine.c

+ 20
- 14
app/cmTimeLine.c View File

@@ -134,7 +134,7 @@ cmTlMidiFile_t*  _cmTlMidiFileObjPtr(  _cmTl_t* p, cmTlObj_t* op, bool errFl )
134 134
   if( op==NULL || op->typeId != kMidiFileTlId )
135 135
   {
136 136
     if( errFl && p != NULL)
137
-      cmErrMsg(&p->err,kTypeCvtFailTlRC,"A time line object type promotion failed.");
137
+      cmErrMsg(&p->err,kTypeCvtFailTlRC,"A time line object type promotion to MIDI file failed.");
138 138
     return NULL;
139 139
   }
140 140
 
@@ -147,7 +147,7 @@ cmTlMidiEvt_t*   _cmTlMidiEvtObjPtr(   _cmTl_t* p, cmTlObj_t* op, bool errFl )
147 147
   if( op==NULL || op->typeId != kMidiEvtTlId )
148 148
   {
149 149
     if( errFl && p != NULL )
150
-      cmErrMsg(&p->err,kTypeCvtFailTlRC,"A time line object type promotion failed.");
150
+      cmErrMsg(&p->err,kTypeCvtFailTlRC,"A time line object type promotion to MIDI event failed.");
151 151
     return NULL;
152 152
   }
153 153
 
@@ -173,7 +173,7 @@ cmTlAudioEvt_t*  _cmTlAudioEvtObjPtr(  _cmTl_t* p, cmTlObj_t* op, bool errFl )
173 173
   if( op==NULL || op->typeId != kAudioEvtTlId )
174 174
   {
175 175
     if( errFl && p != NULL)
176
-      cmErrMsg(&p->err,kTypeCvtFailTlRC,"A time line object type promotion failed.");
176
+      cmErrMsg(&p->err,kTypeCvtFailTlRC,"A time line object type promotion to audio event failed.");
177 177
     return NULL;
178 178
   }
179 179
   return (cmTlAudioEvt_t*)op;
@@ -186,7 +186,7 @@ cmTlMarker_t*    _cmTlMarkerObjPtr(    _cmTl_t* p, cmTlObj_t* op, bool errFl )
186 186
   if( op==NULL || op->typeId != kMarkerTlId )
187 187
   {
188 188
     if( errFl && p != NULL)
189
-      cmErrMsg(&p->err,kTypeCvtFailTlRC,"A time line object type promotion failed.");
189
+      cmErrMsg(&p->err,kTypeCvtFailTlRC,"A time line object type promotion to marker object failed.");
190 190
     return NULL;
191 191
   }
192 192
   return (cmTlMarker_t*)op;
@@ -1227,31 +1227,37 @@ _cmTlObj_t* _cmTimeLineObjAtTime( _cmTl_t* p, unsigned seqId, unsigned seqSmpIdx
1227 1227
   _cmTlObj_t* op      = p->seq[seqId].first;
1228 1228
   _cmTlObj_t* min_op  = NULL;
1229 1229
   unsigned    minDist = UINT_MAX;
1230
-
1230
+  bool        inFl    = false;
1231
+  
1232
+  // for each object in the requested sequence
1231 1233
   for(; op!=NULL; op=op->next)
1232 1234
     if( typeId==cmInvalidId || op->obj->typeId == typeId )
1233 1235
     {
1234
-      // if seqSmpIdx is inside this object - then return it as the solution
1236
+      bool in0Fl = false;
1237
+      
1238
+      // if seqSmpIdx is inside this object - then the returned object must contain seqSmpIdx
1239
+      // (but the ideal point to return is the one which contains seqSmpIdx and also has
1240
+      //  a begin or end point very close to seqSmpIdx - so this defer selecting an object
1241
+      // until all objects which may contain seqSmpIdx have been examined 
1235 1242
       if((op->obj->seqSmpIdx <= seqSmpIdx && seqSmpIdx < (op->obj->seqSmpIdx + op->obj->durSmpCnt)))
1236
-        return op;
1237
-
1243
+      {
1244
+        inFl  = true;   // the returned object must contain seqSmpIdx
1245
+        in0Fl = true;   // this object contains seqSmpIdx
1246
+      }
1247
+      
1238 1248
       // measure the distance from seqSmpIdx to the begin and end of this object
1239 1249
       unsigned d0 =  op->obj->seqSmpIdx                    < seqSmpIdx ? seqSmpIdx - op->obj->seqSmpIdx                    : op->obj->seqSmpIdx - seqSmpIdx;
1240 1250
       unsigned d1 =  op->obj->seqSmpIdx+op->obj->durSmpCnt < seqSmpIdx ? seqSmpIdx - op->obj->seqSmpIdx+op->obj->durSmpCnt : op->obj->seqSmpIdx+op->obj->durSmpCnt - seqSmpIdx;
1241 1251
 
1242
-      // d0 and d1 should decrease as the cur object approaches seqSmpIdx
1243
-      // If they do not then the search is over - return the closest point.
1244
-      if( d0>minDist && d1>minDist)
1245
-        break;
1246 1252
 
1247 1253
       // track the min dist and the assoc'd obj
1248
-      if( d0 < minDist )
1254
+      if( d0 < minDist && (inFl==false || inFl==in0Fl))
1249 1255
       {
1250 1256
         minDist = d0;
1251 1257
         min_op  = op;
1252 1258
       }
1253 1259
 
1254
-      if( d1 < minDist )
1260
+      if( d1 < minDist && (inFl==false || inFl==in0Fl))
1255 1261
       {
1256 1262
         minDist = d1;
1257 1263
         min_op  = op;

Loading…
Cancel
Save