| 161 | } |
| 162 | |
| 163 | static |
| 164 | OfxStatus |
| 165 | getKeyIndex(const KnobIPtr& knob, |
| 166 | OfxTime time, |
| 167 | int direction, |
| 168 | int & index, |
| 169 | int startDim = -1, |
| 170 | int endDim = -1) |
| 171 | { |
| 172 | OfxKeyFramesSet keyframes; |
| 173 | |
| 174 | getOfxKeyFrames(knob.get(), keyframes, startDim, endDim); |
| 175 | int i = 0; |
| 176 | if (direction == 0) { |
| 177 | //search for key at indicated time |
| 178 | for (OfxKeyFramesSet::iterator it = keyframes.begin(); it != keyframes.end(); ++it, ++i) { |
| 179 | if (std::abs(*it - time) < NATRON_CURVE_X_SPACING_EPSILON) { |
| 180 | index = i; |
| 181 | |
| 182 | return kOfxStatOK; |
| 183 | } |
| 184 | } |
| 185 | } else if (direction < 0) { |
| 186 | //search for key before indicated time |
| 187 | OfxKeyFramesSet::iterator next = keyframes.begin(); |
| 188 | if ( !keyframes.empty() ) { |
| 189 | ++next; |
| 190 | } |
| 191 | for (OfxKeyFramesSet::iterator it = keyframes.begin(); it != keyframes.end(); ++it, ++i) { |
| 192 | if (*it < time) { |
| 193 | if ( next != keyframes.end() ) { |
| 194 | if (*next > time) { |
| 195 | index = i; |
| 196 | |
| 197 | return kOfxStatOK; |
| 198 | } |
| 199 | } else { |
| 200 | index = i; |
| 201 | assert(i == (int)keyframes.size() - 1); |
| 202 | |
| 203 | return kOfxStatOK; |
| 204 | } |
| 205 | } else { |
| 206 | return kOfxStatFailed; |
| 207 | } |
| 208 | if ( !keyframes.empty() ) { |
| 209 | ++next; |
| 210 | } |
| 211 | } |
| 212 | } else if (direction > 0) { |
| 213 | ///Find the first keyframe that is considered to be after the given time |
| 214 | for (OfxKeyFramesSet::iterator it = keyframes.begin(); it != keyframes.end(); ++it, ++i) { |
| 215 | if (*it > time) { |
| 216 | index = i; |
| 217 | |
| 218 | return kOfxStatOK; |
| 219 | } |
| 220 | } |
no test coverage detected