]> git.sesse.net Git - mlt/commitdiff
Add mlt_properties_anim_set/get_double().
authorDan Dennedy <dan@dennedy.org>
Tue, 28 May 2013 02:08:27 +0000 (19:08 -0700)
committerDan Dennedy <dan@dennedy.org>
Fri, 31 May 2013 23:58:13 +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 2e8097f98baacd076c747b1cbf34035b19cbe898..3fbf2cecaa6cb2b7fe7341c078dba143fa459f85 100644 (file)
@@ -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
index 93c283cd05abcb81be5d1c1d923384cd32f99448..5113f2a93cd8a1599883b4cb9c42fc8653f48595 100644 (file)
@@ -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 );
 
index 84b6e1d29878b654c052cb7856735b63b60c5ab1..b00cc56382efb182ba637b389e51e719fa9ae67e 100644 (file)
@@ -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 )
                {
index e717ec98209fa60938f5ef9f76d4374a61aef478..2df5b58e354d40700f63097cc350375a416dc6c0 100644 (file)
@@ -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 );
index 96d395ab907abddc756008bacb22da53c83536cd..decb7d135056f1f937940b2c68e604056e077c8a 100644 (file)
@@ -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 );
index c17580a448ebfcf1b90d38ff66f3334e1e9949f8..b23b68bad8c9fe4504eec46ee279ebf6c39f3586 100644 (file)
@@ -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();