From 15a3694cca9fe09b3a52cf487a9dc05d90c8801c Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 11 Jun 2011 20:20:20 +0200 Subject: [PATCH] more complete unit test pass --- src/lib/time/control.hpp | 35 ++++++++++++++++++---------- src/lib/time/lumitime.cpp | 13 ++++++++--- src/lib/time/timevalue.hpp | 13 +++++++---- tests/lib/time/time-control-test.cpp | 13 ++++------- tests/lib/time/time-value-test.cpp | 9 ++++++- 5 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/lib/time/control.hpp b/src/lib/time/control.hpp index 01f5295cc..48af1813c 100644 --- a/src/lib/time/control.hpp +++ b/src/lib/time/control.hpp @@ -321,8 +321,19 @@ namespace time { // special treatment of Durations as target... + namespace { + template + struct canMutateDuration + { + static const bool value = is_sameType::value + || is_sameType::value + || is_sameType::value; + }; + } + template - struct Policy + struct Policy, + Duration>::type> { static function buildChangeHandler (Duration& target) @@ -331,15 +342,15 @@ namespace time { } }; - template - struct Policy - { - static function - buildChangeHandler (Duration& target) - { - return bind (Adap::template processValueChange, ref(target), _1 ); - } - }; +// template +// struct Policy +// { +// static function +// buildChangeHandler (Duration& target) +// { +// return bind (Adap::template processValueChange, ref(target), _1 ); +// } +// }; template struct Policy @@ -573,9 +584,9 @@ namespace time { void Mutator::bind_to (TAR& target) const { - setVal_ = Policy ::buildChangeHandler (target); + setVal_ = Policy::buildChangeHandler (target); offset_ = Policy::buildChangeHandler (target); - nudge_ = Policy ::buildChangeHandler (target); + nudge_ = Policy::buildChangeHandler (target); } template diff --git a/src/lib/time/lumitime.cpp b/src/lib/time/lumitime.cpp index 978e8190f..f80dc9c6e 100644 --- a/src/lib/time/lumitime.cpp +++ b/src/lib/time/lumitime.cpp @@ -119,9 +119,16 @@ namespace time { } - /** duration of the given number of frames */ - Duration::Duration (ulong count, FrameRate const& fps) - : TimeValue (count? lumiera_frame_duration (fps/count) : _raw(Duration::NIL)) + /** offset by the given number of frames. */ + Offset::Offset (int64_t count, FrameRate const& fps) + : TimeValue (count? (count<0? -1:+1) * lumiera_framecount_to_time (::abs(count), fps) + : _raw(Duration::NIL)) + { } + + /** duration of the given number of frames. + * @note always positive; count used absolute */ + Duration::Duration (int64_t count, FrameRate const& fps) + : TimeValue (count? lumiera_framecount_to_time (abs(count), fps) : _raw(Duration::NIL)) { } diff --git a/src/lib/time/timevalue.hpp b/src/lib/time/timevalue.hpp index 5535beed1..0c8fb2e15 100644 --- a/src/lib/time/timevalue.hpp +++ b/src/lib/time/timevalue.hpp @@ -42,6 +42,11 @@ namespace time { namespace error = lumiera::error; + // forwards... + class FrameRate; + class TimeSpan; + class Mutation; + /** * basic constant internal time value. @@ -193,8 +198,11 @@ namespace time { : TimeValue(TimeVar(target) -= origin) { } + Offset (int64_t count, FrameRate const& fps); + static const Offset ZERO; + TimeValue abs() const { @@ -243,7 +251,6 @@ namespace time { * @warning do not mix up gavl_time_t and FSecs */ typedef boost::rational FSecs; - class FrameRate; /** * Lumiera's internal time value datatype. @@ -306,8 +313,6 @@ namespace time { - class TimeSpan; - class Mutation; /** * Duration is the internal Lumiera time metric. @@ -338,7 +343,7 @@ namespace time { { } Duration (TimeSpan const& interval); - Duration (ulong count, FrameRate const& fps); + Duration (int64_t count, FrameRate const& fps); static const Duration NIL; diff --git a/tests/lib/time/time-control-test.cpp b/tests/lib/time/time-control-test.cpp index 6787e995c..db1fa6d83 100644 --- a/tests/lib/time/time-control-test.cpp +++ b/tests/lib/time/time-control-test.cpp @@ -140,14 +140,11 @@ namespace test{ CHECK (c!=Time::ZERO && o != c, "unsuitable testdata"); // 25fps-grid, but with an time origin offset by 1/50sec - TimeGrid::build("test_grid", FrameRate::PAL, Time(FSecs(1,50))); + TimeGrid::build("test_grid_PAL", FrameRate::PAL, Time(FSecs(1,50))); // disjoint NTSC-framerate grid for grid aligned changes TimeGrid::build("test_grid_NTSC", FrameRate::NTSC); - QuTime qChange (c, "test_grid"); - FrameNr count(qChange); - verifyBasics(); verifyMatrix_of_MutationCases(o,c); } @@ -210,7 +207,7 @@ namespace test{ static QuTime build (TimeValue const& org) { - return QuTime (org, "test_grid"); + return QuTime (org, "test_grid_PAL"); } }; @@ -303,17 +300,17 @@ namespace test{ void ____verify_nudged (TAR const& target, TAR const& refState, int64_t offsetSteps) { - CHECK (target != refState); + CHECK (target != refState || !offsetSteps); CHECK (target == Time(refState)+Time(FSecs(offsetSteps))); } template<> void ____verify_nudged (QuTime const& target, QuTime const& refState, int64_t offsetSteps) { - CHECK (target != refState); + CHECK (target != refState || !offsetSteps); PQuant quantiser(target); CHECK (target == Time(quantiser->materialise(refState)) - + offsetSteps * FrameRate::NTSC.duration()); + + Offset(offsetSteps, FrameRate::PAL)); } diff --git a/tests/lib/time/time-value-test.cpp b/tests/lib/time/time-value-test.cpp index e2316f240..27656bd44 100644 --- a/tests/lib/time/time-value-test.cpp +++ b/tests/lib/time/time-value-test.cpp @@ -233,7 +233,14 @@ namespace test{ CHECK (9 == off9); // simple linear combinations CHECK (7 == -2*off9 + off5*5); - } + + // build offset by number of frames + Offset byFrames(-125, FrameRate::PAL); + CHECK (Time(FSecs(-5)) == byFrames); + + CHECK (Offset(-5, FrameRate(5,4)) == -Offset(5, FrameRate(5,4))); + CHECK (Offset(3, FrameRate(3)) == Offset(12345, FrameRate(24690,2))); + } // precise rational number calculations void