瀏覽代碼

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 年之前
父節點
當前提交
caffeb4b0a
共有 1 個文件被更改,包括 20 次插入14 次删除
  1. 20
    14
      app/cmTimeLine.c

+ 20
- 14
app/cmTimeLine.c 查看文件

134
   if( op==NULL || op->typeId != kMidiFileTlId )
134
   if( op==NULL || op->typeId != kMidiFileTlId )
135
   {
135
   {
136
     if( errFl && p != NULL)
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
     return NULL;
138
     return NULL;
139
   }
139
   }
140
 
140
 
147
   if( op==NULL || op->typeId != kMidiEvtTlId )
147
   if( op==NULL || op->typeId != kMidiEvtTlId )
148
   {
148
   {
149
     if( errFl && p != NULL )
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
     return NULL;
151
     return NULL;
152
   }
152
   }
153
 
153
 
173
   if( op==NULL || op->typeId != kAudioEvtTlId )
173
   if( op==NULL || op->typeId != kAudioEvtTlId )
174
   {
174
   {
175
     if( errFl && p != NULL)
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
     return NULL;
177
     return NULL;
178
   }
178
   }
179
   return (cmTlAudioEvt_t*)op;
179
   return (cmTlAudioEvt_t*)op;
186
   if( op==NULL || op->typeId != kMarkerTlId )
186
   if( op==NULL || op->typeId != kMarkerTlId )
187
   {
187
   {
188
     if( errFl && p != NULL)
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
     return NULL;
190
     return NULL;
191
   }
191
   }
192
   return (cmTlMarker_t*)op;
192
   return (cmTlMarker_t*)op;
1227
   _cmTlObj_t* op      = p->seq[seqId].first;
1227
   _cmTlObj_t* op      = p->seq[seqId].first;
1228
   _cmTlObj_t* min_op  = NULL;
1228
   _cmTlObj_t* min_op  = NULL;
1229
   unsigned    minDist = UINT_MAX;
1229
   unsigned    minDist = UINT_MAX;
1230
-
1230
+  bool        inFl    = false;
1231
+  
1232
+  // for each object in the requested sequence
1231
   for(; op!=NULL; op=op->next)
1233
   for(; op!=NULL; op=op->next)
1232
     if( typeId==cmInvalidId || op->obj->typeId == typeId )
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
       if((op->obj->seqSmpIdx <= seqSmpIdx && seqSmpIdx < (op->obj->seqSmpIdx + op->obj->durSmpCnt)))
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
       // measure the distance from seqSmpIdx to the begin and end of this object
1248
       // measure the distance from seqSmpIdx to the begin and end of this object
1239
       unsigned d0 =  op->obj->seqSmpIdx                    < seqSmpIdx ? seqSmpIdx - op->obj->seqSmpIdx                    : op->obj->seqSmpIdx - seqSmpIdx;
1249
       unsigned d0 =  op->obj->seqSmpIdx                    < seqSmpIdx ? seqSmpIdx - op->obj->seqSmpIdx                    : op->obj->seqSmpIdx - seqSmpIdx;
1240
       unsigned d1 =  op->obj->seqSmpIdx+op->obj->durSmpCnt < seqSmpIdx ? seqSmpIdx - op->obj->seqSmpIdx+op->obj->durSmpCnt : op->obj->seqSmpIdx+op->obj->durSmpCnt - seqSmpIdx;
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
       // track the min dist and the assoc'd obj
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
         minDist = d0;
1256
         minDist = d0;
1251
         min_op  = op;
1257
         min_op  = op;
1252
       }
1258
       }
1253
 
1259
 
1254
-      if( d1 < minDist )
1260
+      if( d1 < minDist && (inFl==false || inFl==in0Fl))
1255
       {
1261
       {
1256
         minDist = d1;
1262
         minDist = d1;
1257
         min_op  = op;
1263
         min_op  = op;

Loading…
取消
儲存