Lumiera  0.pre.03
»edit your freedom«
quantiser.cpp
Go to the documentation of this file.
1 /*
2  Quantiser - aligning time values to a time grid
3 
4  Copyright (C)
5  2010, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
14 
20 #include "lib/time/quantiser.hpp"
21 #include "lib/time/timevalue.hpp"
22 #include "lib/time/timequant.hpp"
23 #include "lib/time.h"
24 
25 #include <boost/rational.hpp>
26 
27 using boost::rational_cast;
28 using std::string;
29 
30 
31 namespace error = lumiera::error;
32 
33 namespace lib {
34 namespace time {
35 
36 
37  PQuant
39  {
40  static PQuant globalDefaultGrid (new FixedFrameQuantiser(1));
41  return globalDefaultGrid;
42  };
43 
44 
45 
46 
47 
48  Grid::~Grid() { } // hint to emit the VTable here...
49 
50 
51  /* Note: the ctor QuTime(TimeValue, Symbol) and the static function
52  * PQuant Quantiser::retrieve (Symbol) are defined in common-services.cpp
53  * To use this special convenience shortcuts, you need to link against liblumieracore.so
54  * This allows to use the Advice-system to retrieve grid definitions directly from the session
55  */
56 
57 
64  QuTime::QuTime (TimeValue raw, PQuant quantisation_to_use)
65  : Time(raw)
66  , quantiser_(quantisation_to_use)
67  { }
68 
69 
70 
75  FixedFrameQuantiser::FixedFrameQuantiser (FrameRate const& frames_per_second, TimeValue referencePoint)
76  : origin_(referencePoint)
77  , raster_(__ensure_nonzero(frames_per_second.duration()))
78  { }
79 
80  FixedFrameQuantiser::FixedFrameQuantiser (Duration const& frame_duration, TimeValue referencePoint)
81  : origin_(referencePoint)
82  , raster_(__ensure_nonzero(frame_duration))
83  { }
84 
85 
86 
87 
100  TimeValue
102  {
103  return timeOf (gridPoint (raw));
104  }
105 
106 
107 
116  FrameCnt
118  {
119  return lumiera_quantise_frames (_raw(rawTime), _raw(origin_), _raw(raster_));
120  }
121 
122 
135  TimeValue
137  {
138  return TimeValue (lumiera_quantise_time (_raw(rawTime), _raw(origin_), _raw(raster_)));
139  }
140 
141 
147  TimeValue
149  {
150  return TimeValue (lumiera_time_of_gridpoint (gridPoint, _raw(origin_), _raw(raster_)));
151  }
152 
153 
161  TimeValue
162  FixedFrameQuantiser::timeOf (FSecs gridTime, int gridOffset) const
163  {
164  Time gt(gridTime);
165  TimeVar timePoint = gt + origin_;
166  timePoint += gridOffset * Offset(raster_);
167  return timePoint;
168  }
169 
170 
171 
172 
173  LUMIERA_ERROR_DEFINE (UNKNOWN_GRID, "referring to an undefined grid or scale in value quantisation");
174 
175 
176 
177 }} // lib::time
178 
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:232
FixedFrameQuantiser(FrameRate const &frames_per_second, TimeValue referencePoint=TimeValue(0))
Create a quantiser based on a fixed constant spaced grid, rooted at the reference point as origin of ...
Definition: quantiser.cpp:75
Common functions for handling of time values.
Framerate specified as frames per second.
Definition: timevalue.hpp:655
int64_t lumiera_quantise_frames(gavl_time_t time, gavl_time_t origin, gavl_time_t grid)
Quantise the given time into a fixed grid, relative to the origin.
Definition: time.cpp:485
virtual ~Grid()
this is an Interface
Definition: quantiser.cpp:48
Implementation namespace for support and library code.
QuTime(TimeValue raw, Symbol gridID)
build a quantised time value, referring the time grid by-name.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
TimeValue materialise(TimeValue const &raw) const
convenience shortcut: materialise a raw time value based on this grid or time axis, but returning a raw time value.
Definition: quantiser.cpp:101
PQuant getDefaultGridFallback()
Definition: quantiser.cpp:38
TimeValue gridLocal(TimeValue const &) const
transform into the local time scale grid aligned.
Definition: quantiser.cpp:136
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:220
gavl_time_t lumiera_quantise_time(gavl_time_t time, gavl_time_t origin, gavl_time_t grid)
Similar to lumiera_quantise_frames, but returns a grid aligned relative time.
Definition: time.cpp:497
FrameCnt gridPoint(TimeValue const &) const
grid quantisation (alignment).
Definition: quantiser.cpp:117
gavl_time_t lumiera_time_of_gridpoint(int64_t nr, gavl_time_t origin, gavl_time_t grid)
Calculate time of a grid point (frame start)
Definition: time.cpp:505
Support library to represent grid-aligned time specifications This is part of Lumiera&#39;s time and time...
Library functions to support the formation of grid-aligned time values.
Offset measures a distance in time.
Definition: timevalue.hpp:358
TimeValue timeOf(FrameCnt gridPoint) const
calculate time value of a grid interval (frame) start point
Definition: quantiser.cpp:148
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:312
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:133
Simple stand-alone Quantiser implementation based on a constant sized gird.
Definition: quantiser.hpp:135
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:71