Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
time-quantisation-test.cpp
Go to the documentation of this file.
1/*
2 TimeQuantisation(Test) - handling of virtually grid aligned time values
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
20#include "lib/test/run.hpp"
24#include "lib/format-cout.hpp"
25#include "lib/util.hpp"
26
27#include <boost/lexical_cast.hpp>
28
29using boost::lexical_cast;
30using util::isnil;
31using util::contains;
32
33
34namespace lib {
35namespace time{
36namespace test{
37
39
40
41 /****************************************************/
50 class TimeQuantisation_test : public Test
51 {
52 int
53 random_or_get (Arg arg)
54 {
55 if (isnil(arg))
56 {// use random time value for all tests
57 seedRand();
58 return 1 + rani(100'000);
59 }
60 else // use argument as 1/10 seconds
61 return 10 * lexical_cast<int> (arg[1]);
62 }
63
64
65
70 virtual void
71 run (Arg arg)
72 {
73 Time ref (random_or_get(arg),0,0,0);
74 CHECK (TimeValue(0) < ref);
75
76 checkSimpleUsage (ref);
79 checkGridBinding (ref);
80 }
81
82
83 void
85 {
86 TimeGrid::build("my_simple_grid", 25); // "someone" has defined a time grid
87
88 QuTime qVal (org, "my_simple_grid"); // create time quantised to this grid
89
90 FrameNr count(qVal); // materialise this quantised time into..
91 int n = count; // frame count, accessible as plain number
92
93 CHECK (Time(FSecs(n, 25)) <= org); // verify quantisation: the original time
94 CHECK (org < Time(FSecs(n+1, 25))); // is properly bracketed by [n, n+1[
95 }
96
97
98 void
100 {
101 cout << "TEST rawTime:"<<Time{org} << endl;
102 PQuant fixQ (new FixedFrameQuantiser(25));
103 QuTime qVal (org, fixQ);
104
105 CHECK ( qVal == org); // Note: stores the raw value, but tagged with a grid
106 CHECK ( fixQ.get() == PQuant(qVal).get());
107 CHECK ( qVal.supports<format::Frames>());
108 CHECK ( qVal.supports<format::Smpte>());
109
110 SmpteTC smpteTCode = qVal.formatAs<format::Smpte>();
111 showTimeCode (smpteTCode);
112
113 HmsTC pureTimeCode = qVal.formatAs<format::Hms>();
114 showTimeCode (pureTimeCode);
115
116 FrameNr frameTCode = qVal.formatAs<format::Frames>();
117 showTimeCode (frameTCode);
118
119 Secs seconds = qVal.formatAs<format::Seconds>();
120 showTimeCode (seconds);
121 }
122
123 template<class TC>
124 void
125 showTimeCode (TC timecodeValue)
126 {
127 cout << timecodeValue.describe()
128 << " time = "<< timecodeValue.getTime()
129 << " code = "<< timecodeValue
130 << endl;
131 }
132
133
134 void
136 {
137 TimeGrid::build("my_alternate_grid", FrameRate::NTSC);
138
139 QuTime palVal (org, "my_simple_grid");
140 QuTime ntscVal (org, "my_alternate_grid");
141
142 CHECK (org == palVal);
143 CHECK (org == ntscVal);
144
145 FrameNr palNr (palVal);
146 FrameNr ntscNr(ntscVal);
147 CHECK (palNr <= ntscNr);
148 }
149
150
151 void
153 {
154 // refer to a grid not yet defined
155 VERIFY_ERROR (UNKNOWN_GRID, QuTime weird(org, "special_funny_grid"));
156
157 TimeGrid::build("special_funny_grid", 1); // provide the grid's definition (1 frame per second)
158
159 QuTime funny (org, "special_funny_grid"); // now OK, grid is known
160 int cnt = funny.formatAs<format::Frames>();
161 // and now performing quantisation is OK
162 SmpteTC smpte (funny); // also converting into SMPTE (which implies frame quantisation)
163 CHECK (0 == smpte.frames); // we have 1fps, thus the frame part is always zero!
164 CHECK (cnt % 60 == smpte.secs); // and the seconds part will be in sync with the frame count
165 }
166 };
167
168
171
172
173
174}}} // namespace lib::time::test
Simple stand-alone Quantiser implementation based on a constant sized gird.
A frame counting timecode value.
Definition timecode.hpp:99
static const FrameRate NTSC
grid aligned time specification, referring to a specific scale.
Definition timequant.hpp:91
bool supports() const
does our implicit time grid support building that timecode format?
format::Traits< FMT >::TimeCode formatAs() const
create new time code instance, then castInto
Classical Timecode value reminiscent to SMPTE format.
Definition timecode.hpp:147
basic constant internal time value.
Lumiera's internal time value datatype.
Interface: a grid and scale definition for time quantisation.
Definition time-grid.hpp:80
static PGrid build(FrameRate frames_per_second)
Automatically use custom string conversion in C++ stream output.
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.
int rani(uint bound=_iBOUND())
Definition random.hpp:135
Test runner and basic definitions for tests.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Frame count as timecode format.
Definition formats.hpp:77
The informal hours-minutes-seconds-millisecond timecode.
Definition formats.hpp:110
Simple timecode specification as fractional seconds.
Definition formats.hpp:128
Widely used standard media timecode format.
Definition formats.hpp:92
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
To establish a reference scale for quantised time values.
Support library to represent grid-aligned time specifications This is part of Lumiera's time and time...
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...