attribute turns "none" how to?

Dec 28, 2010 at 3:39pm

attribute turns "none" how to?

sorry if i just did not find it in the docs.

how can i define a (type double) attribute, that turns when the user deletes the value in the inspector?

same behaviour like in the number inspector at minimum and maximum.

i thought it would be a style of CLASS_ATTR_STYLE but obviously it is not..

thanks
klaus

#54135
Dec 28, 2010 at 5:05pm

There’s no style for that. You need to set the attribute type to ATOM, and roll your own gettr/settr methods. That’s what we do for number e.g.

#194779
Dec 28, 2010 at 7:33pm

ok,
thanks for the quick answer.

is there any chance to have a look into number.c ?

klaus

#194780
Dec 28, 2010 at 9:14pm

It probably looks like something like this:

CLASS_ATTR_ATOM(c, "myattr", 0, t_myobject, myattr);
CLASS_ATTR_ACCESSORS(c, "myattr", (method)NULL, (method)myobject_setattr_myattr);
t_max_err myobjet_setattr_myattr(t_myobject *x, void *attr, long ac, t_atom *av)
{
    if (ac && av) {
        if (atom_gettype(av) == A_LONG || atom_gettype(av) == A_FLOAT) {
            x->myattr = *av;
        else
            atom_setsym(&x->myattr, gensym(""));
    } else
        atom_setsym(&x->myattr, gensym(""));

     return MAX_ERR_NONE;
}

forum coding.

#194781
Dec 28, 2010 at 11:23pm

emmanuel, thanks again!
works like a charm

(there is a typo at:
“t_max_err myobjet_ser…” better is:
“t_max_err myobjet_set…

#194782
Dec 29, 2010 at 10:09am

Glad it works, typo fixed.

#194783

You must be logged in to reply to this topic.