diff --git a/src/lib/time/mutation.cpp b/src/lib/time/mutation.cpp index e98bafb33..cd2b205c3 100644 --- a/src/lib/time/mutation.cpp +++ b/src/lib/time/mutation.cpp @@ -197,7 +197,7 @@ namespace time { public: explicit MaterialiseIntoTarget (QuTime const& quant) - : SetNewStartTimeMutation (Secs(quant).getTime()) + : SetNewStartTimeMutation (PQuant(quant)->materialise(quant)) { } }; @@ -264,8 +264,10 @@ namespace time { virtual void change (QuTime& target) const { - long gridPoint = FrameNr(target)+steps_; - imposeChange (target, PQuant(target)->timeOf(gridPoint)); + PQuant const& grid (target); + int64_t originalGridPoint = grid->gridPoint(target); + int64_t adjustedGridPoint = originalGridPoint + steps_; + imposeChange (target, grid->timeOf (adjustedGridPoint)); } diff --git a/src/lib/time/quantiser.cpp b/src/lib/time/quantiser.cpp index 6ae061587..6a43b014a 100644 --- a/src/lib/time/quantiser.cpp +++ b/src/lib/time/quantiser.cpp @@ -47,7 +47,7 @@ namespace time { advice::Request query(gridID); PQuant grid_found = query.getAdvice(); if (!grid_found) - throw error::Logic ("unable to fetch the quantisation grid -- is it already defined?" + throw error::Logic ("unable to fetch the quantisation grid -- was it already defined?" ////////TICKET #197 , LUMIERA_ERROR_UNKNOWN_GRID); return grid_found; } @@ -112,6 +112,27 @@ namespace time { } + + /** convenience shortcut: \em materialise a raw time value + * based on this grid or time axis, but returning a raw time value. + * Implemented as combination of the #gridAlign and #timeOf operations, + * i.e. we quantise into this scale, but transform the result back onto + * the raw time value scale. + * @warning this operation incurs information loss. Values may be rounded + * and / or clipped, according to the grid used. And, contrary to + * a QuTime value, the information about the actual grid is + * discarded. Please don't use this operation if you just + * "want a number" but feel to too lazy to understand + * properly what quantisation means! + */ + TimeValue + Quantiser::materialise (TimeValue const& raw) const + { + return timeOf (gridPoint (raw)); + } + + + /** alignment to a simple fixed size grid. * The actual calculation first determines the number * of the grid interval containing the given rawTime, diff --git a/src/lib/time/quantiser.hpp b/src/lib/time/quantiser.hpp index a8efad7a1..33c4e9d3f 100644 --- a/src/lib/time/quantiser.hpp +++ b/src/lib/time/quantiser.hpp @@ -93,6 +93,7 @@ namespace time { } static PQuant retrieve (Symbol gridID); + TimeValue materialise (TimeValue const& raw) const; //------Grid-API----------------------------------------------