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) Lumiera.org
5  2010, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
29 #include "lib/time/quantiser.hpp"
30 #include "lib/time/timevalue.hpp"
31 #include "lib/time/timequant.hpp"
32 #include "lib/time.h"
33 
34 #include <boost/rational.hpp>
35 
36 using boost::rational_cast;
37 using std::string;
38 
39 
40 namespace error = lumiera::error;
41 
42 namespace lib {
43 namespace time {
44 
45 
46  PQuant
48  {
49  static PQuant globalDefaultGrid (new FixedFrameQuantiser(1));
50  return globalDefaultGrid;
51  };
52 
53 
54 
55 
56 
57  Grid::~Grid() { } // hint to emit the VTable here...
58 
59 
60  /* Note: the ctor QuTime(TimeValue, Symbol) and the static function
61  * PQuant Quantiser::retrieve (Symbol) are defined in common-services.cpp
62  * To use this special convenience shortcuts, you need to link against liblumieracore.so
63  * This allows to use the Advice-system to retrieve grid definitions directly from the session
64  */
65 
66 
73  QuTime::QuTime (TimeValue raw, PQuant quantisation_to_use)
74  : Time(raw)
75  , quantiser_(quantisation_to_use)
76  { }
77 
78 
79 
84  FixedFrameQuantiser::FixedFrameQuantiser (FrameRate const& frames_per_second, TimeValue referencePoint)
85  : origin_(referencePoint)
86  , raster_(__ensure_nonzero(frames_per_second.duration()))
87  { }
88 
89  FixedFrameQuantiser::FixedFrameQuantiser (Duration const& frame_duration, TimeValue referencePoint)
90  : origin_(referencePoint)
91  , raster_(__ensure_nonzero(frame_duration))
92  { }
93 
94 
95 
96 
109  TimeValue
111  {
112  return timeOf (gridPoint (raw));
113  }
114 
115 
116 
125  FrameCnt
127  {
128  return lumiera_quantise_frames (_raw(rawTime), _raw(origin_), _raw(raster_));
129  }
130 
131 
144  TimeValue
146  {
147  return TimeValue (lumiera_quantise_time (_raw(rawTime), _raw(origin_), _raw(raster_)));
148  }
149 
150 
156  TimeValue
158  {
159  return TimeValue (lumiera_time_of_gridpoint (gridPoint, _raw(origin_), _raw(raster_)));
160  }
161 
162 
170  TimeValue
171  FixedFrameQuantiser::timeOf (FSecs gridTime, int gridOffset) const
172  {
173  Time gt(gridTime);
174  TimeVar timePoint = gt + origin_;
175  timePoint += gridOffset * Offset(raster_);
176  return timePoint;
177  }
178 
179 
180 
181 
182  LUMIERA_ERROR_DEFINE (UNKNOWN_GRID, "referring to an undefined grid or scale in value quantisation");
183 
184 
185 
186 }} // lib::time
187 
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:241
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:84
Common functions for handling of time values.
Framerate specified as frames per second.
Definition: timevalue.hpp:664
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:494
virtual ~Grid()
this is an Interface
Definition: quantiser.cpp:57
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:308
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:110
PQuant getDefaultGridFallback()
Definition: quantiser.cpp:47
TimeValue gridLocal(TimeValue const &) const
transform into the local time scale grid aligned.
Definition: quantiser.cpp:145
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:229
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:506
FrameCnt gridPoint(TimeValue const &) const
grid quantisation (alignment).
Definition: quantiser.cpp:126
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:514
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:367
TimeValue timeOf(FrameCnt gridPoint) const
calculate time value of a grid interval (frame) start point
Definition: quantiser.cpp:157
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:321
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:142
Simple stand-alone Quantiser implementation based on a constant sized gird.
Definition: quantiser.hpp:144
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:80