#include <mlt++/Mlt.h>
using namespace Mlt;
+extern "C" {
+#define __DARWIN__
+#include <framework/mlt_property.h>
+#include <framework/mlt_animation.h>
+}
+
class TestProperties: public QObject
{
Q_OBJECT
p.set("key", "0,125");
QCOMPARE(p.get_double("key"), double(1) / double(8));
}
+
+ void DoubleAnimation()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_animation a = mlt_animation_new();
+ struct mlt_animation_item_s item;
+
+ mlt_animation_parse(a, "50=1; 60=60; 100=0", 100, fps, locale);
+ mlt_animation_remove(a, 60);
+ char *a_serialized = mlt_animation_serialize(a);
+ QCOMPARE(a_serialized, "50=1;100=0");
+ if (a_serialized) free(a_serialized);
+ item.property = mlt_property_init();
+
+ mlt_animation_get_item(a, &item, 10);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 1.0);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 50);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 1.0);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 75);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.5);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 100);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.0);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 110);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.0);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_property_close(item.property);
+ mlt_animation_close(a);
+ }
+
+ void IntAnimation()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_animation a = mlt_animation_new();
+ struct mlt_animation_item_s item;
+
+ mlt_animation_parse(a, "50=100; 60=60; 100=0", 100, fps, locale);
+ mlt_animation_remove(a, 60);
+ char *a_serialized = mlt_animation_serialize(a);
+ QCOMPARE(a_serialized, "50=100;100=0");
+ if (a_serialized) free(a_serialized);
+ item.property = mlt_property_init();
+
+ mlt_animation_get_item(a, &item, 10);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 50);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 75);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 50);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 100);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 110);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_property_close(item.property);
+ mlt_animation_close(a);
+ }
+
+ void AnimationWithTimeValueKeyframes()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_animation a = mlt_animation_new();
+ struct mlt_animation_item_s item;
+
+ mlt_animation_parse(a, ":2.0=1; :4.0=0", 100, fps, locale);
+ char *a_serialized = mlt_animation_serialize(a);
+ // Time serializes to frame units :-\.
+ QCOMPARE(a_serialized, "50=1;100=0");
+ if (a_serialized) free(a_serialized);
+ item.property = mlt_property_init();
+
+ mlt_animation_get_item(a, &item, 10);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 1.0);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 50);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 1.0);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 75);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.5);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 100);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.0);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 110);
+ QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.0);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_property_close(item.property);
+ mlt_animation_close(a);
+ }
+
+ void DiscreteIntAnimation()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_animation a = mlt_animation_new();
+ struct mlt_animation_item_s item;
+
+ mlt_animation_parse(a, "50|=100; 60|=60; 100|=0", 100, fps, locale);
+ char *a_serialized = mlt_animation_serialize(a);
+ QCOMPARE(a_serialized, "50|=100;60|=60;100|=0");
+ if (a_serialized) free(a_serialized);
+ item.property = mlt_property_init();
+
+ mlt_animation_get_item(a, &item, 10);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 50);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 55);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 60);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 60);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 75);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 60);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 100);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 110);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_property_close(item.property);
+ mlt_animation_close(a);
+ }
+
+ void StringAnimation()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_animation a = mlt_animation_new();
+ struct mlt_animation_item_s item;
+
+ mlt_animation_parse(a, "50=hello world; 60=\"good night\"; 100=bar", 100, fps, locale);
+ char *a_serialized = mlt_animation_serialize(a);
+ QCOMPARE(a_serialized, "50=hello world;60=\"good night\";100=bar");
+ if (a_serialized) free(a_serialized);
+ item.property = mlt_property_init();
+
+ mlt_animation_get_item(a, &item, 10);
+ QCOMPARE(mlt_property_get_string(item.property), "hello world");
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 50);
+ QCOMPARE(mlt_property_get_string(item.property), "hello world");
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 75);
+ QCOMPARE(mlt_property_get_string(item.property), "\"good night\"");
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 100);
+ QCOMPARE(mlt_property_get_string(item.property), "bar");
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 110);
+ QCOMPARE(mlt_property_get_string(item.property), "bar");
+ QCOMPARE(item.is_key, 0);
+
+ mlt_property_close(item.property);
+ mlt_animation_close(a);
+ }
+
+ void test_property_get_double_pos()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_property p = mlt_property_init();
+ mlt_property_set_string(p, "10=100; 20=200");
+ QCOMPARE(mlt_property_get_double(p, fps, locale), 10.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 0, 100), 100.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 15, 100), 150.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 20, 100), 200.0);
+
+ mlt_property_set_string(p, "1.5");
+ QCOMPARE(mlt_property_get_double(p, fps, locale), 1.5);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 10, 100), 1.5);
+
+ mlt_property_close(p);
+ }
+
+ void test_property_get_int_pos()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_property p = mlt_property_init();
+ mlt_property_set_string(p, "10=100; 20=200");
+ QCOMPARE(mlt_property_get_int(p, fps, locale), 10);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 0, 100), 100);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 15, 100), 150);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 20, 100), 200);
+
+ mlt_property_set_string(p, "1.5");
+ QCOMPARE(mlt_property_get_int(p, fps, locale), 1);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 10, 100), 1);
+
+ mlt_property_close(p);
+ }
+
+ void SmoothIntAnimation()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_animation a = mlt_animation_new();
+ struct mlt_animation_item_s item;
+
+ mlt_animation_parse(a, "0=80;10~=80; 20~=30; 30~=40; 40~=28; 50=90; 60=0; 70=60; 80=20", 100, fps, locale);
+ item.property = mlt_property_init();
+ char *a_serialized = mlt_animation_serialize(a);
+ QCOMPARE(a_serialized, "0=80;10~=80;20~=30;30~=40;40~=28;50=90;60=0;70=60;80=20");
+ if (a_serialized) free(a_serialized);
+
+ mlt_animation_get_item(a, &item, 10);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 80);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 50);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 90);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 55);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 45);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 60);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 75);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 40);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 100);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 20);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 110);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 20);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_property_close(item.property);
+ mlt_animation_close(a);
+ }
+
+ void test_property_set_double_pos()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_property p = mlt_property_init();
+ mlt_property_set_string(p, "10=100; 20=200");
+ mlt_property_set_double_pos(p, 1.5, fps, locale, mlt_keyframe_linear, 30, 100);
+ QCOMPARE(mlt_property_get_double(p, fps, locale), 10.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 0, 100), 100.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 15, 100), 150.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 20, 100), 200.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 25, 100), 100.75);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 30, 100), 1.5);
+ mlt_property_close(p);
+ }
+
+ void test_property_set_int_pos()
+ {
+ locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ double fps = 25.0;
+ mlt_property p = mlt_property_init();
+ mlt_property_set_string(p, "10=100; 20=200");
+ mlt_property_set_int_pos(p, 300, fps, locale, mlt_keyframe_linear, 30, 100);
+ QCOMPARE(mlt_property_get_int(p, fps, locale), 10);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 0, 100), 100);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 15, 100), 150);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 20, 100), 200);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 25, 100), 250);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 30, 100), 300);
+ mlt_property_close(p);
+ }
+
+ void PercentAsRatio()
+ {
+ Properties p;
+ p.set("foo", "12.3%");
+ QCOMPARE(p.get_double("foo"), 0.123);
+ p.set("foo", "456 %");
+ QCOMPARE(p.get_double("foo"), 456.0);
+ }
+
+ void PropertiesAnimInt()
+ {
+ int len = 50;
+ Properties p;
+ p.set_lcnumeric("POSIX");
+
+ // Construct animation from scratch
+ p.set("foo", 0, 0, len);
+ p.set("foo", 100, 50, len, mlt_keyframe_smooth);
+ QCOMPARE(p.get_int("foo", 0, len), 0);
+ QCOMPARE(p.get_int("foo", 25, len), 50);
+ QCOMPARE(p.get_int("foo", 50, len), 100);
+ QCOMPARE(p.get("foo"), "0=0;50~=100");
+
+ // Animation from string value
+ p.set("foo", "10=100;20=200");
+ QCOMPARE(p.get_int("foo", 0, len), 100);
+ QCOMPARE(p.get_int("foo", 15, len), 150);
+ QCOMPARE(p.get_int("foo", 20, len), 200);
+
+ // Animation from string using time clock values
+ // Need to set a profile so fps can be used to convert time to frames.
+ Profile profile("dv_pal");
+ p.set("_profile", profile.get_profile(), 0);
+ p.set("foo", ":0.0=100; :2.0=200");
+ QCOMPARE(p.get_int("foo", 0, len), 100);
+ QCOMPARE(p.get_int("foo", 25, len), 150);
+ QCOMPARE(p.get_int("foo", 50, len), 200);
+ }
};
QTEST_APPLESS_MAIN(TestProperties)