How to implement @param model in an external object?

    Apr 24 2020 | 7:18 am
    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.

    • Apr 24 2020 | 9:10 am
    • Apr 24 2020 | 12:13 pm
      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 ?
    • Apr 24 2020 | 12:45 pm
      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!
    • Apr 24 2020 | 12:52 pm
      Shouldn't you call attr_args_process() in the _new() function?
    • May 11 2020 | 2:52 pm
      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 anythingmethod 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 ?
    • May 11 2020 | 3:51 pm
      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");
      		// x->outputMode = outputMode;  <- no more with attributes
              object_attr_setlong(x, gensym ("format"), outputMode);
    • May 11 2020 | 4:18 pm
      If you're using C, you're welcome to look at how I did it in mine:
    • May 12 2020 | 3:02 am
      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_setin 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.
    • May 12 2020 | 7:44 am
      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
    • May 12 2020 | 10:49 am
      Yes it works, thanks a lot!