diff --git a/src/gui/panels/timeline-panel.cpp b/src/gui/panels/timeline-panel.cpp index 5c79bbe44..9441e8969 100644 --- a/src/gui/panels/timeline-panel.cpp +++ b/src/gui/panels/timeline-panel.cpp @@ -29,9 +29,8 @@ #include "gui/model/project.hpp" #include "gui/controller/controller.hpp" -extern "C" { #include "lib/time.h" -} + using namespace Gtk; using namespace sigc; diff --git a/src/gui/widgets/timeline/timeline-ruler.cpp b/src/gui/widgets/timeline/timeline-ruler.cpp index 63d6ecc7a..c01835c71 100644 --- a/src/gui/widgets/timeline/timeline-ruler.cpp +++ b/src/gui/widgets/timeline/timeline-ruler.cpp @@ -27,9 +27,8 @@ #include "gui/window-manager.hpp" #include "gui/util/cairo-util.hpp" -extern "C" { #include "lib/time.h" -} + using namespace Gtk; using namespace Cairo; diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 8374eab38..fe64f516a 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -59,7 +59,7 @@ liblumiera_la_SOURCES = \ $(liblumiera_la_srcdir)/test/suite.cpp \ $(liblumiera_la_srcdir)/test/test-helper.cpp \ $(liblumiera_la_srcdir)/test/testoption.cpp \ - $(liblumiera_la_srcdir)/time.c \ + $(liblumiera_la_srcdir)/time.cpp \ $(liblumiera_la_srcdir)/time/lumitime.cpp \ $(liblumiera_la_srcdir)/time/quantiser.cpp \ $(liblumiera_la_srcdir)/time/timecode.cpp \ diff --git a/src/lib/lumitime-fmt.hpp b/src/lib/lumitime-fmt.hpp index 20b24f951..b916c13a6 100644 --- a/src/lib/lumitime-fmt.hpp +++ b/src/lib/lumitime-fmt.hpp @@ -45,13 +45,11 @@ #define LUMIERA_LUMITIME_FMT_H #include "lib/lumitime.hpp" - -extern "C" { #include "lib/time.h" -} #include + namespace lumiera { diff --git a/src/lib/time.c b/src/lib/time.cpp similarity index 98% rename from src/lib/time.c rename to src/lib/time.cpp index 6f62a8ada..a85e2d1ea 100644 --- a/src/lib/time.c +++ b/src/lib/time.cpp @@ -19,12 +19,14 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include "lib/time.h" +#include "lib/error.hpp" +extern "C" { #include "lib/tmpbuf.h" +} -#include #include +#include /* GAVL_TIME_SCALE is the correct factor or dividend when using gavl_time_t for diff --git a/src/lib/time.h b/src/lib/time.h index eabc4d5f8..666fa4206 100644 --- a/src/lib/time.h +++ b/src/lib/time.h @@ -19,17 +19,66 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/** @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 \em 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 \em 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 backend 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. + ** + ** + ** @see lib::time::Time + ** @see timequant.hpp + ** @see TimeValue_test + ** + */ + + #ifndef LUMIERA_TIME_H #define LUMIERA_TIME_H #include #include +#ifdef __cplusplus /*=================== C++ facilities ===================== */ +#include "lib/time/timevalue.hpp" + + /** - * Formats a time in a safeclib tmpbuf in HH:MM:SS:mmm format. - * @param size maximal length for the string - * @param the time value to print - * @return safeclib temporary buffer containing the constructed of the string + * Converts a fraction of seconds to Lumiera's internal opaque time scale. + * @param fractionalSeconds given as rational number + */ +inline gavl_time_t +lumiera_rational_to_time (lib::time::FSecs const& fractionalSeconds) +{ + return boost::rational_cast (GAVL_TIME_SCALE * fractionalSeconds); +} + + + + + +extern "C" { /* ===================== C interface ======================== */ +#endif + + +/** + * Formats a time value in H:MM:SS.mmm format into a temporary buffer. + * @return safeclib temporary buffer containing formatted time string */ char* lumiera_tmpbuf_print_time (gavl_time_t time); @@ -41,19 +90,19 @@ lumiera_tmpbuf_print_time (gavl_time_t time); * as zero. Each interval includes its lower bound, but excludes its upper bound. * @param grid spacing of the grid intervals, measured in GAVL_TIME_SCALE * @return number of the grid interval containing the given time. - * @warning the resulting value is limited such as to fit into a 64bit long + * @warning the resulting value is limited to (Time::Min, Time::MAX) */ int64_t lumiera_quantise_frames (gavl_time_t time, double grid, gavl_time_t origin); /** - * Similar to #lumiera_quantise_frames, but returns a grid aligned \em time value + * Similar to #lumiera_quantise_frames, but returns a grid aligned \em time value * @return time of start of the grid interval containing the given time, * but measured relative to the origin * @warning because the resulting value needs to be limited to fit into a 64bit long, * the addressable time range can be considerably reduced. For example, if - * origin = LLONG_MIN, then all original time values above zero will be - * clipped, because the result, relative to origin, needs to be <= LLONG_MAX + * origin = Time::MIN, then all original time values above zero will be + * clipped, because the result, relative to origin, needs to be <= Time::MAX */ gavl_time_t lumiera_quantise_time (gavl_time_t time, double grid, gavl_time_t origin); @@ -65,24 +114,28 @@ gavl_time_t lumiera_build_time (long millis, uint secs, uint mins, uint hours); /** - * Get the hour part of given time. + * Extract the hour part of given time. */ int lumiera_time_hours(gavl_time_t time); /** - * Get the minute part of given time. + * Extract the minute part of given time. */ int lumiera_time_minutes(gavl_time_t time); /** - * Get the seconds part of given time. + * Extract the seconds part of given time. */ int lumiera_time_seconds(gavl_time_t time); /** - * Get the milliseconds part of given time. + * Extract the milliseconds part of given time. */ int lumiera_time_millis(gavl_time_t time); -#endif + +#ifdef __cplusplus +}//extern "C" +#endif +#endif diff --git a/src/lib/time/lumitime.cpp b/src/lib/time/lumitime.cpp index 15444a60c..53338e3a6 100644 --- a/src/lib/time/lumitime.cpp +++ b/src/lib/time/lumitime.cpp @@ -23,10 +23,7 @@ #include "lib/lumitime.hpp" #include "lib/time/timevalue.hpp" - -extern "C" { #include "lib/time.h" -} #include #include diff --git a/src/lib/time/quantiser.cpp b/src/lib/time/quantiser.cpp index c1608184f..02ef85be8 100644 --- a/src/lib/time/quantiser.cpp +++ b/src/lib/time/quantiser.cpp @@ -24,10 +24,7 @@ #include "lib/time/quantiser.hpp" #include "lib/time/timevalue.hpp" #include "lib/time/timequant.hpp" - -extern "C" { #include "lib/time.h" -} #include diff --git a/src/lib/time/timecode.cpp b/src/lib/time/timecode.cpp index 3bb80e697..37e00a9ea 100644 --- a/src/lib/time/timecode.cpp +++ b/src/lib/time/timecode.cpp @@ -26,10 +26,7 @@ #include "lib/time/timevalue.hpp" #include "lib/time/timequant.hpp" #include "lib/time/formats.hpp" - -extern "C" { #include "lib/time.h" -} using std::string; diff --git a/tests/library/test-time.c b/tests/library/test-time.c index 4ce8b63bb..52ce79279 100644 --- a/tests/library/test-time.c +++ b/tests/library/test-time.c @@ -21,8 +21,8 @@ typedef unsigned int uint; -#include "lib/time.h" #include "tests/test.h" +#include "lib/time.h" #include