13
0

Fix compilation of evoral unit-test

Some of these tests should be moved to libtemoral.
On 64bit Linux the tests pass, except various RangeTests.
This commit is contained in:
Robin Gareus 2022-09-30 04:04:48 +02:00
parent 9a34d15b3c
commit d70ebde1dc
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
10 changed files with 302 additions and 210 deletions

View File

@ -23,14 +23,15 @@ CPPUNIT_TEST_SUITE_REGISTRATION (CurveTest);
#endif #endif
using namespace Evoral; using namespace Evoral;
using namespace Temporal;
// linear y = Y0 + YS * x ; with x = i * (X1 - X0) + X0; and i = [0..1023] // linear y = Y0 + YS * x ; with x = i * (X1 - X0) + X0; and i = [0..1023]
#define VEC1024LINCMP(X0, X1, Y0, YS) \ #define VEC1024LINCMP(X0, X1, Y0, YS) \
cl->curve ().get_vector ((X0), (X1), vec, 1024); \ cl->curve ().get_vector ((X0), (X1), vec, 1024); \
for (int i = 0; i < 1024; ++i) { \ for (int i = 0; i < 1024; ++i) { \
char msg[64]; \ char msg[64]; \
snprintf (msg, 64, "at i=%d (x0=%.1f, x1=%.1f, y0=%.1f, ys=%.3f)", \ snprintf (msg, 64, "at i=%d (x0=%s, x1=%s, y0=%.1f, ys=%.3f)", \
i, X0, X1, Y0, YS); \ i, (X0).str().c_str(), (X1).str().c_str(), Y0, YS); \
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE ( \ CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE ( \
msg, \ msg, \
(Y0) + i * (YS), vec[i], \ (Y0) + i * (YS), vec[i], \
@ -47,15 +48,18 @@ CurveTest::trivial ()
cl->create_curve (); cl->create_curve ();
timepos_t t1024 (1024.0);
timepos_t t2047 (2047.0);
// Empty curve // Empty curve
cl->curve().get_vector (1024.0, 2047.0, vec, 1024); cl->curve().get_vector (t1024, t2047, vec, 1024);
for (int i = 0; i < 1024; ++i) { for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (0.0f, vec[i]); CPPUNIT_ASSERT_EQUAL (0.0f, vec[i]);
} }
// Single point curve // Single point curve
cl->fast_simple_add(0.0, 42.0); cl->fast_simple_add(timepos_t (0), 42.0);
cl->curve().get_vector (1024.0, 2047.0, vec, 1024); cl->curve().get_vector (t1024, t2047, vec, 1024);
for (int i = 0; i < 1024; ++i) { for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (42.0f, vec[i]); CPPUNIT_ASSERT_EQUAL (42.0f, vec[i]);
} }
@ -66,21 +70,24 @@ CurveTest::rtGet ()
{ {
float vec[1024]; float vec[1024];
timepos_t t1024 (1024.0);
timepos_t t2047 (2047.0);
// Create simple control list // Create simple control list
boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList(); boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList();
cl->create_curve (); cl->create_curve ();
cl->fast_simple_add(0.0, 42.0); cl->fast_simple_add(timepos_t(0), 42.0);
{ {
// Write-lock list // Write-lock list
Glib::Threads::RWLock::WriterLock lm(cl->lock()); Glib::Threads::RWLock::WriterLock lm(cl->lock());
// Attempt to get vector in RT (expect failure) // Attempt to get vector in RT (expect failure)
CPPUNIT_ASSERT (!cl->curve().rt_safe_get_vector (1024.0, 2047.0, vec, 1024)); CPPUNIT_ASSERT (!cl->curve().rt_safe_get_vector (t1024, t2047, vec, 1024));
} }
// Attempt to get vector in RT (expect success) // Attempt to get vector in RT (expect success)
CPPUNIT_ASSERT (cl->curve().rt_safe_get_vector (1024.0, 2047.0, vec, 1024)); CPPUNIT_ASSERT (cl->curve().rt_safe_get_vector (t1024, t2047, vec, 1024));
for (int i = 0; i < 1024; ++i) { for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (42.0f, vec[i]); CPPUNIT_ASSERT_EQUAL (42.0f, vec[i]);
} }
@ -96,46 +103,55 @@ CurveTest::twoPointLinear ()
cl->create_curve (); cl->create_curve ();
cl->set_interpolation (ControlList::Linear); cl->set_interpolation (ControlList::Linear);
timepos_t t0 (0);
timepos_t t1024 (1024);
timepos_t t2048 (2048);
timepos_t t2047 (2047);
timepos_t t2049 (2049);
timepos_t t2056 (2056);
timepos_t t4092 (4092);
timepos_t t8192 (8192);
// add two points to curve // add two points to curve
cl->fast_simple_add ( 0.0 , 2048.0); cl->fast_simple_add (t0 , 2048.0);
cl->fast_simple_add (8192.0 , 4096.0); cl->fast_simple_add (t8192, 4096.0);
cl->curve ().get_vector (1024.0, 2047.0, vec, 1024); cl->curve ().get_vector (t1024, t2047, vec, 1024);
VEC1024LINCMP (1024.0, 2047.0, 2304.f, .25f); VEC1024LINCMP (t1024, t2047, 2304.f, .25f);
VEC1024LINCMP (2048.0, 2559.5, 2560.f, .125f); //VEC1024LINCMP (t2048, timepos_t (2559.5), 2560.f, .125f);
VEC1024LINCMP ( 0.0, 4092.0, 2048.f, 1.f); VEC1024LINCMP (t0, t4092, 2048.f, 1.f);
// greetings to tartina // greetings to tartina
cl->curve ().get_vector (2048.0, 2048.0, vec, 1); cl->curve ().get_vector (t2048, t2048, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048..2048", 2560.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048..2048", 2560.f, vec[0]);
/* XXX WHAT DO WE EXPECT WITH veclen=1 AND x1 > x0 ? */ /* XXX WHAT DO WE EXPECT WITH veclen=1 AND x1 > x0 ? */
#if 0 #if 0
/* .. interpolated value at (x1+x0)/2 */ /* .. interpolated value at (x1+x0)/2 */
cl->curve ().get_vector (2048.0, 2049.0, vec, 1); cl->curve ().get_vector (2048.0, t2049, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048-2049", 2560.125f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048-2049", 2560.125f, vec[0]);
cl->curve ().get_vector (2048.0, 2056.0, vec, 1); cl->curve ().get_vector (2048.0, 2056.0, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048-2049", 2561.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048-2049", 2561.f, vec[0]);
#else #else
/* .. value at x0 */ /* .. value at x0 */
cl->curve ().get_vector (2048.0, 2049.0, vec, 1); cl->curve ().get_vector (t2048, t2049, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 , 2048..2049", 2560.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 , 2048..2049", 2560.f, vec[0]);
cl->curve ().get_vector (2048.0, 2056.0, vec, 1); cl->curve ().get_vector (t2048, t2056, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 , 2048..2049", 2560.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 , 2048..2049", 2560.f, vec[0]);
#endif #endif
cl->curve ().get_vector (2048.0, 2048.0, vec, 2); cl->curve ().get_vector (t2048, t2048, vec, 2);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2048 @ 0", 2560.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2048 @ 0", 2560.f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2048 @ 1", 2560.f, vec[1]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2048 @ 1", 2560.f, vec[1]);
cl->curve ().get_vector (2048.0, 2056.0, vec, 2); cl->curve ().get_vector (t2048, t2056, vec, 2);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2056 @ 0", 2560.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2056 @ 0", 2560.f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2056 @ 0", 2562.f, vec[1]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2056 @ 0", 2562.f, vec[1]);
cl->curve ().get_vector (2048.0, 2056.0, vec, 3); cl->curve ().get_vector (t2048, t2056, vec, 3);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 0", 2560.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 0", 2560.f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 1", 2561.f, vec[1]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 1", 2561.f, vec[1]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 2", 2562.f, vec[2]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 2", 2562.f, vec[2]);
@ -143,18 +159,22 @@ CurveTest::twoPointLinear ()
/* check out-of range.. /* check out-of range..
* we expect the first and last value - no interpolation * we expect the first and last value - no interpolation
*/ */
cl->curve ().get_vector (-1, -1, vec, 1); timepos_t tm1 (-1);
timepos_t tm999 (-999);
timepos_t t9998 (9998);
timepos_t t9999 (9999);
cl->curve ().get_vector (tm1, tm1, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ -1", 2048.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ -1", 2048.f, vec[0]);
cl->curve ().get_vector (9999.0, 9999.0, vec, 1); cl->curve ().get_vector (t9999, t9999, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 9999", 4096.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 9999", 4096.f, vec[0]);
cl->curve ().get_vector (-999.0, 0, vec, 13); cl->curve ().get_vector (tm999, t0, vec, 13);
for (int i = 0; i < 13; ++i) { for (int i = 0; i < 13; ++i) {
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=13 @ -999..0", 2048.f, vec[i]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=13 @ -999..0", 2048.f, vec[i]);
} }
cl->curve ().get_vector (t9998, t9999, vec, 8);
cl->curve ().get_vector (9998.0, 9999.0, vec, 8);
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=8 @ 9998..9999", 4096.f, vec[i]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=8 @ 9998..9999", 4096.f, vec[i]);
} }
@ -170,26 +190,36 @@ CurveTest::threePointLinear ()
cl->create_curve (); cl->create_curve ();
cl->set_interpolation (ControlList::Linear); cl->set_interpolation (ControlList::Linear);
// add 3 points to curve timepos_t t0 (0);
cl->fast_simple_add ( 0.0 , 2.0); timepos_t t50 (50);
cl->fast_simple_add ( 100.0 , 4.0); timepos_t t60 (60);
cl->fast_simple_add ( 200.0 , 0.0); timepos_t t80 (80);
timepos_t t100 (100);
timepos_t t130 (130);
timepos_t t150 (150);
timepos_t t160 (160);
timepos_t t200 (200);
cl->curve ().get_vector (50.0, 60.0, vec, 1); // add 3 points to curve
cl->fast_simple_add ( t0 , 2.0);
cl->fast_simple_add (t100 , 4.0);
cl->fast_simple_add (t200 , 0.0);
cl->curve ().get_vector (t50, t60, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 50", 3.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 50", 3.f, vec[0]);
cl->curve ().get_vector (100.0, 100.0, vec, 1); cl->curve ().get_vector (t100, t100, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 100", 4.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 100", 4.f, vec[0]);
cl->curve ().get_vector (150.0, 150.0, vec, 1); cl->curve ().get_vector (t150, t150, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 150", 2.f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 150", 2.f, vec[0]);
cl->curve ().get_vector (130.0, 150.0, vec, 3); cl->curve ().get_vector (t130, t150, vec, 3);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 0", 2.8f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 0", 2.8f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 2", 2.4f, vec[1]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 2", 2.4f, vec[1]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 3", 2.0f, vec[2]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 3", 2.0f, vec[2]);
cl->curve ().get_vector (80.0, 160.0, vec, 3); cl->curve ().get_vector (t80, t160, vec, 3);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 0", 3.6f, vec[0]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 0", 3.6f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 2", 3.2f, vec[1]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 2", 3.2f, vec[1]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 3", 1.6f, vec[2]); CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 3", 1.6f, vec[2]);
@ -201,20 +231,27 @@ CurveTest::threePointDiscete ()
boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList(); boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList();
cl->set_interpolation (ControlList::Discrete); cl->set_interpolation (ControlList::Discrete);
// add 3 points to curve timepos_t t0 (0);
cl->fast_simple_add ( 0.0 , 2.0); timepos_t t80 (80);
cl->fast_simple_add ( 100.0 , 4.0); timepos_t t100 (100);
cl->fast_simple_add ( 200.0 , 0.0); timepos_t t120 (120);
timepos_t t160 (160);
timepos_t t200 (200);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.)); // add 3 points to curve
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.)); cl->fast_simple_add ( t0 , 2.0);
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.)); cl->fast_simple_add (t100 , 4.0);
cl->fast_simple_add (t200 , 0.0);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
cl->set_interpolation (ControlList::Linear); cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(t160));
} }
void void
@ -222,75 +259,87 @@ CurveTest::ctrlListEval ()
{ {
boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList(); boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList();
cl->fast_simple_add ( 0.0 , 2.0); timepos_t t0 (0);
timepos_t t80 (80);
timepos_t t100 (100);
timepos_t t120 (120);
timepos_t t160 (160);
timepos_t t200 (200);
timepos_t t250 (250);
timepos_t t300 (300);
timepos_t t350 (350);
timepos_t t400 (400);
timepos_t t999 (999);
cl->fast_simple_add (t0 , 2.0);
cl->set_interpolation (ControlList::Discrete); cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t160));
cl->set_interpolation (ControlList::Linear); cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t160));
cl->fast_simple_add ( 100.0 , 4.0); cl->fast_simple_add (t100 , 4.0);
cl->set_interpolation (ControlList::Discrete); cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
cl->set_interpolation (ControlList::Linear); cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
cl->fast_simple_add ( 200.0 , 0.0); cl->fast_simple_add (t200 , 0.0);
cl->set_interpolation (ControlList::Discrete); cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
cl->set_interpolation (ControlList::Linear); cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(t160));
cl->fast_simple_add ( 300.0 , 8.0); cl->fast_simple_add (t300 , 8.0);
cl->set_interpolation (ControlList::Discrete); cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
CPPUNIT_ASSERT_EQUAL(0.0, cl->unlocked_eval(250.)); CPPUNIT_ASSERT_EQUAL(0.0, cl->unlocked_eval(t250));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(999.)); CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(t999));
cl->set_interpolation (ControlList::Linear); cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(t160));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(250.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t250));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(999.)); CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(t999));
cl->fast_simple_add ( 400.0 , 9.0); cl->fast_simple_add (t400 , 9.0);
cl->set_interpolation (ControlList::Discrete); cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
CPPUNIT_ASSERT_EQUAL(0.0, cl->unlocked_eval(250.)); CPPUNIT_ASSERT_EQUAL(0.0, cl->unlocked_eval(t250));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(350.)); CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(t350));
CPPUNIT_ASSERT_EQUAL(9.0, cl->unlocked_eval(999.)); CPPUNIT_ASSERT_EQUAL(9.0, cl->unlocked_eval(t999));
cl->set_interpolation (ControlList::Linear); cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.)); CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(120.)); CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(160.)); CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(t160));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(250.)); CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t250));
CPPUNIT_ASSERT_EQUAL(8.5, cl->unlocked_eval(350.)); CPPUNIT_ASSERT_EQUAL(8.5, cl->unlocked_eval(t350));
CPPUNIT_ASSERT_EQUAL(9.0, cl->unlocked_eval(999.)); CPPUNIT_ASSERT_EQUAL(9.0, cl->unlocked_eval(t999));
} }
void void
@ -317,19 +366,19 @@ CurveTest::constrainedCubic ()
Evoral::ParameterDescriptor pd; Evoral::ParameterDescriptor pd;
pd.lower = 5; pd.lower = 5;
pd.upper = 325; pd.upper = 325;
Evoral::ControlList l(p,pd); Evoral::ControlList l(p, pd, AudioTime);
size_t i; size_t i;
l.set_interpolation(Evoral::ControlList::Curved); l.set_interpolation(Evoral::ControlList::Curved);
for (i=0; i<sizeof(data)/sizeof(data[0]); i++) { for (i=0; i<sizeof(data)/sizeof(data[0]); i++) {
l.add (data[i].x, data[i].y); l.add (timepos_t (data[i].x), data[i].y);
} }
Evoral::Curve curve(l); Evoral::Curve curve(l);
float f[121]; float f[121];
curve.get_vector(-10, 110, f, 121); curve.get_vector(timepos_t (-10), timepos_t (110), f, 121);
const float *g = &f[10]; /* so g starts at x==0 */ const float *g = &f[10]; /* so g starts at x==0 */

View File

@ -28,6 +28,6 @@ private:
boost::shared_ptr<Evoral::ControlList> TestCtrlList() { boost::shared_ptr<Evoral::ControlList> TestCtrlList() {
Evoral::Parameter param (Evoral::Parameter(0)); Evoral::Parameter param (Evoral::Parameter(0));
const Evoral::ParameterDescriptor desc; const Evoral::ParameterDescriptor desc;
return boost::shared_ptr<Evoral::ControlList> (new Evoral::ControlList(param, desc)); return boost::shared_ptr<Evoral::ControlList> (new Evoral::ControlList(param, desc, Temporal::AudioTime));
} }
}; };

View File

@ -12,7 +12,7 @@ typedef Temporal::Beats Time;
void void
NoteTest::copyTest () NoteTest::copyTest ()
{ {
Note<Time> a(0, Time(1.0), Time(2.0), 60, 0x40); Note<Time> a(0, Time::from_double(1.0), Time::from_double(2.0), 60, 0x40);
Note<Time> b(a); Note<Time> b(a);
CPPUNIT_ASSERT (a == b); CPPUNIT_ASSERT (a == b);
@ -25,7 +25,7 @@ NoteTest::copyTest ()
void void
NoteTest::idTest () NoteTest::idTest ()
{ {
Note<Time> a(0, Time(1.0), Time(2.0), 60, 0x40); Note<Time> a(0, Time::from_double(1.0), Time::from_double(2.0), 60, 0x40);
CPPUNIT_ASSERT_EQUAL (-1, a.id()); CPPUNIT_ASSERT_EQUAL (-1, a.id());
a.set_id(1234); a.set_id(1234);

View File

@ -5,24 +5,30 @@
CPPUNIT_TEST_SUITE_REGISTRATION (RangeTest); CPPUNIT_TEST_SUITE_REGISTRATION (RangeTest);
using namespace Evoral; using namespace Evoral;
using namespace Temporal;
void void
RangeTest::coalesceTest () RangeTest::coalesceTest ()
{ {
RangeList<int> fred; timepos_t t2 (2);
fred.add (Range<int> (2, 4)); timepos_t t4 (4);
fred.add (Range<int> (5, 6)); timepos_t t5 (5);
fred.add (Range<int> (6, 8)); timepos_t t6 (6);
timepos_t t8 (8);
RangeList<int>::List jim = fred.get (); RangeList fred;
fred.add (Range (t2, t4));
fred.add (Range (t5, t6));
fred.add (Range (t6, t8));
RangeList<int>::List::iterator i = jim.begin (); RangeList::List jim = fred.get ();
CPPUNIT_ASSERT_EQUAL (2, i->from);
CPPUNIT_ASSERT_EQUAL (4, i->to);
RangeList::List::iterator i = jim.begin ();
CPPUNIT_ASSERT_EQUAL (2L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (4L, i->end().samples());
++i; ++i;
CPPUNIT_ASSERT_EQUAL (5, i->from); CPPUNIT_ASSERT_EQUAL (5L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (8, i->to); CPPUNIT_ASSERT_EQUAL (8L, i->end().samples());
} }
/* Basic subtraction of a few smaller ranges from a larger one */ /* Basic subtraction of a few smaller ranges from a larger one */
@ -30,67 +36,82 @@ void
RangeTest::subtractTest1 () RangeTest::subtractTest1 ()
{ {
timepos_t t0 (0);
timepos_t t2 (2);
timepos_t t4 (4);
timepos_t t7 (7);
timepos_t t8 (8);
timepos_t t10 (10);
/* 01234567890 /* 01234567890
* fred: |---------| * fred: |---------|
* jim: |-| || * jim: |-| ||
* sheila: || || || * sheila: || || ||
*/ */
Range<int> fred (0, 10); Range fred (t0, t10);
RangeList<int> jim; RangeList jim;
jim.add (Range<int> (2, 4)); jim.add (Range (t2, t4));
jim.add (Range<int> (7, 8)); jim.add (Range (t7, t8));
RangeList<int> sheila = subtract (fred, jim); RangeList sheila = fred.subtract (jim);
RangeList<int>::List s = sheila.get (); RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (3), s.size ()); CPPUNIT_ASSERT_EQUAL (size_t (3), s.size ());
RangeList<int>::List::iterator i = s.begin (); RangeList::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0, i->from); CPPUNIT_ASSERT_EQUAL (0L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (1, i->to); CPPUNIT_ASSERT_EQUAL (1L, i->end().samples()); // XXX -> 2
++i; ++i;
CPPUNIT_ASSERT_EQUAL (5, i->from); CPPUNIT_ASSERT_EQUAL (5L, i->start().samples()); // XXX -> 4
CPPUNIT_ASSERT_EQUAL (6, i->to); CPPUNIT_ASSERT_EQUAL (6L, i->end().samples()); // XXX -> 7
++i; ++i;
CPPUNIT_ASSERT_EQUAL (9, i->from); CPPUNIT_ASSERT_EQUAL (9L, i->start().samples()); // XXX -> 8
CPPUNIT_ASSERT_EQUAL (10, i->to); CPPUNIT_ASSERT_EQUAL (10L, i->end().samples());
} }
/* Test subtraction of a range B from a range A, where A and B do not overlap */ /* Test subtraction of a range B from a range A, where A and B do not overlap */
void void
RangeTest::subtractTest2 () RangeTest::subtractTest2 ()
{ {
Range<int> fred (0, 10); timepos_t t0 (0);
timepos_t t10 (10);
timepos_t t12 (12);
timepos_t t19 (19);
RangeList<int> jim; Range fred (t0, t10);
jim.add (Range<int> (12, 19));
RangeList<int> sheila = subtract (fred, jim); RangeList jim;
jim.add (Range (t12, t19));
RangeList<int>::List s = sheila.get (); RangeList sheila = fred.subtract (jim);
RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (1), s.size ()); CPPUNIT_ASSERT_EQUAL (size_t (1), s.size ());
RangeList<int>::List::iterator i = s.begin (); RangeList::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0, i->from); CPPUNIT_ASSERT_EQUAL (0L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (10, i->to); CPPUNIT_ASSERT_EQUAL (10L, i->end().samples());
} }
/* Test subtraction of B from A, where B entirely overlaps A */ /* Test subtraction of B from A, where B entirely overlaps A */
void void
RangeTest::subtractTest3 () RangeTest::subtractTest3 ()
{ {
Range<int> fred (0, 10); timepos_t t0 (0);
timepos_t t10 (10);
timepos_t t12 (12);
Range fred (t0, t10);
RangeList<int> jim; RangeList jim;
jim.add (Range<int> (0, 12)); jim.add (Range (t0, t12));
RangeList<int> sheila = subtract (fred, jim); RangeList sheila = fred.subtract (jim);
RangeList<int>::List s = sheila.get (); RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (0), s.size ()); CPPUNIT_ASSERT_EQUAL (size_t (0), s.size ());
} }
@ -100,6 +121,14 @@ RangeTest::subtractTest3 ()
void void
RangeTest::subtractTest4 () RangeTest::subtractTest4 ()
{ {
timepos_t t0 (0);
timepos_t t2 (2);
timepos_t t4 (4);
timepos_t t7 (7);
timepos_t t8 (8);
timepos_t t9 (9);
timepos_t t10 (10);
/* 01234567890 /* 01234567890
* fred: |---------| * fred: |---------|
* jim: |-| || * jim: |-| ||
@ -107,29 +136,29 @@ RangeTest::subtractTest4 ()
* sheila: || || | * sheila: || || |
*/ */
Range<int> fred (0, 10); Range fred (t0, t10);
RangeList<int> jim; RangeList jim;
jim.add (Range<int> (2, 4)); jim.add (Range (t2, t4));
jim.add (Range<int> (7, 8)); jim.add (Range (t7, t8));
jim.add (Range<int> (8, 9)); jim.add (Range (t8, t9));
RangeList<int> sheila = subtract (fred, jim); RangeList sheila = fred.subtract (jim);
RangeList<int>::List s = sheila.get (); RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (3), s.size ()); CPPUNIT_ASSERT_EQUAL (size_t (3), s.size ());
RangeList<int>::List::iterator i = s.begin (); RangeList::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0, i->from); CPPUNIT_ASSERT_EQUAL (0L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (1, i->to); CPPUNIT_ASSERT_EQUAL (1L, i->end().samples());
++i; ++i;
CPPUNIT_ASSERT_EQUAL (5, i->from); CPPUNIT_ASSERT_EQUAL (5L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (6, i->to); CPPUNIT_ASSERT_EQUAL (6L, i->end().samples());
++i; ++i;
CPPUNIT_ASSERT_EQUAL (10, i->from); CPPUNIT_ASSERT_EQUAL (10L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (10, i->to); CPPUNIT_ASSERT_EQUAL (10L, i->end().samples());
} }
/* A bit like subtractTest1, except some of the ranges /* A bit like subtractTest1, except some of the ranges
@ -139,31 +168,40 @@ RangeTest::subtractTest4 ()
void void
RangeTest::subtractTest5 () RangeTest::subtractTest5 ()
{ {
timepos_t t0 (0);
timepos_t t1 (1);
timepos_t t4 (4);
timepos_t t6 (6);
timepos_t t7 (7);
timepos_t t9 (9);
timepos_t t12 (12);
timepos_t t42 (42);
/* 01234567890123 /* 01234567890123
* fred: |----------| * fred: |----------|
* jim: |---| || |------... * jim: |---| || |------...
* sheila:i | | * sheila:i | |
*/ */
Range<int> fred (1, 12); Range fred (t1, t12);
RangeList<int> jim; RangeList jim;
jim.add (Range<int> (0, 4)); jim.add (Range (t0, t4));
jim.add (Range<int> (6, 7)); jim.add (Range (t6, t7));
jim.add (Range<int> (9, 42)); jim.add (Range (t9, t42));
RangeList<int> sheila = subtract (fred, jim); RangeList sheila = fred.subtract (jim);
RangeList<int>::List s = sheila.get (); RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (2), s.size ()); CPPUNIT_ASSERT_EQUAL (size_t (2), s.size ());
RangeList<int>::List::iterator i = s.begin (); RangeList::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (5, i->from); CPPUNIT_ASSERT_EQUAL (5L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (5, i->to); CPPUNIT_ASSERT_EQUAL (5L, i->end().samples());
++i; ++i;
CPPUNIT_ASSERT_EQUAL (8, i->from); CPPUNIT_ASSERT_EQUAL (8L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (8, i->to); CPPUNIT_ASSERT_EQUAL (8L, i->end().samples());
} }
/* Test coverage() with all possible types of overlap. /* Test coverage() with all possible types of overlap.
@ -172,60 +210,61 @@ RangeTest::subtractTest5 ()
void void
RangeTest::coverageTest () RangeTest::coverageTest ()
{ {
#define coverage(A0, A1, B0, B1) Range(timepos_t(A0), timepos_t(A1)).coverage(timepos_t(B0), timepos_t(B1))
// b starts before a // b starts before a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 1), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 1), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 2), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 2), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 3), Evoral::OverlapStart); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 3), OverlapStart); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 5), Evoral::OverlapStart); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 5), OverlapStart);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 7), Evoral::OverlapExternal); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 7), OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 9), Evoral::OverlapExternal); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 9), OverlapExternal);
// b starts at a // b starts at a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 3), Evoral::OverlapStart); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 3), OverlapStart); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 5), Evoral::OverlapStart); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 5), OverlapStart);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 7), Evoral::OverlapExternal); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 7), OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 9), Evoral::OverlapExternal); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 9), OverlapExternal);
// b starts inside a // b starts inside a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 4), Evoral::OverlapInternal); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 4), OverlapInternal); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 6), Evoral::OverlapInternal); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 6), OverlapInternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 7), Evoral::OverlapEnd); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 7), OverlapEnd);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 8), Evoral::OverlapEnd); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 8), OverlapEnd);
// b starts at end of a // b starts at end of a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 7), Evoral::OverlapEnd); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 7), OverlapEnd); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 9), Evoral::OverlapEnd); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 9), OverlapEnd); // XXX fails
// b starts after end of a // b starts after end of a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 8), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 8), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 9), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 9), OverlapNone);
// zero-length range a // zero-length range a
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 2, 4), Evoral::OverlapExternal); CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 2, 4), OverlapExternal); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 1, 2), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 1, 2), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 3, 3), Evoral::OverlapExternal); CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 3, 3), OverlapExternal); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 8, 9), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 8, 9), OverlapNone);
// negative length range a // negative length range a
// XXX these are debatable - should we just consider start & end to be // XXX these are debatable - should we just consider start & end to be
// swapped if end < start? // swapped if end < start?
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 1, 2), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 1, 2), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 2, 3), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 2, 3), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 2, 4), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 2, 4), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 3, 3), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 3, 3), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 8, 9), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 8, 9), OverlapNone);
// negative length range b // negative length range b
// b starts before a // b starts before a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 0), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 0), OverlapNone);
// b starts at a // b starts at a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 2), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 2), OverlapNone);
// b starts inside a // b starts inside a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 3), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 3), OverlapNone);
// b starts at end of a // b starts at end of a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 5), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 5), OverlapNone);
// b starts after end of a // b starts after end of a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 7), Evoral::OverlapNone); CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 7), OverlapNone);
} }

View File

@ -74,7 +74,6 @@ SMFTest::takeFiveTest ()
CPPUNIT_ASSERT(!seq->empty()); CPPUNIT_ASSERT(!seq->empty());
// Iterate over all notes // Iterate over all notes
bool on = true;
size_t num_notes = 0; size_t num_notes = 0;
size_t num_sysexes = 0; size_t num_sysexes = 0;
for (Sequence<Time>::const_iterator i = seq->begin(Time()); i != seq->end(); ++i) { for (Sequence<Time>::const_iterator i = seq->begin(Time()); i != seq->end(); ++i) {

View File

@ -24,6 +24,7 @@
#include <cppunit/TestFixture.h> #include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/HelperMacros.h>
#include "temporal/beats.h" #include "temporal/beats.h"
#include "temporal/tempo.h"
#include "evoral/SMF.h" #include "evoral/SMF.h"
#include "SequenceTest.h" #include "SequenceTest.h"
@ -63,6 +64,7 @@ public:
typedef Temporal::Beats Time; typedef Temporal::Beats Time;
void setUp() { void setUp() {
Temporal::TempoMap::fetch();
type_map = new DummyTypeMap(); type_map = new DummyTypeMap();
assert(type_map); assert(type_map);
seq = new MySequence<Time>(*type_map); seq = new MySequence<Time>(*type_map);

View File

@ -41,8 +41,8 @@ SequenceTest::preserveEventOrderingTest ()
); );
event->buffer()[0] = MIDI_CMD_CONTROL; event->buffer()[0] = MIDI_CMD_CONTROL;
event->buffer()[1] = event->time().to_double() / 1000; event->buffer()[1] = 0; //event->time().to_double() / 1000;
event->buffer()[2] = event->time().to_double() / 1000; event->buffer()[2] = 0; //event->time().to_double() / 1000;
boost::shared_ptr<Event<Time> > event_ptr(event); boost::shared_ptr<Event<Time> > event_ptr(event);
@ -88,10 +88,10 @@ SequenceTest::iteratorSeekTest ()
// Iterate over all notes // Iterate over all notes
bool on = true; bool on = true;
for (Sequence<Time>::const_iterator i = seq->begin(Time(600)); i != seq->end(); ++i) { for (Sequence<Time>::const_iterator i = seq->begin(Time::from_double(600)); i != seq->end(); ++i) {
if (on) { if (on) {
CPPUNIT_ASSERT(i->is_note_on()); CPPUNIT_ASSERT(i->is_note_on());
CPPUNIT_ASSERT_EQUAL(i->time(), Time((num_notes + 6) * 100)); CPPUNIT_ASSERT_EQUAL(i->time(), Time::from_double((num_notes + 6) * 100));
++num_notes; ++num_notes;
on = false; on = false;
} else { } else {
@ -103,20 +103,20 @@ SequenceTest::iteratorSeekTest ()
CPPUNIT_ASSERT_EQUAL(size_t(6), num_notes); CPPUNIT_ASSERT_EQUAL(size_t(6), num_notes);
// Test invalidation // Test invalidation
Sequence<Time>::const_iterator i = seq->begin(Time(600)); Sequence<Time>::const_iterator i = seq->begin(Time::from_double(600));
std::set< boost::weak_ptr< Note<Time> > > active_notes; std::set< boost::weak_ptr< Note<Time> > > active_notes;
i.invalidate(&active_notes); i.get_active_notes(active_notes);
CPPUNIT_ASSERT_EQUAL((size_t)1, active_notes.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, active_notes.size());
// Test resuming after invalidation // Test resuming after invalidation
i = seq->begin(Time(601), false, std::set<Evoral::Parameter>(), &active_notes); i = seq->begin(Time::from_double(601), false, std::set<Evoral::Parameter>(), &active_notes);
CPPUNIT_ASSERT(i->is_note_off()); CPPUNIT_ASSERT(i->is_note_off());
on = false; on = false;
num_notes = 1; num_notes = 1;
for (; i != seq->end(); ++i) { for (; i != seq->end(); ++i) {
if (on) { if (on) {
CPPUNIT_ASSERT(i->is_note_on()); CPPUNIT_ASSERT(i->is_note_on());
CPPUNIT_ASSERT_EQUAL(Time((num_notes + 6) * 100), i->time()); CPPUNIT_ASSERT_EQUAL(Time::from_double((num_notes + 6) * 100), i->time());
++num_notes; ++num_notes;
on = false; on = false;
} else { } else {
@ -137,6 +137,7 @@ SequenceTest::iteratorSeekTest ()
void void
SequenceTest::controlInterpolationTest () SequenceTest::controlInterpolationTest ()
{ {
using namespace Temporal;
seq->clear(); seq->clear();
static const uint64_t delay = 1000; static const uint64_t delay = 1000;
@ -149,9 +150,9 @@ SequenceTest::controlInterpolationTest ()
double max = 127.0; double max = 127.0;
// Make a ramp like /\ from min to max and back to min // Make a ramp like /\ from min to max and back to min
c->set_double(min, 0, true); c->set_double(min, timepos_t(Time::from_double(0)), true);
c->set_double(max, delay, true); c->set_double(max, timepos_t(Time::from_double(delay)), true);
c->set_double(min, 2*delay, true); c->set_double(min, timepos_t(Time::from_double(2*delay)), true);
CCTestSink<Time> sink(cc_type); CCTestSink<Time> sink(cc_type);
@ -161,11 +162,11 @@ SequenceTest::controlInterpolationTest ()
sink.write(i->time(), i->event_type(), i->size(), i->buffer()); sink.write(i->time(), i->event_type(), i->size(), i->buffer());
} }
CPPUNIT_ASSERT_EQUAL((size_t)3, sink.events.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, sink.events.size());
CPPUNIT_ASSERT_EQUAL(Time(0), sink.events[0].first); CPPUNIT_ASSERT_EQUAL(Time::from_double(0), sink.events[0].first);
CPPUNIT_ASSERT_EQUAL((uint8_t)0, sink.events[0].second); CPPUNIT_ASSERT_EQUAL((uint8_t)0, sink.events[0].second);
CPPUNIT_ASSERT_EQUAL(Time(1000), sink.events[1].first); CPPUNIT_ASSERT_EQUAL(Time::from_double(1000), sink.events[1].first);
CPPUNIT_ASSERT_EQUAL((uint8_t)127, sink.events[1].second); CPPUNIT_ASSERT_EQUAL((uint8_t)127, sink.events[1].second);
CPPUNIT_ASSERT_EQUAL(Time(2000), sink.events[2].first); CPPUNIT_ASSERT_EQUAL(Time::from_double(2000), sink.events[2].first);
CPPUNIT_ASSERT_EQUAL((uint8_t)0, sink.events[2].second); CPPUNIT_ASSERT_EQUAL((uint8_t)0, sink.events[2].second);
sink.events.clear(); sink.events.clear();
CPPUNIT_ASSERT_EQUAL((size_t)0, sink.events.size()); CPPUNIT_ASSERT_EQUAL((size_t)0, sink.events.size());
@ -176,7 +177,7 @@ SequenceTest::controlInterpolationTest ()
sink.write(i->time(), i->event_type(), i->size(), i->buffer()); sink.write(i->time(), i->event_type(), i->size(), i->buffer());
} }
CPPUNIT_ASSERT_EQUAL((size_t)(128 * 2 - 1), sink.events.size()); CPPUNIT_ASSERT_EQUAL((size_t)(128 * 2 - 1), sink.events.size());
Time last_time(0); Time last_time = Time::from_double (0);
int16_t last_value = -1; int16_t last_value = -1;
bool ascending = true; bool ascending = true;
for (CCTestSink<Time>::Events::const_iterator i = sink.events.begin(); for (CCTestSink<Time>::Events::const_iterator i = sink.events.begin();

View File

@ -63,7 +63,7 @@ public:
Evoral::ParameterDescriptor desc; Evoral::ParameterDescriptor desc;
desc.upper = 127; desc.upper = 127;
desc.rangesteps = 128; desc.rangesteps = 128;
boost::shared_ptr<ControlList> list(new ControlList(param, desc)); boost::shared_ptr<ControlList> list(new ControlList(param, desc, Temporal::BeatTime));
return boost::shared_ptr<Control>(new Control(param, desc, list)); return boost::shared_ptr<Control>(new Control(param, desc, list));
} }
}; };
@ -71,7 +71,7 @@ public:
template<typename Time> template<typename Time>
class TestSink : public EventSink<Time> { class TestSink : public EventSink<Time> {
public: public:
TestSink() : _last_event_time(-1) {} TestSink() : _last_event_time(Time::from_double (-1)) {}
/// return value, time, type, size, buffer /// return value, time, type, size, buffer
sigc::signal<uint32_t, Time, EventType, uint32_t, const uint8_t*> writing; sigc::signal<uint32_t, Time, EventType, uint32_t, const uint8_t*> writing;
@ -136,7 +136,7 @@ public:
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
test_notes.push_back( test_notes.push_back(
boost::shared_ptr<Note<Time> >( boost::shared_ptr<Note<Time> >(
new Note<Time>(0, Time(i * 100), Time(100), 64 + i, 64))); new Note<Time>(0, Time::from_double(i * 100), Time::from_double(100), 64 + i, 64)));
} }
} }

View File

@ -6,11 +6,13 @@
#include <cppunit/BriefTestProgressListener.h> #include <cppunit/BriefTestProgressListener.h>
#include "pbd/pbd.h" #include "pbd/pbd.h"
#include "temporal/tempo.h"
int int
main() main()
{ {
if (!PBD::init ()) return 1; if (!PBD::init ()) return 1;
Temporal::init ();
CppUnit::TestResult testresult; CppUnit::TestResult testresult;

View File

@ -117,7 +117,7 @@ def build(bld):
obj.defines += [ 'PACKAGE="libevoral"' ] obj.defines += [ 'PACKAGE="libevoral"' ]
# disable unit-tests -- build is broken with nutempo # disable unit-tests -- build is broken with nutempo
if False and bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'): if bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'):
# Static library (for unit test code coverage) # Static library (for unit test code coverage)
obj = bld(features = 'cxx cstlib') obj = bld(features = 'cxx cstlib')
obj.source = lib_source obj.source = lib_source