Adjust frame number for Clip position and start (which can result in a different number)
| 1617 | |
| 1618 | // Adjust frame number for Clip position and start (which can result in a different number) |
| 1619 | int64_t Clip::adjust_timeline_framenumber(int64_t clip_frame_number) { |
| 1620 | |
| 1621 | // Get clip position from parent clip (if any) |
| 1622 | float position = 0.0; |
| 1623 | float start = 0.0; |
| 1624 | Clip *parent = static_cast<Clip *>(ParentClip()); |
| 1625 | if (parent) { |
| 1626 | position = parent->Position(); |
| 1627 | start = parent->Start(); |
| 1628 | } |
| 1629 | |
| 1630 | // Adjust start frame and position based on parent clip. |
| 1631 | // This ensures the same frame # is used by mapped readers and clips, |
| 1632 | // when calculating samples per frame. |
| 1633 | // Thus, this prevents gaps and mismatches in # of samples. |
| 1634 | int64_t clip_start_frame = (start * info.fps.ToDouble()) + 1; |
| 1635 | int64_t clip_start_position = round(position * info.fps.ToDouble()) + 1; |
| 1636 | int64_t frame_number = clip_frame_number + clip_start_position - clip_start_frame; |
| 1637 | |
| 1638 | return frame_number; |
| 1639 | } |