diff --git a/src/lib/time.h b/src/lib/time.h deleted file mode 100644 index abb9d3a74..000000000 --- a/src/lib/time.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - time.h - Utilities for handling time - - Copyright (C) - 2008, Christian Thaeter - 2010, Stefan Kangas - -  **Lumiera** is free software; you can redistribute it and/or modify it -  under the terms of the GNU General Public License as published by the -  Free Software Foundation; either version 2 of the License, or (at your -  option) any later version. See the file COPYING for further details. -*/ - -/** @file time.h - ** Common functions for handling of time values. - ** Working with time values in sexagesimal format, quantising time and converting - ** to/from common timecode formats can be tricky to get right. Thus the goal is - ** to concentrate the actual bits of math for these operations into a small number - ** of library functions, which are easy to test thoroughly in isolation. - ** - ** Built on top of that, the actual time handling in the GUI and within the Lumiera - ** session is mostly confined to use the opaque lib::time::Time wrapper objects. - ** When time values actually need to be _quantised_ (aligned to a frame grid), - ** this is expressed at the API through using the lib::time::QuTime type, which - ** then in turn can be materialised into a number of _timecode formats_. - ** These definitions ensure that whenever an actual quantisation (rounding) - ** operation is performed, the link to the appropriate time grid is available, - ** so that multiple output or rendering operations can use differing time origins - ** and frame rates simultaneously on the same model. - ** - ** The Lumiera Vault Layer functions mostly operate on raw frame counts, which in - ** this model are defined to be a special kind of timecode, and thus dependent on - ** a preceding time quantisation. - ** - ** @deprecated 2025 this should not be a "simple" C library set aside from the Lumiera - ** time handling framework, rather it should be clarified that these are - ** implementation helpers and must not be used by any application code. - ** It should be checked which of these functions actually need to be - ** exposed through an interface header, since these are typically - ** used to implement parts of the time handling framework. - ** - ** @see lib::time::Time - ** @see timequant.hpp - ** @see TimeValue_test - ** - */ - - -#ifndef LUMIERA_TIME_H -#define LUMIERA_TIME_H - -#include - -#ifdef __cplusplus /*=================== C++ facilities ===================== */ -#include "lib/time/timevalue.hpp" - -using lib::time::raw_time_64; - - -/** - * Converts a fraction of seconds to Lumiera's internal opaque time scale. - * @param fractionalSeconds given as rational number - * @note inconsistent with Lumiera's general quantisation behaviour, - * here negative fractional micro-ticks are truncated towards zero. - * This was deemed irrelevant in practice. - */ -raw_time_64 -lumiera_rational_to_time (lib::time::FSecs const& fractionalSeconds); - - -/** - * Converts a frame count into Lumiera's internal time scale. - * based on a framerate given as rational number (e.g. NTSC) - * @note handles only positive frame counts and assumes the - * origin to be at zero. - */ -raw_time_64 -lumiera_framecount_to_time (uint64_t frameCount, lib::time::FrameRate const& fps); - - - - - -extern "C" { /* ===================== C interface ======================== */ -#endif - - -/** - * Build a time value by summing up the given components. - * @param millis number of milliseconds - * @param secs number of seconds - * @param mins number of minutes - * @param hours number of hours - */ -raw_time_64 -lumiera_build_time (long millis, uint secs, uint mins, uint hours); - - - - -#ifdef __cplusplus -}//extern "C" -#endif -#endif - diff --git a/src/lib/time/time.cpp b/src/lib/time/time.cpp index 320b25e21..0475bfbe7 100644 --- a/src/lib/time/time.cpp +++ b/src/lib/time/time.cpp @@ -21,9 +21,8 @@ ** for the derived time entities (TimeVar, Offset, Duration, TimeSpan, FrameRate) ** and for the basic time and frame rate conversion functions. ** - ** Client code includes either time.h (for basics and conversion functions) - ** or timevalue.hpp (for the time entities), timequant.hpp for grid aligned - ** time values or timecode.hpp + ** Client code includes either timevalue.hpp (for the time entities), + ** or timequant.hpp for grid aligned time values, or timecode.hpp. ** ** @see Time ** @see TimeValue @@ -35,14 +34,12 @@ #include "lib/error.hpp" -#include "lib/time.h" -#include "lib/time/timevalue.hpp" #include "lib/rational.hpp" -#include "lib/util-quant.hpp" +#include "lib/time/timevalue.hpp" #include "lib/format-string.hpp" +#include "lib/util-quant.hpp" #include "lib/util.hpp" -#include #include #include #include @@ -61,20 +58,18 @@ using boost::lexical_cast; #undef MIN -namespace error = lumiera::error; - - namespace lib { namespace meta { extern const std::string FAILURE_INDICATOR; } namespace time { + namespace error = lumiera::error; const raw_time_64 TimeValue::SCALE = 1'000'000; - /** @note the allowed time range is explicitly limited to help overflow protection */ + /** @note the allowed time range is explicitly limited to allow for overflow protection */ const Time Time::MAX ( TimeValue::buildRaw_(+std::numeric_limits::max() / 30) ); const Time Time::MIN ( TimeValue::buildRaw_(-_raw(Time::MAX) ) ); const Time Time::ZERO; @@ -84,16 +79,57 @@ namespace time { const Offset Offset::ZERO (Time::ZERO); + + + namespace { // local definitions for the implementation.... + + /** scale factor _used locally within this implementation header_. + * TimeValue::SCALE (µ-ticks, i.e. 1e6) is the correct factor or dividend when using + * raw_time_64 for display on a scale with seconds. Since we want to use milliseconds, + * we need a factor of 1000 to get correct results. */ + const raw_time_64 TIME_SCALE_MS (lib::time::TimeValue::SCALE / 1000); + + const FSecs FSEC_MAX{std::numeric_limits::max() / lib::time::TimeValue::SCALE}; Literal DIAGNOSTIC_FORMAT{"%s%01d:%02d:%02d.%03d"}; - -/** scale factor _used locally within this implementation header_. - * TimeValue::SCALE (µ-ticks, i.e. 1e6) is the correct factor or dividend when using - * raw_time_64 for display on a scale with seconds. Since we want to use milliseconds, - * we need to multiply or divide by 1000 to get correct results. */ -#define TIME_SCALE_MS (lib::time::TimeValue::SCALE / 1000) + + /** + * Converts a fraction of seconds to Lumiera's internal opaque time scale. + * @param fractionalSeconds given as rational number + * @note inconsistent with Lumiera's general quantisation behaviour, + * here negative fractional micro-ticks are truncated towards zero. + * This was deemed irrelevant in practice. + * @todo 2022 this utility function could be factored out into a `FSecs` or `RSec` class /////////////////TICKET #1262 + */ + raw_time_64 + build_time_from (FSecs const& fractionalSeconds) + { + // avoid numeric wrap from values not representable as 64bit µ-ticks + if (abs(fractionalSeconds) > lib::time::FSEC_MAX) + return (fractionalSeconds < 0? -1:+1) + * std::numeric_limits::max(); + + return raw_time_64(util::reQuant (fractionalSeconds.numerator() + ,fractionalSeconds.denominator() + ,lib::time::TimeValue::SCALE + )); + } + + + raw_time_64 + build_time_from (long millis, uint secs, uint mins, uint hours) + { + raw_time_64 time = millis + + 1000 * secs + + 1000 * 60 * mins + + 1000 * 60 * 60 * hours; + time *= TIME_SCALE_MS; + return time; + } + }//(End)local definitions + /** convenience constructor to build an @@ -111,7 +147,7 @@ namespace time { , uint mins , uint hours ) - : TimeValue(lumiera_build_time (millis,secs,mins,hours)) + : TimeValue(build_time_from (millis,secs,mins,hours)) { } @@ -120,11 +156,11 @@ namespace time { * An example would be to the time unit of a framerate. */ Time::Time (FSecs const& fractionalSeconds) - : TimeValue(lumiera_rational_to_time (fractionalSeconds)) + : TimeValue(build_time_from (fractionalSeconds)) { } Offset::Offset (FSecs const& delta_in_secs) - : TimeValue{buildRaw_(symmetricLimit (lumiera_rational_to_time (delta_in_secs) + : TimeValue{buildRaw_(symmetricLimit (build_time_from (delta_in_secs) ,Duration::MAX))} { } @@ -338,10 +374,21 @@ namespace time { } + namespace { + raw_time_64 + framecount_to_time (uint64_t frameCount, FrameRate const& fps) + { + // convert to 64bit + boost::rational framerate (fps.numerator(), fps.denominator()); + + return rational_cast (lib::time::TimeValue::SCALE * frameCount / framerate); + } + } + /** offset by the given number of frames. */ Offset::Offset (FrameCnt count, FrameRate const& fps) : TimeValue{buildRaw_( - count? (count<0? -1:+1) * lumiera_framecount_to_time (::abs(count), fps) + count? (count<0? -1:+1) * framecount_to_time (::abs(count), fps) :_raw(Duration::NIL))} { } @@ -361,6 +408,8 @@ namespace time { }} // namespace lib::Time + + namespace util { string StringConv::invoke (lib::time::FSecs val) noexcept @@ -369,100 +418,3 @@ namespace util { } } // namespace util - - - - - - -/* ===== implementation of the C API functions ===== */ - - -/// @todo this utility function could be factored out into a `FSecs` or `RSec` class ///////////////////////TICKET #1262 -raw_time_64 -lumiera_rational_to_time (FSecs const& fractionalSeconds) -{ - // avoid numeric wrap from values not representable as 64bit µ-ticks - if (abs(fractionalSeconds) > lib::time::FSEC_MAX) - return (fractionalSeconds < 0? -1:+1) - * std::numeric_limits::max(); - - return raw_time_64(util::reQuant (fractionalSeconds.numerator() - ,fractionalSeconds.denominator() - ,lib::time::TimeValue::SCALE - )); -} - -raw_time_64 -lumiera_framecount_to_time (uint64_t frameCount, FrameRate const& fps) -{ - // convert to 64bit - boost::rational framerate (fps.numerator(), fps.denominator()); - - return rational_cast (lib::time::TimeValue::SCALE * frameCount / framerate); -} - - - - - -raw_time_64 -lumiera_build_time(long millis, uint secs, uint mins, uint hours) -{ - raw_time_64 time = millis - + 1000 * secs - + 1000 * 60 * mins - + 1000 * 60 * 60 * hours; - time *= TIME_SCALE_MS; - return time; -} - -raw_time_64 -lumiera_build_time_fps (uint fps, uint frames, uint secs, uint mins, uint hours) -{ - raw_time_64 time = 1000LL * frames/fps - + 1000 * secs - + 1000 * 60 * mins - + 1000 * 60 * 60 * hours; - time *= TIME_SCALE_MS; - return time; -} - -int -lumiera_time_hours (raw_time_64 time) -{ - return time / TIME_SCALE_MS / 1000 / 60 / 60; -} - -int -lumiera_time_minutes (raw_time_64 time) -{ - return (time / TIME_SCALE_MS / 1000 / 60) % 60; -} - -int -lumiera_time_seconds (raw_time_64 time) -{ - return (time / TIME_SCALE_MS / 1000) % 60; -} - -int -lumiera_time_millis (raw_time_64 time) -{ - return (time / TIME_SCALE_MS) % 1000; -} - -int -lumiera_time_frames (raw_time_64 time, uint fps) -{ - REQUIRE (fps < uint(std::numeric_limits::max())); - return floordiv (lumiera_time_millis(time) * int(fps), TIME_SCALE_MS); -} - - - -namespace lib { -namespace time { ////////////////////////////////////////////////////////////////////////////////////////////TICKET #1259 : move all calculation functions into a C++ namespace - - -}} // lib::time diff --git a/src/lib/time/timecode.cpp b/src/lib/time/timecode.cpp index cc12e24ea..1ed1a6b4d 100644 --- a/src/lib/time/timecode.cpp +++ b/src/lib/time/timecode.cpp @@ -23,7 +23,6 @@ #include "lib/time/timevalue.hpp" #include "lib/time/timequant.hpp" #include "lib/time/formats.hpp" -#include "lib/time.h" #include "lib/util.hpp" #include "lib/util-quant.hpp" diff --git a/src/vault/gear/job.h b/src/vault/gear/job.h index 506878561..b30b24d07 100644 --- a/src/vault/gear/job.h +++ b/src/vault/gear/job.h @@ -45,8 +45,9 @@ #include "lib/llist.h" #include "lib/hash-value.h" -#include "lib/time.h" +#include +typedef int64_t raw_time_64; ////////////////////////////////////////////////////////////////////////TICKET #1287 : rework Job representation -- and then turn this into a C++ Header enum JobState @@ -189,6 +190,7 @@ typedef lumiera_jobDescriptor* LumieraJobDescriptor; #ifdef __cplusplus /* ============== C++ Interface ================= */ #include "lib/nocopy.hpp" +#include "lib/time/timevalue.hpp" ////////////////////////////////////////////////////////////////////////TICKET #1287 : rework Job representation -- and then turn this into a C++ Header #include diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 1a604aa9d..9a9180ce3 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -162309,8 +162309,8 @@ Since then others have made contributions, see the log for the history. - - + + @@ -162713,7 +162713,7 @@ Since then others have made contributions, see the log for the history. - + @@ -162745,7 +162745,7 @@ Since then others have made contributions, see the log for the history. - + @@ -162801,10 +162801,10 @@ Since then others have made contributions, see the log for the history. - - + + - + @@ -162820,16 +162820,15 @@ Since then others have made contributions, see the log for the history. - +

- wohl inzwischen nirgends mehr includiert + inzwischen nirgends mehr includiert — lasse diesen Header und die Library-Abhängigkeit dennoch vorerst bestehen — als Platzhalter (für eine »Domain-Ontology«)

- @@ -162866,8 +162865,8 @@ Since then others have made contributions, see the log for the history. - - + + @@ -162917,9 +162916,10 @@ Since then others have made contributions, see the log for the history. - - - + + + + @@ -162985,7 +162985,8 @@ Since then others have made contributions, see the log for the history. - + + @@ -163042,7 +163043,7 @@ Since then others have made contributions, see the log for the history. - + @@ -163103,7 +163104,7 @@ Since then others have made contributions, see the log for the history. - + @@ -163114,17 +163115,17 @@ Since then others have made contributions, see the log for the history. - - + + - - - + + + @@ -163179,7 +163180,7 @@ Since then others have made contributions, see the log for the history. - + @@ -163205,7 +163206,7 @@ Since then others have made contributions, see the log for the history. - + @@ -163228,7 +163229,7 @@ Since then others have made contributions, see the log for the history. - + @@ -163249,9 +163250,10 @@ Since then others have made contributions, see the log for the history. - - - + + + + @@ -163260,6 +163262,7 @@ Since then others have made contributions, see the log for the history. + @@ -163279,13 +163282,14 @@ Since then others have made contributions, see the log for the history. + - + - + @@ -163325,30 +163329,24 @@ Since then others have made contributions, see the log for the history. - - - +

Zeiten sind bereits µ-Tick-quantisiert, d.h. eine einfache Division über ein Grid ist stets im Integer-Value range und ohne Fehler ausführbar

- -
+
- - - +

und zwar wegen der Gefahr numerischer Overflows; die eingebaute Limitierung der Lumiera-Time ist nicht ausreichend: denn die Quantisierung muß die Framerate durch das µ-Grid dividieren, also den Zähler mal 10^6 nehmen

- -
+
@@ -163359,16 +163357,13 @@ Since then others have made contributions, see the log for the history. - - - +

...und das macht durchaus Sinn, grade wegen der starken Limitierung, die ich bisher in diesem Fall demonstriert habe; außerdem ist diese grid-local-Time ohnehin etwas sonderbar, und auch daher ist es sinnvoll, diese als Offset (gegenüber dem Origin) zu modellieren. Sofern der Benutzer in eine normale Lumiera-Time speichert, sind wir wieder zurück bei den alten Limitierungen, aber man kann eben mit diesem Offset auch weiterrechnen, und ihn z.B. zum Origin dazuaddieren (und würde dann im Beispiel wieder bei ganz kleinen Zeiten ankommen)

- -
+
@@ -163376,16 +163371,13 @@ Since then others have made contributions, see the log for the history. - - - +

...und die Grenzen ausreizen, die das Zeit-Framework (bewußt) erlaubt, wenn man die Typisierung geschickt ausnutzt: denn ein TimeValue wird aus einer anderen Zeit-Enität (absichtlich) ohne weiteren Bounds-Check übernommen. Es sind mithin durchaus TimeValue möglich, die größer sind als Time::MAX

- -
+ @@ -163408,6 +163400,10 @@ Since then others have made contributions, see the log for the history.
+ + + +