From: Dan Dennedy Date: Thu, 23 May 2013 03:14:55 +0000 (-0700) Subject: Add mlt_properties_set/get_int_pos and Properties::set/get_int. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=4031b2655c7ab703fe8f0fd362767c2de5a8a03a;p=mlt Add mlt_properties_set/get_int_pos and Properties::set/get_int. --- diff --git a/src/framework/mlt_properties.c b/src/framework/mlt_properties.c index 6f826e58..e96a1307 100644 --- a/src/framework/mlt_properties.c +++ b/src/framework/mlt_properties.c @@ -2055,3 +2055,55 @@ char *mlt_properties_get_time( mlt_properties self, const char* name, mlt_time_f } return NULL; } + +/** Get an integer 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 integer value, 0 if not found (which may also be a legitimate value) + */ + +int mlt_properties_get_int_pos( 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 : mlt_property_get_int_pos( value, fps, list->locale, position, length ); +} + +/** Set a property to an integer value at a frame position. + * + * \public \memberof mlt_properties_s + * \param self a properties list + * \param name the property to set + * \param value the integer + * \return true if error + */ + +int mlt_properties_set_int_pos( mlt_properties self, const char *name, int 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_set_int_pos( 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; +} + diff --git a/src/framework/mlt_properties.h b/src/framework/mlt_properties.h index 449f3630..8aaa8a4b 100644 --- a/src/framework/mlt_properties.h +++ b/src/framework/mlt_properties.h @@ -90,4 +90,7 @@ extern void mlt_properties_lock( mlt_properties self ); extern void mlt_properties_unlock( mlt_properties self ); extern char *mlt_properties_get_time( mlt_properties, const char* name, mlt_time_format ); +extern int mlt_properties_get_int_pos( mlt_properties self, const char *name, int position, int length ); +extern int mlt_properties_set_int_pos( mlt_properties self, const char *name, int value, mlt_keyframe_type keyframe_type, int position, int length ); + #endif diff --git a/src/framework/mlt_property.c b/src/framework/mlt_property.c index 7d8808fb..8604e31f 100644 --- a/src/framework/mlt_property.c +++ b/src/framework/mlt_property.c @@ -971,7 +971,7 @@ int mlt_property_interpolate( mlt_property self, mlt_property p[], double progress, double fps, locale_t locale, mlt_keyframe_type interp ) { int error = 0; - if ( interp != mlt_keyframe_discrete && fps > 0 && + if ( interp != mlt_keyframe_discrete && is_property_numeric( p[1], locale ) && is_property_numeric( p[2], locale ) ) { double value; @@ -1005,9 +1005,19 @@ static void refresh_animation( mlt_property self, double fps, locale_t locale, i if ( !self->animation ) { self->animation = mlt_animation_new(); - mlt_animation_parse( self->animation, self->prop_string, length, fps, locale ); + if ( self->prop_string ) + { + mlt_animation_parse( self->animation, self->prop_string, length, fps, locale ); + } + else + { + mlt_animation_set_length( self->animation, length ); + self->types |= mlt_prop_data; + self->data = self->animation; + self->serialiser = (mlt_serialiser) mlt_animation_serialize; + } } - else + else if ( self->prop_string ) { mlt_animation_refresh( self->animation, self->prop_string, length ); } @@ -1016,7 +1026,7 @@ static void refresh_animation( mlt_property self, double fps, locale_t locale, i double mlt_property_get_double_pos( mlt_property self, double fps, locale_t locale, int position, int length ) { double result; - if ( ( self->types & mlt_prop_string ) && self->prop_string ) + if ( self->animation || ( ( self->types & mlt_prop_string ) && self->prop_string ) ) { struct mlt_animation_item_s item; item.property = mlt_property_init(); @@ -1037,7 +1047,7 @@ double mlt_property_get_double_pos( mlt_property self, double fps, locale_t loca int mlt_property_get_int_pos( mlt_property self, double fps, locale_t locale, int position, int length ) { int result; - if ( ( self->types & mlt_prop_string ) && self->prop_string ) + if ( self->animation || ( ( self->types & mlt_prop_string ) && self->prop_string ) ) { struct mlt_animation_item_s item; item.property = mlt_property_init(); @@ -1067,23 +1077,18 @@ int mlt_property_set_double_pos( mlt_property self, double value, double fps, lo 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 ); + 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 ); - 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; } @@ -1099,22 +1104,17 @@ int mlt_property_set_int_pos( mlt_property self, int value, double fps, locale_t 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 ); + 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 ); - 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/mlt++/MltProperties.cpp b/src/mlt++/MltProperties.cpp index c80756eb..734d2c3b 100644 --- a/src/mlt++/MltProperties.cpp +++ b/src/mlt++/MltProperties.cpp @@ -336,3 +336,13 @@ char *Properties::get_time( const char *name, mlt_time_format format ) { return mlt_properties_get_time( get_properties(), name, format ); } + +int Properties::get_int( const char *name, int position, int length ) +{ + return mlt_properties_get_int_pos( get_properties(), name, position, length ); +} + +int Properties::set( const char *name, int value, int position, int length, mlt_keyframe_type keyframe_type ) +{ + return mlt_properties_set_int_pos( get_properties(), name, value, keyframe_type, position, length ); +} diff --git a/src/mlt++/MltProperties.h b/src/mlt++/MltProperties.h index dfbc5eec..a174708a 100644 --- a/src/mlt++/MltProperties.h +++ b/src/mlt++/MltProperties.h @@ -97,6 +97,9 @@ namespace Mlt int set_lcnumeric( const char *locale ); const char *get_lcnumeric( ); char *get_time( const char *name, mlt_time_format = mlt_time_smpte ); + int get_int( const char *name, int position, int length ); + int set( const char *name, int value, int position, int length, + mlt_keyframe_type keyframe_type = mlt_keyframe_linear ); }; } diff --git a/src/tests/test_properties/test_properties.cpp b/src/tests/test_properties/test_properties.cpp index 206cd694..296b7f35 100644 --- a/src/tests/test_properties/test_properties.cpp +++ b/src/tests/test_properties/test_properties.cpp @@ -658,6 +658,36 @@ private Q_SLOTS: 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)