How to implement @param model in an external object?
I would like to implement @param_name
like syntax an in an external, similar to metro @active 1 @defer 1
. How are those @param_name val
parameters retrieved in the C code? Are there any example or documentation in the SDK ? I could not find any. Thanks.
OK thanks. So I tried to do:
1) add fields in the struct:double m_arg1;
double m_arg2;
2) then add the declaration in main:CLASS_ATTR_DOUBLE(c, "m_arg1", 0, t_faust, m_arg1);
CLASS_ATTR_DOUBLE(c, "m_arg2", 0, t_faust, m_arg2);
I tried to allocate the object with foo @m_arg1 0.5 @m_arg2 1.5
, hoping the m_arg1/m_arg2 would be written with the 0.5/1.5 values. It does not seem to work. Is is supposed to be enough?
Another question: it il possible for an attribute to refer to an arbitrary memory location instead of a field of the struct like m_arg1/m_arg2 described before ?
Sorry Stéphane , I don't have access to my C dev archives from home and can't help much more (I dont even have Xcode at hand)…
But there are some examples using patter in the SDK, just do a multi file search on the SDK folder with "CLASS_ATTR", and you'll find for instance the /basics/attrtest project.
Good luck!
Shouldn't you call attr_args_process() in the _new() function?
I did that and it works, but... as soon as the @param attribute is in place, regular param (thats is without the @ character) are not received anymore in the C++ code (I'm using the anything
method to handle all incoming messages), and @param syntax has to be used. This is not the case for standard Max objects.
So what is the way to have this 1) @param attribute model 2) keep the regular param syntax for messages ?
Sorry I still can't help much (still no Xcode) , and my C is now very rusty but as nobody helped you here I am again.
I found some old code of mine, not sure it will help but I see I used object_attr_setlong () in the setters instead of directly setting the values in the object struct (see the comment). This is the setter for the outputMode function, expecting a long.
class_addmethod(c, (method)sfmarkers_outputMode, "mode", A_LONG, 0);
CLASS_ATTR_LONG (c, "format", 0, t_sfmarkers, outputMode);
CLASS_ATTR_STYLE_LABEL (c, "format", 0, "enumindex", "Markers time format");
CLASS_ATTR_ENUMINDEX (c, "format", 0, "ms sample");
CLASS_ATTR_CATEGORY (c, "format", 0, "sfmarkers~");
CLASS_ATTR_SAVE (c, "format", 0);
void sfmarkers_outputMode (t_sfmarkers *x, long outputMode)
{
if (outputMode != 0 && outputMode != 1)
object_error ((t_object *)x, "OutputMode accepts only 0 or 1");
else
// x->outputMode = outputMode; <- no more with attributes
object_attr_setlong(x, gensym ("format"), outputMode);
}
If you're using C, you're welcome to look at how I did it in mine:
https://github.com/iainctduncan/scheme-for-max/blob/master/s4m/s4m.c
Thanks IAIN DUNCAN for you code sample. I can now use the CLASS_ATTR_ACCESSORS model, but I see that you're defining 2 different functions (s4m_inlets_set
and s4m_outlets_set
in your code) to handle the 2 different cases.
Is there a way to have a unique generic function that would also get the attribute name ? I see the unused t_object *attr
second argument in s4m_inlets_set
and s4m_outlets_set,
but I don't see if it could be used for that purpose...
Thanks.
Good question. Yes, there is a way.
Inside your generic attribute function you can query the attribute for its name using precisely the t_object *attr
argument.
Example:t_symbol *attrname = (t_symbol *)object_method(attr, gensym("getname"));
This way you can use the same accessor method for multiple attributes.
Hope this helps.
- Luigi
Yes it works, thanks a lot!