Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
formats.hpp
Go to the documentation of this file.
1/*
2 FORMATS.hpp - formats for displaying and specifying time
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
25#ifndef LIB_TIME_FORMATS_H
26#define LIB_TIME_FORMATS_H
27
30#include "lib/meta/typelist.hpp"
32#include "lib/typed-counter.hpp"
33
34#include <memory>
35#include <string>
36#include <bitset>
37
38namespace lumiera {
39namespace error {
40 LUMIERA_ERROR_DECLARE (INVALID_TIMECODE);
41}}
42
43
44namespace lib {
45namespace time {
46
47
48 // ====== forward declarations of concrete Timecode types
49
50 class FrameNr;
51 class SmpteTC;
52 class HmsTC;
53 class Secs;
54
55
56 class Quantiser; // API for grid aligning
57 using QuantR = Quantiser const&;
58 using PQuant = std::shared_ptr<const Quantiser>;
59
60
61 namespace format {
62
63 using std::string;
64 using lib::meta::NoInstance; // the following types are for metaprogramming only...
65
66
75 struct Frames
76 : NoInstance<Frames>
77 {
78 static TimeValue parse (string const&, QuantR);
79 static void rebuild (FrameNr&, QuantR, TimeValue const&);
80 static TimeValue evaluate (FrameNr const&, QuantR);
81 };
82
83
90 struct Smpte
91 : NoInstance<Smpte>
92 {
93 static TimeValue parse (string const&, QuantR);
94 static void rebuild (SmpteTC&, QuantR, TimeValue const&);
95 static TimeValue evaluate (SmpteTC const&, QuantR);
96 static uint getFramerate (QuantR, TimeValue const&);
97 static void applyRangeLimitStrategy (SmpteTC&);
98 };
99
100
108 struct Hms
109 : NoInstance<Hms>
110 {
111 static TimeValue parse (string const&, QuantR);
112 static void rebuild (HmsTC&, QuantR, TimeValue const&);
113 static TimeValue evaluate (HmsTC const&, QuantR);
114 };
115
116
126 struct Seconds
127 : NoInstance<Seconds>
128 {
129 static TimeValue parse (string const&, QuantR);
130 static void rebuild (Secs&, QuantR, TimeValue const&);
131 static TimeValue evaluate (Secs const&, QuantR);
132 };
133
134
135
136
137
138 template<class FMT>
139 struct Traits;
140
141 template<>
143 {
145 };
146
147 template<>
148 struct Traits<Smpte>
149 {
151 };
152
153 template<>
154 struct Traits<Hms>
155 {
157 };
158
159 template<>
161 {
162 using TimeCode = Secs;
163 };
164
165
166
167 /* == Descriptor to define Support for specific formats == */
168
169 using lib::meta::Types;
170 using lib::meta::Node;
171 using lib::meta::Nil;
172
188 {
189 enum { MAXID = 8 };
190
191 std::bitset<MAXID> flags_;
192
193 template<class F>
194 IxID
195 typeID() const
196 {
198 }
199
200 template<class F, class FS>
203 {
204 flags_.set (typeID<F>());
205 return define(FS());
206 }
207 Supported define(Nil) { return *this;}
208
210
211
212 public:
216 template<typename TY>
217 static Supported
219 {
220 using SupportedFormats = TY::List;
221 return Supported().define(SupportedFormats());
222 }
223
225 template<class F>
226 bool
227 check() const
228 {
229 return flags_[typeID<F>()];
230 }
231 };
232
244
245
246}}} // lib::time::format
247#endif
Provide type-IDs for a specific context.
A frame counting timecode value.
Definition timecode.hpp:99
Facility to create grid-aligned time values.
Definition quantiser.hpp:95
Classical Timecode value reminiscent to SMPTE format.
Definition timecode.hpp:147
basic constant internal time value.
Descriptor to denote support for a specific (timecode) format.
Definition formats.hpp:188
std::bitset< MAXID > flags_
Definition formats.hpp:191
static Supported formats()
build a new Descriptor to denote support for all the Formats,
Definition formats.hpp:218
bool check() const
check if a specific Format is supported
Definition formats.hpp:227
Supported define(Node< F, FS >)
Definition formats.hpp:202
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition error.h:62
Helpers for working with lib::meta::Types (i.e.
unsigned int uint
Definition integral.hpp:29
»Empty« mark
Definition typelist.hpp:82
Type list with head and tail; T ≡ Nil marks list end.
Definition typelist.hpp:90
variadic sequence of types
Definition typelist.hpp:102
Quantiser const & QuantR
Definition formats.hpp:57
std::shared_ptr< const Quantiser > PQuant
Definition formats.hpp:58
Implementation namespace for support and library code.
size_t IxID
Lumiera public interface.
Definition advice.hpp:102
Metaprogramming helper to prevent an entity to be ever instantiated at runtime.
An Entity never to be instantiated.
Frame count as timecode format.
Definition formats.hpp:77
static void rebuild(FrameNr &, QuantR, TimeValue const &)
build up a frame count by quantising the given time value
Definition timecode.cpp:150
static TimeValue evaluate(FrameNr const &, QuantR)
calculate the time point denoted by this frame count
Definition timecode.cpp:157
static TimeValue parse(string const &, QuantR)
try to parse a frame number specification
Definition timecode.cpp:64
The informal hours-minutes-seconds-millisecond timecode.
Definition formats.hpp:110
static TimeValue evaluate(HmsTC const &, QuantR)
static void rebuild(HmsTC &, QuantR, TimeValue const &)
static TimeValue parse(string const &, QuantR)
Definition timecode.cpp:84
Simple timecode specification as fractional seconds.
Definition formats.hpp:128
static void rebuild(Secs &, QuantR, TimeValue const &)
static TimeValue evaluate(Secs const &, QuantR)
static TimeValue parse(string const &, QuantR)
try to parse a time specification in seconds or fractional seconds.
Definition timecode.cpp:112
Widely used standard media timecode format.
Definition formats.hpp:92
static TimeValue evaluate(SmpteTC const &, QuantR)
calculate the time point denoted by this SMPTE timecode, by summing up the timecode's components
Definition timecode.cpp:178
static void applyRangeLimitStrategy(SmpteTC &)
handle the limits of SMPTE timecode range.
Definition timecode.cpp:232
static uint getFramerate(QuantR, TimeValue const &)
yield the Framerate in effect at that point.
Definition timecode.cpp:202
static void rebuild(SmpteTC &, QuantR, TimeValue const &)
build up a SMPTE timecode by quantising the given time value and then splitting it into hours,...
Definition timecode.cpp:168
static TimeValue parse(string const &, QuantR)
Definition timecode.cpp:77
predefined standard configuration: Descriptor for supporting all the classical timecode formats
Definition formats.hpp:239
a family of time value like entities and their relationships.
Creating series of type-based contexts.
A template metaprogramming technique for manipulating collections of types.