This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Frei0r parameter defaults

Tags: None
(comma "," separated)
markoc
Registered Member
Posts
342
Karma
1

Frei0r parameter defaults

Sun Feb 07, 2010 4:16 pm
I am trying my hand at writing Frei0r plugins, and have a question regarding parameter handling in Kdenlive.

The problem is the following:
I assign default values to the parameters in the constructor function.
But when I add the effect in Kdenlive, it comes up with parameters set to zeros.
I thought this was some bug of mine, but if I try the same plugin in Open Movie Editor, it does come up with the default parameters as set in the constructor function.

Putting some printf into the functions, I can see that after calling the constructor, Kdenlive first calls "get parameters" and then "set parameters".
Although the "get parameters" call returns the correct defaut value from the constructor, the following "set parameters" call comes with zero!

Below is an example of a "minimal possible Frei0r plugin", that displays this behaviour. (It is not meant to do anything useful, just draws a blue square whose size is determined by a single parameter).

To see the printouts, you must call Kdenlive from a console.

What should I do to get the desired defaults in Kdenlive?




-----------------------------------------------------------------------------
//frajer.c poskus izdelave Frei0r plugina
// samo narise plav kvadrat v sredo slike

// MC jan 2009

//compile: gcc -c -fPIC frajer.c -o frajer.o
//link: gcc -shared -o frajer.so frajer.o

#include
#include

//----------------------------------------
//struktura za instanco efekta
typedef struct
{
int h;
int w;
int size;
} inst;


//***********************************************
// OBVEZNE FREI0R FUNKCIJE

//-----------------------------------------------
int f0r_init()
{
return 1;
}

//------------------------------------------------
void f0r_deinit()
{
}

//-----------------------------------------------
void f0r_get_plugin_info(f0r_plugin_info_t* info)
{

info->name="frajer";
info->author="Marko Cebokli";
info->plugin_type=F0R_PLUGIN_TYPE_FILTER;
info->color_model=F0R_COLOR_MODEL_RGBA8888;
info->frei0r_version=FREI0R_MAJOR_VERSION;
info->major_version=0;
info->minor_version=1;
info->num_params=1;
info->explanation="";
}

//--------------------------------------------------
void f0r_get_param_info(f0r_param_info_t* info, int param_index)
{
switch(param_index)
{
case 0:
info->name = "Size";
info->type = F0R_PARAM_DOUBLE;
info->explanation = "Size of square";
break;
}
}

//----------------------------------------------
f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
{
inst *in;

in=malloc(sizeof(inst));
in->w=width;
in->h=height;
in->size=100;

printf("Construct, default=%d\n",in->size);
return (f0r_instance_t)in;
}

//---------------------------------------------------
void f0r_destruct(f0r_instance_t instance)
{
free(instance);
}

//-----------------------------------------------------
void f0r_set_param_value(f0r_instance_t instance, f0r_param_t parm, int param_index)
{
inst *p;
double tmpf;

p=(inst*)instance;

switch(param_index)
{
case 0: //f
tmpf=*(double*)parm;
p->size=(int)(tmpf*200.0);
printf("Set parm, received %f\n", *(double*)parm, p->size);
break;
}
}

//--------------------------------------------------
void f0r_get_param_value(f0r_instance_t instance, f0r_param_t param, int param_index)
{
inst *p;
double tmpf;

p=(inst*)instance;

switch(param_index)
{
case 0: //f
tmpf=(float)p->size/200.0;
*((double*)param)=tmpf;
printf("Get parm, sent %f\n", *(double*)param);
break;
}
}

//-------------------------------------------------
void f0r_update(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe)
{
inst *in;
int size;
int i,j;

in=(inst*)instance;
size=in->h*in->w*4;

memcpy(outframe, inframe, size);

for (i=(in->h/2-in->size); i<(in->h/2+in->size);i++)
for (j=(in->w/2-in->size); j<(in->w/2+in->size);j++)
outframe[i*in->w+j]=0x00FF0000; //plava barva (INTEL!)

printf("Update, size=%d\n",in->size);
}

//**********************************************************
markoc
Registered Member
Posts
342
Karma
1

Re: Frei0r parameter defaults

Sun Feb 07, 2010 4:19 pm
the code get mutilated a bit when inserted, the includes should be frei0r.h and string.h
ttill
Registered Member
Posts
372
Karma
0

Re: Frei0r parameter defaults

Sat Feb 13, 2010 9:28 am
If you add a xml for your effect in the kdenlive effects folder your are able to set a default value.
markoc
Registered Member
Posts
342
Karma
1

Re: Frei0r parameter defaults

Sun Feb 14, 2010 5:09 pm
Thanks, this works. I've written it and put it in /usr/share/kde4/apps/kdenlive/effects

There is also a simpler way, just set the desired values and then click "save" button in the effects window. This will automatically write an xml file and put it in ~/.kde4/apps/kdenlive/effects - but it will show up as a new effect on the list.


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], daret, Evergrowing, Google [Bot], sandyvee, Sogou [Bot]