From 64299d1bf7647f89ce1de6bb2d1a9acfae28033f Mon Sep 17 00:00:00 2001 From: Dan Dennedy Date: Sun, 19 May 2013 20:09:30 -0700 Subject: [PATCH] Add mlt_property_set_double_pos() and mlt_property_set_int_pos(). --- src/framework/mlt_property.c | 64 +++++++++++++++++++ src/framework/mlt_property.h | 12 ++-- src/framework/mlt_types.h | 14 ++-- src/tests/test_properties/test_properties.cpp | 38 +++++++++++ 4 files changed, 117 insertions(+), 11 deletions(-) diff --git a/src/framework/mlt_property.c b/src/framework/mlt_property.c index e09959f3..fd1659db 100644 --- a/src/framework/mlt_property.c +++ b/src/framework/mlt_property.c @@ -1046,3 +1046,67 @@ int mlt_property_get_int_pos( mlt_property self, double fps, locale_t locale, in } return result; } + +/** Set a property animation keyframe to a real number. + * + * \public \memberof mlt_property_s + * \param self a property + * \param value a double precision floating point value + * \return false if successful, true to indicate error + */ + +int mlt_property_set_double_pos( mlt_property self, double value, double fps, locale_t locale, + mlt_keyframe_type keyframe_type, int position, int length ) +{ + int result; + if ( ( self->types & mlt_prop_string ) && self->prop_string ) + { + struct mlt_animation_item_s item; + item.property = mlt_property_init(); + item.frame = position; + item.keyframe_type = keyframe_type; + mlt_property_set_double( item.property, value ); + + refresh_animation( self, fps, locale, length ); + result = mlt_animation_insert( self->animation, &item ); + mlt_animation_interpolate( self->animation ); + mlt_property_close( item.property ); + } + else + { + result = mlt_property_set_double( self, value ); + } + return result; +} + +/** Set a property animation keyframe to an integer value. + * + * \public \memberof mlt_property_s + * \param self a property + * \param value a double precision floating point value + * \return false if successful, true to indicate error + */ + +int mlt_property_set_int_pos( mlt_property self, int value, double fps, locale_t locale, + mlt_keyframe_type keyframe_type, int position, int length ) +{ + int result; + if ( ( self->types & mlt_prop_string ) && self->prop_string ) + { + struct mlt_animation_item_s item; + item.property = mlt_property_init(); + item.frame = position; + item.keyframe_type = keyframe_type; + mlt_property_set_int( item.property, value ); + + refresh_animation( self, fps, locale, length ); + result = mlt_animation_insert( self->animation, &item ); + mlt_animation_interpolate( self->animation ); + mlt_property_close( item.property ); + } + else + { + result = mlt_property_set_int( self, value ); + } + return result; +} diff --git a/src/framework/mlt_property.h b/src/framework/mlt_property.h index 8df1d165..07fe6631 100644 --- a/src/framework/mlt_property.h +++ b/src/framework/mlt_property.h @@ -54,9 +54,13 @@ extern void *mlt_property_get_data( mlt_property self, int *length ); extern void mlt_property_close( mlt_property self ); extern void mlt_property_pass( mlt_property self, mlt_property that ); extern char *mlt_property_get_time( mlt_property self, mlt_time_format, double fps, locale_t ); -extern int mlt_property_interpolate(mlt_property self, mlt_property points[], - double progress, double fps, locale_t locale , mlt_keyframe_type interp); -extern double mlt_property_get_double_pos(mlt_property self, double fps, locale_t locale, int position, int length ); -extern int mlt_property_get_int_pos(mlt_property self, double fps, locale_t locale, int position, int length ); +extern int mlt_property_interpolate( mlt_property self, mlt_property points[], + double progress, double fps, locale_t locale, mlt_keyframe_type interp ); +extern double mlt_property_get_double_pos( mlt_property self, double fps, locale_t locale, int position, int length ); +extern int mlt_property_get_int_pos( mlt_property self, double fps, locale_t locale, int position, int length ); +extern int mlt_property_set_double_pos( mlt_property self, double value, double fps, locale_t locale, + mlt_keyframe_type keyframe_type, int position, int length ); +extern int mlt_property_set_int_pos( mlt_property self, int value, double fps, locale_t locale, + mlt_keyframe_type keyframe_type, int position, int length ); #endif diff --git a/src/framework/mlt_types.h b/src/framework/mlt_types.h index 5261051f..41e42c8d 100644 --- a/src/framework/mlt_types.h +++ b/src/framework/mlt_types.h @@ -78,9 +78,9 @@ mlt_time_format; /** Interpolation methods for animation keyframes */ typedef enum { - mlt_keyframe_discrete, //< non-interpolated; value changes instantaneously at the key frame - mlt_keyframe_linear, //< simple, constant pace from this key frame to the next - mlt_keyframe_smooth //< eased pacing from this keyframe to the next using a Catmull-Rom spline + mlt_keyframe_discrete = 0, /**< non-interpolated; value changes instantaneously at the key frame */ + mlt_keyframe_linear, /**< simple, constant pace from this key frame to the next */ + mlt_keyframe_smooth /**< eased pacing from this keyframe to the next using a Catmull-Rom spline */ } mlt_keyframe_type; @@ -88,9 +88,9 @@ mlt_keyframe_type; typedef enum { - mlt_whence_relative_start, /**< relative to the beginning */ - mlt_whence_relative_current,/**< relative to the current position */ - mlt_whence_relative_end /**< relative to the end */ + mlt_whence_relative_start = 0, /**< relative to the beginning */ + mlt_whence_relative_current, /**< relative to the current position */ + mlt_whence_relative_end /**< relative to the end */ } mlt_whence; @@ -98,7 +98,7 @@ mlt_whence; typedef enum { - invalid_type, /**< invalid service */ + invalid_type = 0, /**< invalid service */ unknown_type, /**< unknown class */ producer_type, /**< Producer class */ tractor_type, /**< Tractor class */ diff --git a/src/tests/test_properties/test_properties.cpp b/src/tests/test_properties/test_properties.cpp index 1aac05cf..d496e4c8 100644 --- a/src/tests/test_properties/test_properties.cpp +++ b/src/tests/test_properties/test_properties.cpp @@ -611,6 +611,44 @@ private Q_SLOTS: 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); + } }; QTEST_APPLESS_MAIN(TestProperties) -- 2.39.5