From 02653621f6e19b4db41ca38be4ad9dd03f7450eb Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 17 Jan 2011 06:38:10 +0100 Subject: [PATCH] adapt the TimeGrid meta asset, so it can be published as Quantiser --- src/lib/time/quantiser.hpp | 3 +- src/proc/asset/meta/time-grid.cpp | 63 +++++++++++++++++++++---------- src/proc/asset/meta/time-grid.hpp | 20 +++++----- tests/41asset.tests | 2 +- 4 files changed, 54 insertions(+), 34 deletions(-) diff --git a/src/lib/time/quantiser.hpp b/src/lib/time/quantiser.hpp index 6aaff8e69..369c48055 100644 --- a/src/lib/time/quantiser.hpp +++ b/src/lib/time/quantiser.hpp @@ -73,10 +73,9 @@ namespace time { * the Lumiera session. Time quantisation and timecode handling explicitly * relies on this Quantiser interface. * - * @todo WIP-WIP-WIP */ class Quantiser - : public Grid + : public virtual Grid { protected: format::Supported supportedFormats_; diff --git a/src/proc/asset/meta/time-grid.cpp b/src/proc/asset/meta/time-grid.cpp index 65f1978c8..ad3599a80 100644 --- a/src/proc/asset/meta/time-grid.cpp +++ b/src/proc/asset/meta/time-grid.cpp @@ -27,12 +27,14 @@ #include "lib/time/quantiser.hpp" #include "lib/time/timevalue.hpp" #include "lib/time/display.hpp" +#include "lib/advice.hpp" #include "lib/util.hpp" //#include "include/logging.h" #include #include +using util::cStr; using util::isnil; using boost::format; using boost::str; @@ -44,10 +46,6 @@ namespace meta { namespace error = lumiera::error; - namespace { - - // Implementation details (still required???) - } /** */ @@ -63,32 +61,58 @@ namespace meta { using lib::time::Offset; using lib::time::FSecs; + using lib::time::PQuant; + using lib::time::Quantiser; + using lib::time::FixedFrameQuantiser; + using std::tr1::dynamic_pointer_cast; + + namespace advice = lib::advice; + + namespace { + + /** @internal helper to retrieve the smart-ptr + * from the AssetManager, then attach a further + * smart-ptr-to-Quantiser to that, which then can be + * published via the \link advice.hpp "advice system"\endlink + */ + inline PGrid + publishWrapped (TimeGrid& newGrid) + { + PGrid gridImplementation = AssetManager::instance().wrap (newGrid); + PQuant quantiser (dynamic_pointer_cast(gridImplementation)); + Literal bindingID (cStr(newGrid.ident.name)); + + advice::Provision(bindingID).setAdvice(quantiser); + return gridImplementation; + } + + + } + /** * TimeGrid implementation: a trivial time grid, * starting at a given point in time and using a - * constant grid spacing + * constant grid spacing. + * + * @note The actual implementation is mixed in, + * together with the Quantiser API; the intended use + * of this implementation is to publish it via the advice + * framework, when building and registering the meta asset. */ class SimpleTimeGrid : public TimeGrid + , public FixedFrameQuantiser { - lib::time::FixedFrameQuantiser frameGrid_; - - /* == grid API forwarded to embedded quantiser == */ - long gridPoint (TimeValue const& rawTime) const { return frameGrid_.gridPoint (rawTime); } - TimeValue gridAlign (TimeValue const& rawTime) const { return frameGrid_.gridAlign (rawTime); } - TimeValue timeOf (long gridPoint) const { return frameGrid_.timeOf (gridPoint); } - TimeValue timeOf (FSecs gridTime, int gridOffset =0) const { return frameGrid_.timeOf (gridTime,gridOffset); } - public: SimpleTimeGrid (Time start, Duration frameDuration, EntryID const& name) : TimeGrid (name) - , frameGrid_(frameDuration,start) + , FixedFrameQuantiser(frameDuration,start) { } SimpleTimeGrid (Time start, FrameRate frames_per_second, EntryID const& name) : TimeGrid (name) - , frameGrid_(frames_per_second,start) + , FixedFrameQuantiser(frames_per_second,start) { } }; @@ -104,7 +128,7 @@ namespace meta { * might raise further exception when asset registration fails. * @todo currently (12/2010) the AssetManager is unable to detect duplicate assets. * Later on the intention is that in such cases, instead of creating a new grid - * we'll silently return the already registered exisiting and equivalent grid. + * we'll silently return the already registered existing and equivalent grid. */ P Builder::commit() @@ -116,13 +140,12 @@ namespace meta { if (isnil (id_)) { - format gridIdFormat("grid_%f_%s"); - id_ = str(gridIdFormat % fps_ % origin_); + format gridIdFormat("grid(%f_%d)"); + id_ = str(gridIdFormat % fps_ % _raw(origin_)); } EntryID nameID (id_); - TimeGrid& newGrid (*new SimpleTimeGrid(origin_, fps_, nameID)); - return AssetManager::instance().wrap (newGrid); + return publishWrapped (*new SimpleTimeGrid(origin_, fps_, nameID)); } diff --git a/src/proc/asset/meta/time-grid.hpp b/src/proc/asset/meta/time-grid.hpp index 01b96f480..b8e768326 100644 --- a/src/proc/asset/meta/time-grid.hpp +++ b/src/proc/asset/meta/time-grid.hpp @@ -69,23 +69,21 @@ namespace meta { /** - * Interface: a grid and scale for time quantisation. - * This meta-Asset describes a coordinate system or - * reference scale for quantised time values. + * Interface: a grid and scale definition for time quantisation. + * This meta-Asset describes a coordinate system or reference scale + * for quantised time values. Especially it allows to define an actual + * implementation, which can then implicitly be used by lib::time::QuTime + * and for conversions into timecode. + * @note for this to work, the actual implementation classes returned + * by the builder or the static #build function additionally expose + * an implementation of the lib::time::Quantiser API */ class TimeGrid : public Meta - , public lib::time::Grid + , public virtual lib::time::Grid { public: - //--------Grid-API------------------------------------ - long gridPoint (TimeValue const& raw) const =0; - TimeValue gridAlign (TimeValue const& raw) const =0; - TimeValue timeOf (long gridPoint) const =0; - TimeValue timeOf (FSecs, int =0) const =0; - - /* === shortcut builder functions === */ static PGrid build (Symbol gridID, FrameRate frames_per_second); static PGrid build (Symbol gridID, FrameRate frames_per_second, Time origin); diff --git a/tests/41asset.tests b/tests/41asset.tests index a117cd120..bd2cb93a2 100644 --- a/tests/41asset.tests +++ b/tests/41asset.tests @@ -71,6 +71,6 @@ END TEST "Simple TimeGrid" TimeGridBasics_test <