Skip to content

Commit

Permalink
Add mlt_properties_anim_set/get_double().
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed May 31, 2013
1 parent e4a0fa0 commit 92b51b2
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 5 deletions.
51 changes: 51 additions & 0 deletions src/framework/mlt_properties.c
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/framework/mlt_properties.h
Expand Up @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions src/framework/mlt_property.c
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down
10 changes: 10 additions & 0 deletions src/mlt++/MltProperties.cpp
Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions src/mlt++/MltProperties.h
Expand Up @@ -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 );
Expand Down
34 changes: 32 additions & 2 deletions src/tests/test_properties/test_properties.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 92b51b2

Please sign in to comment.