]> git.sesse.net Git - mlt/commitdiff
Add mlt_properties_anim_set/get() for string.
authorDan Dennedy <dan@dennedy.org>
Tue, 28 May 2013 03:35:59 +0000 (20:35 -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/framework/mlt_property.h
src/mlt++/MltProperties.cpp
src/mlt++/MltProperties.h
src/tests/test_properties/test_properties.cpp

index 3fbf2cecaa6cb2b7fe7341c078dba143fa459f85..a8cef7d163a88e7c5196664e3af52a8786dc95b0 100644 (file)
@@ -700,9 +700,19 @@ int mlt_properties_set( mlt_properties self, const char *name, const char *value
 
                        // Determine the value
                        if ( isdigit( id[ 0 ] ) )
-                               current = atof( id );
+                       {
+#if defined(__GLIBC__) || defined(__DARWIN__)
+                               property_list *list = self->local;
+                               if ( list->locale )
+                                       current = strtod_l( id, NULL, list->locale );
+#endif
+                               else
+                                       current = strtod( id, NULL );
+                       }
                        else
+                       {
                                current = mlt_properties_get_double( self, id );
+                       }
 
                        // Apply the operation
                        switch( op )
@@ -2057,6 +2067,62 @@ char *mlt_properties_get_time( mlt_properties self, const char* name, mlt_time_f
        return NULL;
 }
 
+/** Get a string value by name.
+ *
+ * Do not free the returned string. It's lifetime is controlled by the property
+ * and this properties object.
+ * \public \memberof mlt_properties_s
+ * \param self a properties list
+ * \param name the property to get
+ * \return the property's string value or NULL if it does not exist
+ */
+
+char* mlt_properties_anim_get( 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 );
+       mlt_property value = mlt_properties_find( self, name );
+       property_list *list = self->local;
+       return value == NULL ? NULL : mlt_property_anim_get_string( value, fps, list->locale, position, length );
+}
+
+/** Set a property to a string.
+ *
+ * The event "property-changed" is fired after the property has been set.
+ *
+ * This makes a copy of the string value you supply.
+ * \public \memberof mlt_properties_s
+ * \param self a properties list
+ * \param name the property to set
+ * \param value the property's new value
+ * \return true if error
+ */
+
+int mlt_properties_anim_set( mlt_properties self, const char *name, const char *value, 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 )
+       {
+               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_string( property, value,
+                       fps, list->locale, position, length );
+               mlt_properties_do_mirror( self, name );
+       }
+
+       mlt_events_fire( self, "property-changed", name, NULL );
+
+       return error;
+}
+
 /** Get an integer associated to the name at a frame position.
  *
  * \public \memberof mlt_properties_s
index 5113f2a93cd8a1599883b4cb9c42fc8653f48595..8c0d0a3c945530df590e11a9ae2fb2c4879e1d07 100644 (file)
@@ -90,6 +90,8 @@ 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 char* mlt_properties_anim_get( mlt_properties self, const char *name, int position, int length );
+extern int mlt_properties_anim_set( mlt_properties self, const char *name, const char *value, int position, int length );
 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 );
index b00cc56382efb182ba637b389e51e719fa9ae67e..bbc02ee0d7c49940dcea22bbdbf7e15a34fb2104 100644 (file)
@@ -1134,6 +1134,37 @@ int mlt_property_anim_get_int( mlt_property self, double fps, locale_t locale, i
        return result;
 }
 
+char* mlt_property_anim_get_string( mlt_property self, double fps, locale_t locale, int position, int length )
+{
+       char *result;
+       if ( self->animation || ( ( self->types & mlt_prop_string ) && self->prop_string ) )
+       {
+               struct mlt_animation_item_s item;
+               item.property = mlt_property_init();
+
+               if ( !self->animation )
+                       refresh_animation( self, fps, locale, length );
+               mlt_animation_get_item( self->animation, &item, position );
+
+               pthread_mutex_lock( &self->mutex );
+               if ( self->prop_string )
+                       free( self->prop_string );
+               self->prop_string = mlt_property_get_string_l( item.property, locale );
+               if ( self->prop_string )
+                       self->prop_string = strdup( self->prop_string );
+               self->types |= mlt_prop_string;
+               pthread_mutex_unlock( &self->mutex );
+
+               result = self->prop_string;
+               mlt_property_close( item.property );
+       }
+       else
+       {
+               result = mlt_property_get_string_l( self, locale );
+       }
+       return result;
+}
+
 /** Set a property animation keyframe to a real number.
  *
  * \public \memberof mlt_property_s
@@ -1188,6 +1219,24 @@ int mlt_property_anim_set_int( mlt_property self, int value, double fps, locale_
        return result;
 }
 
+int mlt_property_anim_set_string( mlt_property self, const char *value, double fps, locale_t locale, int position, int length )
+{
+       int result;
+       struct mlt_animation_item_s item;
+
+       item.property = mlt_property_init();
+       item.frame = position;
+       item.keyframe_type = mlt_keyframe_discrete;
+       mlt_property_set_string( 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 );
+
+       return result;
+}
+
 static char* serialise_mlt_rect( mlt_rect *rect, int length )
 {
        char* result = calloc( 1, 100 );
index bc3fb591a7da48b812721b28821f7091e4d735be..1b4285db48f770f0f6d792d90881ed5f5df7c456 100644 (file)
@@ -58,10 +58,13 @@ 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_anim_get_double( mlt_property self, double fps, locale_t locale, int position, int length );
 extern int mlt_property_anim_get_int( mlt_property self, double fps, locale_t locale, int position, int length );
+extern char* mlt_property_anim_get_string( mlt_property self, double fps, locale_t locale, int position, int length );
 extern int mlt_property_anim_set_double( mlt_property self, double value, double fps, locale_t locale,
-                                        mlt_keyframe_type keyframe_type, int position, int length );
+                                         mlt_keyframe_type keyframe_type, int position, int length );
 extern int mlt_property_anim_set_int( mlt_property self, int value, double fps, locale_t locale,
-                                     mlt_keyframe_type keyframe_type, int position, int length );
+                                      mlt_keyframe_type keyframe_type, int position, int length );
+extern int mlt_property_anim_set_string( mlt_property self, const char *value, double fps, locale_t locale,
+                                         int position, int length );
 extern int mlt_property_set_rect( mlt_property self, mlt_rect value );
 extern mlt_rect mlt_property_get_rect( mlt_property self, locale_t locale );
 extern int mlt_property_anim_set_rect( mlt_property self, mlt_rect value, double fps, locale_t locale,
index 2df5b58e354d40700f63097cc350375a416dc6c0..e493a36cc6856b870dd6e6029bb15cb82ce048c5 100644 (file)
@@ -337,6 +337,16 @@ char *Properties::get_time( const char *name, mlt_time_format format )
        return mlt_properties_get_time( get_properties(), name, format );
 }
 
+char *Properties::anim_get( const char *name, int position, int length )
+{
+       return mlt_properties_anim_get( get_properties(), name, position, length );
+}
+
+int Properties::anim_set( const char *name, const char *value, int position, int length )
+{
+       return mlt_properties_anim_set( get_properties(), name, value, position, length );
+}
+
 int Properties::anim_get_int( const char *name, int position, int length )
 {
        return mlt_properties_anim_get_int( get_properties(), name, position, length );
index decb7d135056f1f937940b2c68e604056e077c8a..6a710e4bf03f419a79c5b64ee827696e892957c2 100644 (file)
@@ -98,6 +98,8 @@ namespace Mlt
                        const char *get_lcnumeric( );
                        char *get_time( const char *name, mlt_time_format = mlt_time_smpte );
 
+                       char* anim_get( const char *name, int position, int length );
+                       int anim_set( const char *name, const char *value, int position, int length );
                        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 );
index b23b68bad8c9fe4504eec46ee279ebf6c39f3586..db02688cd02f7a83fef706889cbccf0c9c13bd68 100644 (file)
@@ -685,6 +685,19 @@ private Q_SLOTS:
         QCOMPARE(p.anim_get_double("foo", 50, len), 200.0);
     }
 
+    void PropertiesStringAnimation()
+    {
+        Properties p;
+        int len = 50;
+        p.anim_set("key", "foo", 10, len);
+        p.anim_set("key", "bar", 30, len);
+        QCOMPARE(p.get("key"), "10|=foo;30|=bar");
+        p.set("key", "0=; 10=foo bar; 30=hello world");
+        QCOMPARE(p.anim_get("key",  1, len), "");
+        QCOMPARE(p.anim_get("key", 15, len), "foo bar");
+        QCOMPARE(p.anim_get("key", 45, len), "hello world");
+    }
+
     void test_mlt_rect()
     {
         mlt_property p = mlt_property_init();