Lumiera  0.pre.03
»edit your freedom«
quantiser.hpp
Go to the documentation of this file.
1 /*
2  QUANTISER.hpp - 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 
30 #ifndef LIB_TIME_QUANTISER_H
31 #define LIB_TIME_QUANTISER_H
32 
33 #include "lib/error.hpp"
34 #include "lib/time/grid.hpp"
35 #include "lib/time/formats.hpp"
36 #include "lib/time/timevalue.hpp"
37 #include "lib/iter-adapter.hpp"
38 
39 #include <vector>
40 #include <string>
41 #include <cmath>
42 
43 
44 namespace lib {
45 namespace time {
46 
47  LUMIERA_ERROR_DECLARE (UNKNOWN_GRID);
48 
49 
50  namespace { // stashed here for later
51 
52  template<typename NUM>
53  struct ValTrait;
54 
55  template<>
56  struct ValTrait<int>
57  {
58  static int asInt (int val) { return val; }
59  static double asDouble (int val) { return val; }
60  };
61 
62  template<>
63  struct ValTrait<double>
64  {
65  static int asInt (double val) { return std::floor(0.5+val); }
66  static double asDouble (double val) { return val; }
67  };
68 
69  }
70 
71 
72 
78 
79 
80 
81 
82 
93  class Quantiser
94  : public virtual Grid
95  {
96  protected:
97  format::Supported supportedFormats_;
98 
99  Quantiser()
100  : supportedFormats_(format::SupportStandardTimecode())
101  { }
102 
103  public:
104  template<class FMT>
105  bool
106  supports() const
107  {
108  return supportedFormats_.check<FMT>();
109  }
110 
111  static PQuant retrieve (Symbol gridID);
112  TimeValue materialise (TimeValue const& raw) const;
113 
114 
115  //------Grid-API----------------------------------------------
116  virtual FrameCnt gridPoint (TimeValue const& raw) const =0;
117  virtual TimeValue gridLocal (TimeValue const& raw) const =0;
118  virtual TimeValue timeOf (FrameCnt gridPoint) const =0;
119  virtual TimeValue timeOf (FSecs, int =0) const =0;
120  };
121 
122 
123 
124 
125 
136  : public Quantiser
137  {
138  Time origin_;
139  Duration raster_;
140 
141  public:
142  FixedFrameQuantiser (FrameRate const& frames_per_second, TimeValue referencePoint =TimeValue(0));
143  FixedFrameQuantiser (Duration const& frame_duration, TimeValue referencePoint =TimeValue(0));
144 
145  FrameCnt gridPoint (TimeValue const&) const;
146  TimeValue gridLocal (TimeValue const&) const;
147  TimeValue timeOf (FrameCnt gridPoint) const;
148  TimeValue timeOf (FSecs, int =0) const;
149 
150  };
151 
152 
153 
154 }} // lib::time
155 #endif
auto retrieve(void *streamType)
Entrance point for defining data flows and processing steps.
Facility to create grid-aligned time values.
Definition: quantiser.hpp:93
bool check() const
check if a specific Format is supported
Definition: formats.hpp:227
Framerate specified as frames per second.
Definition: timevalue.hpp:655
Helper template(s) for creating Lumiera Forward Iterators.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:62
Implementation namespace for support and library code.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Descriptor to denote support for a specific (timecode) format.
Definition: formats.hpp:187
definition of a time grid abstraction for time and timecode handling.
static int asInt(double val)
in accordance with Lumiera&#39;s time handling RfC
Definition: quantiser.hpp:65
PQuant getDefaultGridFallback()
Definition: quantiser.cpp:38
predefined standard configuration: Descriptor for supporting all the classical timecode formats ...
Definition: formats.hpp:237
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:220
Lumiera error handling (C++ interface).
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
Definition of time code formats This header is part of the Lumiera time and timecode handling library...
Abstraction of a value alignment grid.
Definition: grid.hpp:58
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