Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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"
37#include "lib/iter-adapter.hpp"
38
39#include <vector>
40#include <string>
41#include <cmath>
42
43
44namespace lib {
45namespace 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
94 : public virtual Grid
95 {
96 protected:
98
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 Offset 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 {
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 override;
146 Offset gridLocal (TimeValue const&) const override;
147 TimeValue timeOf (FrameCnt gridPoint) const override;
148 TimeValue timeOf (FSecs, int =0) const override;
149
150 private:
151 static int64_t grid_aligned (TimeValue const&, TimeValue const&);
152 };
153
154
155
156}} // lib::time
157#endif
Token or Atom with distinct identity.
Definition symbol.hpp:120
Duration is the internal Lumiera time metric.
Simple stand-alone Quantiser implementation based on a constant sized gird.
FrameCnt gridPoint(TimeValue const &) const override
grid quantisation (alignment).
Offset gridLocal(TimeValue const &) const override
transform into the local time scale grid aligned.
TimeValue timeOf(FrameCnt gridPoint) const override
calculate time value of a grid interval (frame) start point
static int64_t grid_aligned(TimeValue const &, TimeValue const &)
Quantise the given time into a fixed grid, relative to the origin.
Definition quantiser.cpp:86
Framerate specified as frames per second.
Abstraction of a value alignment grid.
Definition grid.hpp:59
Offset measures a distance in time.
Facility to create grid-aligned time values.
Definition quantiser.hpp:95
bool supports() const
TimeValue materialise(TimeValue const &raw) const
convenience shortcut: materialise a raw time value based on this grid or time axis,...
virtual TimeValue timeOf(FSecs, int=0) const =0
virtual TimeValue timeOf(FrameCnt gridPoint) const =0
virtual Offset gridLocal(TimeValue const &raw) const =0
static PQuant retrieve(Symbol gridID)
Access an existing grid definition or quantiser, known by the given symbolic ID.
virtual FrameCnt gridPoint(TimeValue const &raw) const =0
format::Supported supportedFormats_
Definition quantiser.hpp:97
basic constant internal time value.
Lumiera's internal time value datatype.
Descriptor to denote support for a specific (timecode) format.
Definition formats.hpp:188
bool check() const
check if a specific Format is supported
Definition formats.hpp:227
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition error.h:62
Lumiera error handling (C++ interface).
Definition of time code formats This header is part of the Lumiera time and timecode handling library...
definition of a time grid abstraction for time and timecode handling.
Helper template(s) for creating Lumiera Forward Iterators.
int64_t FrameCnt
relative framecount or frame number.
Definition digxel.hpp:310
PQuant getDefaultGridFallback()
Definition quantiser.cpp:94
std::shared_ptr< const Quantiser > PQuant
Definition formats.hpp:58
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Implementation namespace for support and library code.
static int asInt(double val)
in accordance with Lumiera's time handling RfC
Definition quantiser.hpp:65
a family of time value like entities and their relationships.