diff --git a/src/lib/time.cpp b/src/lib/time.cpp index 83ffa4e53..16acf2622 100644 --- a/src/lib/time.cpp +++ b/src/lib/time.cpp @@ -118,6 +118,13 @@ lumiera_quantise_time (gavl_time_t time, gavl_time_t origin, gavl_time_t grid) return alignedTime; } +gavl_time_t +lumiera_time_of_gridpoint (long nr, gavl_time_t origin, gavl_time_t grid) +{ + gavl_time_t offset = nr * grid; + return origin + offset; +} + gavl_time_t lumiera_build_time(long millis, uint secs, uint mins, uint hours) diff --git a/src/lib/time.h b/src/lib/time.h index 873157e7f..6f9974dab 100644 --- a/src/lib/time.h +++ b/src/lib/time.h @@ -116,6 +116,15 @@ lumiera_quantise_frames (gavl_time_t time, gavl_time_t origin, gavl_time_t grid) gavl_time_t lumiera_quantise_time (gavl_time_t time, gavl_time_t origin, gavl_time_t grid); +/** + * Calculate time of a grid point (frame start) + * @param nr index number of the grid point (0 is at origin) + * @param grid spacing of the grid intervals, measured in GAVL_TIME_SCALE + * @return time point (frame start) on the Lumiera internal time scale + */ +gavl_time_t +lumiera_time_of_gridpoint (long nr, gavl_time_t origin, gavl_time_t grid); + /** * Builds a time value by summing up the given components. */ diff --git a/src/lib/time/digxel.hpp b/src/lib/time/digxel.hpp index 4a359f462..6ade5c742 100644 --- a/src/lib/time/digxel.hpp +++ b/src/lib/time/digxel.hpp @@ -273,7 +273,7 @@ namespace time { /* == predefined Digxel configurations == */ typedef Digxel< int, digxel::SexaFormatter> SexaDigit; ///< for displaying time components (sexagesimal) typedef Digxel HexaDigit; ///< for displaying a hex byte - typedef Digxel CountVal; ///< for displaying a hex byte + typedef Digxel CountVal; ///< for displaying a hex byte }} // lib::time diff --git a/src/lib/time/formats.hpp b/src/lib/time/formats.hpp index 5478e8c21..ca92b048c 100644 --- a/src/lib/time/formats.hpp +++ b/src/lib/time/formats.hpp @@ -44,6 +44,25 @@ namespace time { class Quantiser; // API for grid aligning + /** + * smart reference for accessing an existing quantiser + */ + class QuantiserRef + { + size_t hashID_; + + public: + QuantiserRef (Quantiser const&); + + // using standard copy; + + + const Quantiser * + operator-> () + { + UNIMPLEMENTED ("how to manage and address the existing quantisers"); + } + }; /** @@ -74,10 +93,11 @@ namespace time { * these frame counts. As with any timecode, the * underlying framerate/quantisation remains implicit. */ - class Frames - : public Format + struct Frames + : Format { - static void rebuild (FrameNr&, Quantiser const&, TimeValue const&); + static void rebuild (FrameNr&, Quantiser const&, TimeValue const&); + static TimeValue evaluate (FrameNr const&, QuantiserRef); }; @@ -87,10 +107,11 @@ namespace time { * by specifying time as hour-minute-second plus the * frame number within the actual second. */ - class Smpte - : public Format + struct Smpte + : Format { - static void rebuild (SmpteTC&, Quantiser const&); + static void rebuild (SmpteTC&, Quantiser const&); + static TimeValue evaluate (SmpteTC const&, QuantiserRef); }; @@ -101,10 +122,11 @@ namespace time { * entity in time. HMS-Timecode is similar to SMPTE, but uses a * floating point milliseconds value instead of the frame count */ - class Hms - : public Format + struct Hms + : Format { - static void rebuild (HmsTC&, Quantiser const&); + static void rebuild (HmsTC&, Quantiser const&); + static TimeValue evaluate (HmsTC const&, QuantiserRef); }; @@ -117,10 +139,11 @@ namespace time { * @note Seconds is implemented as rational number and thus uses * decimal format, not the usual sexagesimal time format */ - class Seconds - : public Format + struct Seconds + : Format { - static void rebuild (Secs&, Quantiser const&); + static void rebuild (Secs&, Quantiser const&); + static TimeValue evaluate (Secs const&, QuantiserRef); }; diff --git a/src/lib/time/quantiser.cpp b/src/lib/time/quantiser.cpp index 9879eac47..9b81d40a2 100644 --- a/src/lib/time/quantiser.cpp +++ b/src/lib/time/quantiser.cpp @@ -92,7 +92,7 @@ namespace time { * @see #lumiera_quantise_time */ TimeValue - FixedFrameQuantiser::gridAlign (TimeValue const& rawTime) + FixedFrameQuantiser::gridAlign (TimeValue const& rawTime) const { return TimeValue (lumiera_quantise_time (_raw(rawTime), _raw(origin_), _raw(raster_))); } @@ -107,11 +107,23 @@ namespace time { * @see #lumiera_quantise_frames */ long - FixedFrameQuantiser::gridPoint (TimeValue const& rawTime) + FixedFrameQuantiser::gridPoint (TimeValue const& rawTime) const { return lumiera_quantise_frames (_raw(rawTime), _raw(origin_), _raw(raster_)); } - + + + /** calculate time value of a grid interval (frame) start point + * @return time point measured in Lumiera internal time + * @warning returned time values are limited by the + * valid range of lumiera::Time + */ + TimeValue + FixedFrameQuantiser::timeOf (long gridPoint) const + { + return TimeValue (lumiera_time_of_gridpoint (gridPoint, _raw(origin_), _raw(raster_))); + } + diff --git a/src/lib/time/quantiser.hpp b/src/lib/time/quantiser.hpp index a5b8273eb..bbc88db70 100644 --- a/src/lib/time/quantiser.hpp +++ b/src/lib/time/quantiser.hpp @@ -84,32 +84,13 @@ namespace time { typedef _Iter iterator; iterator getSupportedFormats() const; - virtual TimeValue gridAlign (TimeValue const& raw) =0; - virtual long gridPoint (TimeValue const& raw) =0; + virtual TimeValue gridAlign (TimeValue const& raw) const =0; + virtual long gridPoint (TimeValue const& raw) const =0; + virtual TimeValue timeOf (long gridPoint) const =0; }; - /** - * smart reference - * for accessing an existing quantiser - */ - class QuantiserRef - { - size_t hashID_; - - public: - QuantiserRef (Quantiser const&); - - // using standard copy; - - - Quantiser const& - operator-> () - { - UNIMPLEMENTED ("how to manage and address the existing quantisers"); - } - }; @@ -133,8 +114,9 @@ namespace time { FixedFrameQuantiser (Duration const& frame_duration, TimeValue referencePoint =TimeValue(0)); - TimeValue gridAlign (TimeValue const&); - long gridPoint (TimeValue const&); + TimeValue gridAlign (TimeValue const&) const; + long gridPoint (TimeValue const&) const; + TimeValue timeOf (long gridPoint) const; }; diff --git a/src/lib/time/timecode.cpp b/src/lib/time/timecode.cpp index 97cffcf7f..978739635 100644 --- a/src/lib/time/timecode.cpp +++ b/src/lib/time/timecode.cpp @@ -49,24 +49,50 @@ namespace time { { framecnt.setValueRaw(quantiser.gridPoint (rawTime)); } + + /** calculate the time point denoted by this frame count */ + TimeValue + Frames::evaluate (FrameNr const& framecnt, QuantiserRef quantiser) + { + return quantiser->timeOf (framecnt); + } + } + /** */ + QuantiserRef::QuantiserRef (Quantiser const&) + : hashID_(123) /////////////////////////////////////////////////TODO + { } + + + /** */ + FrameNr::FrameNr (QuTime const& quantisedTime) + : TCode(quantisedTime) + , CountVal() + { + quantisedTime.castInto (*this); + } + + /** */ SmpteTC::SmpteTC (QuTime const& quantisedTime) - : tpoint_(quantisedTime) /////////////////////////////TODO eternal bullshit + : TCode(quantisedTime) +// : tpoint_(quantisedTime) /////////////////////////////TODO eternal bullshit { } /** */ HmsTC::HmsTC (QuTime const& quantisedTime) - : tpoint_(quantisedTime) /////////////////////////////TODO bullshit + : TCode(quantisedTime) +// : tpoint_(quantisedTime) /////////////////////////////TODO bullshit { } /** */ Secs::Secs (QuTime const& quantisedTime) - : sec_(TimeVar(quantisedTime) / GAVL_TIME_SCALE) /////////////TODO bullshit + : TCode(quantisedTime) +// : sec_(TimeVar(quantisedTime) / GAVL_TIME_SCALE) /////////////TODO bullshit { } diff --git a/src/lib/time/timecode.hpp b/src/lib/time/timecode.hpp index 793b07aaf..fdfe5f303 100644 --- a/src/lib/time/timecode.hpp +++ b/src/lib/time/timecode.hpp @@ -50,7 +50,6 @@ namespace time { */ class TCode { - QuantiserRef qID_; public: virtual ~TCode(); @@ -67,6 +66,9 @@ namespace time { virtual string show() const =0; virtual Literal tcID() const =0; virtual TimeValue value() const =0; + + protected: + QuantiserRef qID_; }; @@ -81,24 +83,19 @@ namespace time { */ class FrameNr : public TCode - , CountVal + , public CountVal { - string show() const { return lexical_cast(nr_)+"fr"; } + string show() const { return string(show())+"fr"; } Literal tcID() const { return "Frame-count"; } - TimeValue value() const { return Time(FACTOR_TODO * nr_); } + TimeValue value() const { return Format::evaluate (*this, qID_); } public: typedef format::Frames Format; - FrameNr (QuTime const& quantisedTime) - : TCode(quantisedTime) - , CountVal() - { - quantisedTime.castInto (*this); - } + FrameNr (QuTime const& quantisedTime); - operator long() const { return nr_; } + // CountVal implicitly convertible to long }; diff --git a/src/lib/time/timequant.hpp b/src/lib/time/timequant.hpp index 6978bc63a..be5e82b71 100644 --- a/src/lib/time/timequant.hpp +++ b/src/lib/time/timequant.hpp @@ -70,7 +70,8 @@ namespace time { /* == implementation == */ - + + inline QuTime::operator QuantiserRef() const { ASSERT (quantiser_); @@ -78,7 +79,7 @@ namespace time { } template - bool + inline bool QuTime::supports() const { return false; ////////////////TODO; @@ -86,7 +87,7 @@ namespace time { template - typename format::Traits::TimeCode + inline typename format::Traits::TimeCode QuTime::formatAs() const { typedef typename format::Traits::TimeCode TC; @@ -95,12 +96,12 @@ namespace time { template - void + inline void QuTime::castInto (TC& timecode) const { typedef typename TC::Format Format; - Format::rebuild (timecode, *quantiser_); + Format::rebuild (timecode, *quantiser_, TimeValue(*this)); }