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) 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 
39 #ifndef LIB_TIME_QUANTISER_H
40 #define LIB_TIME_QUANTISER_H
41 
42 #include "lib/error.hpp"
43 #include "lib/time/grid.hpp"
44 #include "lib/time/formats.hpp"
45 #include "lib/time/timevalue.hpp"
46 #include "lib/iter-adapter.hpp"
47 
48 #include <vector>
49 #include <string>
50 #include <cmath>
51 
52 
53 namespace lib {
54 namespace time {
55 
56  LUMIERA_ERROR_DECLARE (UNKNOWN_GRID);
57 
58 
59  namespace { // stashed here for later
60 
61  template<typename NUM>
62  struct ValTrait;
63 
64  template<>
65  struct ValTrait<int>
66  {
67  static int asInt (int val) { return val; }
68  static double asDouble (int val) { return val; }
69  };
70 
71  template<>
72  struct ValTrait<double>
73  {
74  static int asInt (double val) { return std::floor(0.5+val); }
75  static double asDouble (double val) { return val; }
76  };
77 
78  }
79 
80 
81 
87 
88 
89 
90 
91 
102  class Quantiser
103  : public virtual Grid
104  {
105  protected:
106  format::Supported supportedFormats_;
107 
108  Quantiser()
109  : supportedFormats_(format::SupportStandardTimecode())
110  { }
111 
112  public:
113  template<class FMT>
114  bool
115  supports() const
116  {
117  return supportedFormats_.check<FMT>();
118  }
119 
120  static PQuant retrieve (Symbol gridID);
121  TimeValue materialise (TimeValue const& raw) const;
122 
123 
124  //------Grid-API----------------------------------------------
125  virtual FrameCnt gridPoint (TimeValue const& raw) const =0;
126  virtual TimeValue gridLocal (TimeValue const& raw) const =0;
127  virtual TimeValue timeOf (FrameCnt gridPoint) const =0;
128  virtual TimeValue timeOf (FSecs, int =0) const =0;
129  };
130 
131 
132 
133 
134 
145  : public Quantiser
146  {
147  Time origin_;
148  Duration raster_;
149 
150  public:
151  FixedFrameQuantiser (FrameRate const& frames_per_second, TimeValue referencePoint =TimeValue(0));
152  FixedFrameQuantiser (Duration const& frame_duration, TimeValue referencePoint =TimeValue(0));
153 
154  FrameCnt gridPoint (TimeValue const&) const;
155  TimeValue gridLocal (TimeValue const&) const;
156  TimeValue timeOf (FrameCnt gridPoint) const;
157  TimeValue timeOf (FSecs, int =0) const;
158 
159  };
160 
161 
162 
163 }} // lib::time
164 #endif
Facility to create grid-aligned time values.
Definition: quantiser.hpp:102
bool check() const
check if a specific Format is supported
Definition: formats.hpp:236
Framerate specified as frames per second.
Definition: timevalue.hpp:664
Helper template(s) for creating Lumiera Forward Iterators.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:71
Implementation namespace for support and library code.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Descriptor to denote support for a specific (timecode) format.
Definition: formats.hpp:196
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:74
PQuant getDefaultGridFallback()
Definition: quantiser.cpp:47
predefined standard configuration: Descriptor for supporting all the classical timecode formats ...
Definition: formats.hpp:246
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:229
Lumiera error handling (C++ interface).
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
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:67
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