Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
formats.hpp
Go to the documentation of this file.
1 /*
2  FORMATS.hpp - formats for displaying and specifying time
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 
34 #ifndef LIB_TIME_FORMATS_H
35 #define LIB_TIME_FORMATS_H
36 
37 #include "lib/time/timevalue.hpp"
38 #include "lib/meta/no-instance.hpp"
39 #include "lib/meta/typelist.hpp"
40 #include "lib/meta/generator.hpp"
41 #include "lib/typed-counter.hpp"
42 
43 #include <memory>
44 #include <string>
45 #include <bitset>
46 
47 
48 namespace lib {
49 namespace time {
50 
51 
52  // ====== forward declarations of concrete Timecode types
53 
54  class FrameNr;
55  class SmpteTC;
56  class HmsTC;
57  class Secs;
58 
59 
60  class Quantiser; // API for grid aligning
61  typedef Quantiser const& QuantR;
63 
64 
65  namespace format {
66 
67  LUMIERA_ERROR_DECLARE (INVALID_TIMECODE);
68 
69  using std::string;
70  using lib::meta::NoInstance; // the following types are for metaprogramming only...
71 
72 
81  struct Frames
82  : NoInstance<Frames>
83  {
84  static TimeValue parse (string const&, QuantR);
85  static void rebuild (FrameNr&, QuantR, TimeValue const&);
86  static TimeValue evaluate (FrameNr const&, QuantR);
87  };
88 
89 
96  struct Smpte
97  : NoInstance<Smpte>
98  {
99  static TimeValue parse (string const&, QuantR);
100  static void rebuild (SmpteTC&, QuantR, TimeValue const&);
101  static TimeValue evaluate (SmpteTC const&, QuantR);
102  static uint getFramerate (QuantR, TimeValue const&);
103  static void applyRangeLimitStrategy (SmpteTC&);
104  };
105 
106 
114  struct Hms
115  : NoInstance<Hms>
116  {
117  static TimeValue parse (string const&, QuantR);
118  static void rebuild (HmsTC&, QuantR, TimeValue const&);
119  static TimeValue evaluate (HmsTC const&, QuantR);
120  };
121 
122 
132  struct Seconds
133  : NoInstance<Seconds>
134  {
135  static TimeValue parse (string const&, QuantR);
136  static void rebuild (Secs&, QuantR, TimeValue const&);
137  static TimeValue evaluate (Secs const&, QuantR);
138  };
139 
140 
141 
142 
143 
144  template<class FMT>
145  struct Traits;
146 
147  template<>
148  struct Traits<Frames>
149  {
150  typedef FrameNr TimeCode;
151  };
152 
153  template<>
154  struct Traits<Smpte>
155  {
156  typedef SmpteTC TimeCode;
157  };
158 
159  template<>
160  struct Traits<Hms>
161  {
162  typedef HmsTC TimeCode;
163  };
164 
165  template<>
166  struct Traits<Seconds>
167  {
168  typedef Secs TimeCode;
169  };
170 
171 
172 
173  /* == Descriptor to define Support for specific formats == */
174 
175  using lib::meta::Types;
176  using lib::meta::Node;
177  using lib::meta::NullType;
178 
193  class Supported
194  {
195  enum { MAXID = 8 };
196 
197  std::bitset<MAXID> flags_;
198 
199  template<class F>
200  IxID
201  typeID() const
202  {
204  }
205 
206  template<class F, class FS>
207  Supported
209  {
210  flags_.set (typeID<F>());
211  return define(FS());
212  }
213  Supported define(NullType) { return *this;}
214 
215  Supported() { }
216 
217 
218  public:
222  template<typename TY>
223  static Supported
225  {
226  typedef typename TY::List SupportedFormats;
227  return Supported().define(SupportedFormats());
228  }
229 
231  template<class F>
232  bool
233  check() const
234  {
235  return flags_[typeID<F>()];
236  }
237  };
238 
244  : Supported
245  {
248  { }
249  };
250 
251 
252 }}} // lib::time::format
253 #endif
static TimeValue parse(string const &, QuantR)
try to parse a frame number specification
Definition: timecode.cpp:72
static TimeValue evaluate(HmsTC const &, QuantR)
Frame count as timecode format.
Definition: formats.hpp:81
static TimeValue evaluate(FrameNr const &, QuantR)
calculate the time point denoted by this frame count
Definition: timecode.cpp:165
static TimeValue evaluate(Secs const &, QuantR)
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:186
Creating series of type-based contexts.
size_t IxID
Classical Timecode value reminiscent to SMPTE format.
Definition: timecode.hpp:150
Quantiser const & QuantR
Definition: formats.hpp:60
A template metaprogramming technique for manipulating collections of types.
static TimeValue parse(string const &, QuantR)
Definition: timecode.cpp:85
Facility to create grid-aligned time values.
Definition: quantiser.hpp:102
static uint getFramerate(QuantR, TimeValue const &)
yield the Framerate in effect at that point.
Definition: timecode.cpp:210
The informal hours-minutes-seconds-millisecond timecode.
Definition: formats.hpp:114
static void applyRangeLimitStrategy(SmpteTC &)
handle the limits of SMPTE timecode range.
Definition: timecode.cpp:240
static TimeValue parse(string const &, QuantR)
Definition: timecode.cpp:92
Widely used standard media timecode format.
Definition: formats.hpp:96
LinkedElements< Nummy > List
default case: ownership for heap allocated nodes
Helpers for working with lib::meta::Types (i.e.
static void rebuild(Secs &, QuantR, TimeValue const &)
Implementation namespace for support and library code.
Metaprogramming helper to prevent an entity to be ever instantiated at runtime.
Descriptor to denote support for a specific (timecode) format.
Definition: formats.hpp:193
static TimeValue parse(string const &, QuantR)
try to parse a time specification in seconds or fractional seconds.
Definition: timecode.cpp:120
predefined standard configuration: Descriptor for supporting all the classical timecode formats ...
Definition: formats.hpp:243
Supported define(Node< F, FS >)
Definition: formats.hpp:208
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:176
Simple timecode specification as fractional seconds.
Definition: formats.hpp:132
Supported define(NullType)
Definition: formats.hpp:213
static void rebuild(FrameNr &, QuantR, TimeValue const &)
build up a frame count by quantising the given time value
Definition: timecode.cpp:158
An Entity never to be instantiated.
Definition: no-instance.hpp:58
std::shared_ptr< const Quantiser > PQuant
Definition: formats.hpp:62
bool check() const
check if a specific Format is supported
Definition: formats.hpp:233
A frame counting timecode value.
Definition: timecode.hpp:105
Provide type-IDs for a specific context.
a family of time value like entities and their relationships.
static Supported formats()
build a new Descriptor to denote support for all the Formats,
Definition: formats.hpp:224
basic constant internal time value.
Definition: timevalue.hpp:80
std::bitset< MAXID > flags_
Definition: formats.hpp:197
static void rebuild(HmsTC &, QuantR, TimeValue const &)
LUMIERA_ERROR_DECLARE(INVALID_TIMECODE)
timecode format error, illegal value encountered.