Lumiera  0.pre.03
»edit your freedom«
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 namespace lumiera {
48 namespace error {
49  LUMIERA_ERROR_DECLARE (INVALID_TIMECODE);
50 }}
51 
52 
53 namespace lib {
54 namespace time {
55 
56 
57  // ====== forward declarations of concrete Timecode types
58 
59  class FrameNr;
60  class SmpteTC;
61  class HmsTC;
62  class Secs;
63 
64 
65  class Quantiser; // API for grid aligning
66  using QuantR = Quantiser const&;
67  using PQuant = std::shared_ptr<const Quantiser>;
68 
69 
70  namespace format {
71 
72  using std::string;
73  using lib::meta::NoInstance; // the following types are for metaprogramming only...
74 
75 
84  struct Frames
85  : NoInstance<Frames>
86  {
87  static TimeValue parse (string const&, QuantR);
88  static void rebuild (FrameNr&, QuantR, TimeValue const&);
89  static TimeValue evaluate (FrameNr const&, QuantR);
90  };
91 
92 
99  struct Smpte
100  : NoInstance<Smpte>
101  {
102  static TimeValue parse (string const&, QuantR);
103  static void rebuild (SmpteTC&, QuantR, TimeValue const&);
104  static TimeValue evaluate (SmpteTC const&, QuantR);
105  static uint getFramerate (QuantR, TimeValue const&);
106  static void applyRangeLimitStrategy (SmpteTC&);
107  };
108 
109 
117  struct Hms
118  : NoInstance<Hms>
119  {
120  static TimeValue parse (string const&, QuantR);
121  static void rebuild (HmsTC&, QuantR, TimeValue const&);
122  static TimeValue evaluate (HmsTC const&, QuantR);
123  };
124 
125 
135  struct Seconds
136  : NoInstance<Seconds>
137  {
138  static TimeValue parse (string const&, QuantR);
139  static void rebuild (Secs&, QuantR, TimeValue const&);
140  static TimeValue evaluate (Secs const&, QuantR);
141  };
142 
143 
144 
145 
146 
147  template<class FMT>
148  struct Traits;
149 
150  template<>
151  struct Traits<Frames>
152  {
153  using TimeCode = FrameNr;
154  };
155 
156  template<>
157  struct Traits<Smpte>
158  {
159  using TimeCode = SmpteTC;
160  };
161 
162  template<>
163  struct Traits<Hms>
164  {
165  using TimeCode = HmsTC;
166  };
167 
168  template<>
169  struct Traits<Seconds>
170  {
171  using TimeCode = Secs;
172  };
173 
174 
175 
176  /* == Descriptor to define Support for specific formats == */
177 
178  using lib::meta::Types;
179  using lib::meta::Node;
180  using lib::meta::NullType;
181 
196  class Supported
197  {
198  enum { MAXID = 8 };
199 
200  std::bitset<MAXID> flags_;
201 
202  template<class F>
203  IxID
204  typeID() const
205  {
207  }
208 
209  template<class F, class FS>
210  Supported
211  define(Node<F,FS>)
212  {
213  flags_.set (typeID<F>());
214  return define(FS());
215  }
216  Supported define(NullType) { return *this;}
217 
218  Supported() { }
219 
220 
221  public:
225  template<typename TY>
226  static Supported
228  {
229  typedef typename TY::List SupportedFormats;
230  return Supported().define(SupportedFormats());
231  }
232 
234  template<class F>
235  bool
236  check() const
237  {
238  return flags_[typeID<F>()];
239  }
240  };
241 
247  : Supported
248  {
251  { }
252  };
253 
254 
255 }}} // lib::time::format
256 #endif
Frame count as timecode format.
Definition: formats.hpp:84
Creating series of type-based contexts.
Classical Timecode value reminiscent to SMPTE format.
Definition: timecode.hpp:150
A template metaprogramming technique for manipulating collections of types.
The informal hours-minutes-seconds-millisecond timecode.
Definition: formats.hpp:117
bool check() const
check if a specific Format is supported
Definition: formats.hpp:236
Widely used standard media timecode format.
Definition: formats.hpp:99
Helpers for working with lib::meta::Types (i.e.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:71
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:196
predefined standard configuration: Descriptor for supporting all the classical timecode formats ...
Definition: formats.hpp:246
Simple timecode specification as fractional seconds.
Definition: formats.hpp:135
Supported define(NullType)
Definition: formats.hpp:216
An Entity never to be instantiated.
Definition: no-instance.hpp:56
Lumiera public interface.
Definition: advice.cpp:113
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:227
basic constant internal time value.
Definition: timevalue.hpp:142