]> git.sesse.net Git - mlt/commitdiff
Add mlt_properties_set/get_int_pos and Properties::set/get_int.
authorDan Dennedy <dan@dennedy.org>
Thu, 23 May 2013 03:14:55 +0000 (20:14 -0700)
committerDan Dennedy <dan@dennedy.org>
Fri, 31 May 2013 23:58:12 +0000 (16:58 -0700)
src/framework/mlt_properties.c
src/framework/mlt_properties.h
src/framework/mlt_property.c
src/mlt++/MltProperties.cpp
src/mlt++/MltProperties.h
src/tests/test_properties/test_properties.cpp

index 6f826e58d8454219bac8f0e85dd724b64347f508..e96a1307e08a54ce65a83f5ad9bd0e6d6f4cbbb0 100644 (file)
@@ -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;
+}
+
index 449f3630706aaef1e5049fa9747ad5d621a8c2a8..8aaa8a4b2ec64d88f90b5951733592aa12f5ad8a 100644 (file)
@@ -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
index 7d8808fb53d46e34f61584ff81ee6a513e09bc83..8604e31f1a5aa60b6c7084f4a3db0fd92bac2745 100644 (file)
@@ -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;
 }
index c80756eb17abe013df6be19d918387dd11a4be45..734d2c3babf1954acf6f64b750aa3016318d62c0 100644 (file)
@@ -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 );
+}
index dfbc5eecdd85c5894e00e77ed5d1767b6c02f695..a174708abf071bd9956856e78dca1414f6744268 100644 (file)
@@ -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 );
        };
 }
 
index 206cd6943f12e1b8580dfc100e97d1a3e653826e..296b7f35834b86d406ce2a7d30991bbf122bbec4 100644 (file)
@@ -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)