calling attribute setters for default values at startup

Alexis Baskind's icon

Dear all,

Each time I code an external, I am facing a very basic question for which I never found a clean answer: how to properly set default values of the attributes in the new methods with custom setters?

For instance, if the new() method looks like the one in the API doc, i.e.:
void *myobject_new(t_symbol *s, long ac, t_atom *av)
{
    t_myobject *x = NULL;

    if (x=(t_myobject *)object_alloc(myobject_class))
    {
    // initialize any data before processing
    // attributes to avoid overwriting
    // attribute argument-set values
        x->data = 0;

    // process attr args, if any
    attr_args_process(x, ac, av);
}
return x;

This is ok as long as the attribute "data" does not have a custom setter. But if it has, then as far as I know, the setter is not being called at all in this method.

So my question: how to define default attribute values in the new() methods and be sure that all setters are called?

Best

Alexis

Iain Duncan's icon

I don't have an answer, but I'd like to know too!

Timothy Place's icon

Hi,

In your new method, you should be able to call object_attr_setfloat() and friends to accomplish this.

Cheers!

Alexis Baskind's icon

Great, I didn't know that the object_attr_setXXX also trigger the setters.

Thanks for the answer,

Alexis