---------------------------------------------------------------------------
| 682 | |
| 683 | //--------------------------------------------------------------------------- |
| 684 | int TimeCode::FromSeconds(double Seconds, bool Truncate, bool TimeIsDropFrame) |
| 685 | { |
| 686 | // Sign |
| 687 | auto IsSigned = Seconds < 0; |
| 688 | SetNegative(IsSigned); |
| 689 | if (IsSigned) |
| 690 | Seconds = -Seconds; |
| 691 | |
| 692 | // Seconds to frames |
| 693 | double FrameCountF = Seconds * ((int64_t)GetFramesMax() + 1) / ((!TimeIsDropFrame && Is1001fps()) ? 1.001 : 1) + (Truncate ? 0.0 : 0.5); |
| 694 | if (FrameCountF > (double)numeric_limits<int64_t>::max() || FrameCountF < (double)numeric_limits<int64_t>::min()) |
| 695 | { |
| 696 | *this = TimeCode(); |
| 697 | return 1; |
| 698 | } |
| 699 | int64_t FrameCountI = (int64_t)FrameCountF; |
| 700 | |
| 701 | // Manage rounding errors, that makes FromSeconds(ToSeconds()) neutral (symetry) |
| 702 | if (FrameCountF / (FrameCountI + 1) > (double)0.999999999999999) |
| 703 | FrameCountI++; |
| 704 | |
| 705 | // Compute time code from frames, managing the need to consider time with also drop frames |
| 706 | if (TimeIsDropFrame && IsDropFrame()) |
| 707 | SetDropFrame(false); |
| 708 | auto Result = FromFrames(FrameCountI); |
| 709 | if (TimeIsDropFrame && IsDropFrame()) |
| 710 | SetDropFrame(); |
| 711 | |
| 712 | return Result; |
| 713 | } |
| 714 | |
| 715 | //--------------------------------------------------------------------------- |
| 716 | TimeCode TimeCode::ToRescaled(uint32_t FramesMax, flags Flags, rounding Rounding) const |