diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index 2e8097f98..3fbf2ceca 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -2108,6 +2108,57 @@ int mlt_properties_anim_set_int( mlt_properties self, const char *name, int valu return error; } +/** Get a real number associated to the name at a frame position. + * + * \public \memberof mlt_properties_s + * \param self a properties list + * \param name the property to get + * \return The real number, 0 if not found (which may also be a legitimate value) + */ + +double mlt_properties_anim_get_double( mlt_properties self, const char *name, int position, int length ) +{ + mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL ); + double fps = mlt_profile_fps( profile ); + property_list *list = self->local; + mlt_property value = mlt_properties_find( self, name ); + return value == NULL ? 0.0 : mlt_property_anim_get_double( value, fps, list->locale, position, length ); +} + +/** Set a property to a real number at a frame position. + * + * \public \memberof mlt_properties_s + * \param self a properties list + * \param name the property to set + * \param value the real number + * \return true if error + */ + +int mlt_properties_anim_set_double( mlt_properties self, const char *name, double value, + mlt_keyframe_type keyframe_type, int position, int length ) +{ + int error = 1; + + if ( !self || !name ) return error; + + // Fetch the property to work with + mlt_property property = mlt_properties_fetch( self, name ); + + // Set it if not NULL + if ( property != NULL ) + { + mlt_profile profile = mlt_properties_get_data( self, "_profile", NULL ); + double fps = mlt_profile_fps( profile ); + property_list *list = self->local; + error = mlt_property_anim_set_double( property, value, fps, list->locale, keyframe_type, position, length ); + mlt_properties_do_mirror( self, name ); + } + + mlt_events_fire( self, "property-changed", name, NULL ); + + return error; +} + /** Set a property to a rectangle value. * * \public \memberof mlt_properties_s diff --git a/src/framework/mlt_properties.h b/src/framework/mlt_properties.h index 93c283cd0..5113f2a93 100644 --- a/src/framework/mlt_properties.h +++ b/src/framework/mlt_properties.h @@ -92,10 +92,11 @@ extern char *mlt_properties_get_time( mlt_properties, const char* name, mlt_time extern int mlt_properties_anim_get_int( mlt_properties self, const char *name, int position, int length ); extern int mlt_properties_anim_set_int( mlt_properties self, const char *name, int value, mlt_keyframe_type keyframe_type, int position, int length ); +extern double mlt_properties_anim_get_double( mlt_properties self, const char *name, int position, int length ); +extern int mlt_properties_anim_set_double( mlt_properties self, const char *name, double value, mlt_keyframe_type keyframe_type, int position, int length ); extern int mlt_properties_set_rect( mlt_properties self, const char *name, mlt_rect value ); extern mlt_rect mlt_properties_get_rect( mlt_properties self, const char *name ); - extern int mlt_properties_anim_set_rect( mlt_properties self, const char *name, mlt_rect value, mlt_keyframe_type keyframe_type, int position, int length ); extern mlt_rect mlt_properties_anim_get_rect( mlt_properties self, const char *name, int position, int length ); diff --git a/src/framework/mlt_property.c b/src/framework/mlt_property.c index 84b6e1d29..b00cc5638 100644 --- a/src/framework/mlt_property.c +++ b/src/framework/mlt_property.c @@ -591,7 +591,7 @@ char *mlt_property_get_string( mlt_property self ) { self->types |= mlt_prop_string; self->prop_string = malloc( 32 ); - sprintf( self->prop_string, "%f", self->prop_double ); + sprintf( self->prop_string, "%g", self->prop_double ); } else if ( self->types & mlt_prop_position ) { @@ -667,7 +667,7 @@ char *mlt_property_get_string_l( mlt_property self, locale_t locale ) { self->types |= mlt_prop_string; self->prop_string = malloc( 32 ); - sprintf( self->prop_string, "%f", self->prop_double ); + sprintf( self->prop_string, "%g", self->prop_double ); } else if ( self->types & mlt_prop_position ) { diff --git a/src/mlt++/MltProperties.cpp b/src/mlt++/MltProperties.cpp index e717ec982..2df5b58e3 100644 --- a/src/mlt++/MltProperties.cpp +++ b/src/mlt++/MltProperties.cpp @@ -347,6 +347,16 @@ int Properties::anim_set( const char *name, int value, int position, int length, return mlt_properties_anim_set_int( get_properties(), name, value, keyframe_type, position, length ); } +double Properties::anim_get_double(const char *name, int position, int length) +{ + return mlt_properties_anim_get_double( get_properties(), name, position, length ); +} + +int Properties::anim_set(const char *name, double value, int position, int length, mlt_keyframe_type keyframe_type) +{ + return mlt_properties_anim_set_double( get_properties(), name, value, keyframe_type, position, length ); +} + int Properties::set( const char *name, mlt_rect value ) { return mlt_properties_set_rect( get_properties(), name, value ); diff --git a/src/mlt++/MltProperties.h b/src/mlt++/MltProperties.h index 96d395ab9..decb7d135 100644 --- a/src/mlt++/MltProperties.h +++ b/src/mlt++/MltProperties.h @@ -101,6 +101,10 @@ namespace Mlt int anim_get_int( const char *name, int position, int length ); int anim_set( const char *name, int value, int position, int length, mlt_keyframe_type keyframe_type = mlt_keyframe_linear ); + double anim_get_double( const char *name, int position, int length ); + int anim_set( const char *name, double value, int position, int length, + mlt_keyframe_type keyframe_type = mlt_keyframe_linear ); + int set( const char *name, mlt_rect value ); int set( const char *name, double x, double y, double w, double h, double opacity = 1.0 ); mlt_rect get_rect( const char* name ); diff --git a/src/tests/test_properties/test_properties.cpp b/src/tests/test_properties/test_properties.cpp index c17580a44..b23b68bad 100644 --- a/src/tests/test_properties/test_properties.cpp +++ b/src/tests/test_properties/test_properties.cpp @@ -133,8 +133,8 @@ private Q_SLOTS: void DoubleFromString() { Properties p; - const char *s = "-1.234567"; - double d = -1.234567; + const char *s = "-1.23456"; + double d = -1.23456; p.set("key", d); QCOMPARE(p.get("key"), s); p.set("key", s); @@ -655,6 +655,36 @@ private Q_SLOTS: QCOMPARE(p.anim_get_int("foo", 50, len), 200); } + void PropertiesAnimDouble() + { + int len = 50; + Properties p; + p.set_lcnumeric("POSIX"); + + // Construct animation from scratch + p.anim_set("foo", 0.0, 0, len); + p.anim_set("foo", 100.0, 50, len, mlt_keyframe_smooth); + QCOMPARE(p.anim_get_double("foo", 0, len), 0.0); + QCOMPARE(p.anim_get_double("foo", 25, len), 50.0); + QCOMPARE(p.anim_get_double("foo", 50, len), 100.0); + QCOMPARE(p.get("foo"), "0=0;50~=100"); + + // Animation from string value + p.set("foo", "10=100.2;20=200.8"); + QCOMPARE(p.anim_get_double("foo", 0, len), 100.2); + QCOMPARE(p.anim_get_double("foo", 15, len), 150.5); + QCOMPARE(p.anim_get_double("foo", 20, len), 200.8); + + // 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.anim_get_double("foo", 0, len), 100.0); + QCOMPARE(p.anim_get_double("foo", 25, len), 150.0); + QCOMPARE(p.anim_get_double("foo", 50, len), 200.0); + } + void test_mlt_rect() { mlt_property p = mlt_property_init();