Dimming attributes in inspector

    Mar 07 2009 | 4:59 pm
    Hi again,
    one more question today...
    I see that inspectors of some objects are able to dim one of their attributes, in response to the value set for another attribute in the same inspector.
    Can anybody tell me or - even better - post a code example on how to accomplish this?
    Thanks a lot.
    - Luigi

    • Mar 08 2009 | 1:23 am
      You can disable an attribute like that:
      object_attr_setdisabled((t_object *)x, gensym("yourattr"), 1);
    • Mar 08 2009 | 2:55 pm
      Thanks Emmanuel,
      so if I understand correctly, the right strategy would be to use object_attr_setdisabled in my object_notify method and check for the state of an attribute every time it changes. Depending on the state, I can use object_attr_setdisabled to dim the required attribute. Am I correct?
      Also, what's the 3rd argument of object_set_disabled?
      - Luigi
    • Mar 08 2009 | 10:42 pm
      The third argument is to specify the disable state, to disable:
      object_attr_setdisabled((t_object *)x, gensym("yourattr"), 1);
      to enable it back:
      object_attr_setdisabled((t_object *)x, gensym("yourattr"), 0);
      You can put that wherever you want. Usual cases though are in attributes accessors or notify method. For instance in the panel object, there's a custom settr for the mode attribute, and depending on the mode state (color or gradient) the disabled state of other attributes are set.
    • Mar 09 2009 | 5:11 pm
      Great, all is clear now.
      Thank you so much, Emmanuel.
      - Luigi
    • Nov 27 2012 | 11:06 pm
      Hi,object_attr_setdisabled method doesn't seem to work with color attributes (we can still set the rgba value). Do you know a method who can be used in this case? Is there a method to make an attribute visible/invisible from the object inspector ? Thanks.
    • Nov 28 2012 | 1:10 am
      There's no way of doing that at the moment. object_attr_setdisabled is all there is.
    • Nov 28 2012 | 12:37 pm
      Hi ej, Thanks for your reply, basically, i'm wondering if there is a way to reverse the action of object_attr_addattr_parse((t_object*)x, "myattr", "invisible", USESYM(long), 1, "1"); ?
    • Nov 28 2012 | 2:54 pm
      Coded from the top of my head WITHOUT testing. Use with caution...
      object_attr_setlong(object_attr_get(x, gensym("myattr")), gensym("invisible"), 0);
      However, notice that it has nothing to do with object_attr_setdisabled(). The above code will simply make an attribute visible/invisible to the inspector, whereas object_attr_setdisabled() will dim the attribute in the inspector, but the disabled attribute will always be visible.
      Also be aware that your code creates the "invisible" attribute with the ATTR_GET_OPAQUE flag set [ the 1 after USESYM(long) ], which means you cannot query the attribute either by Max message, nor C code. Make sure that's what you want...
      Hope this helps.
      - Luigi
    • Nov 28 2012 | 6:21 pm
      @luigi Many thanks, it's what i'm looking for. But it bring me another problem/question : My goal is to control the visibility of my color attribute depending on the value of an other attribute in the same object inspector. This method works well but i need to refresh the object inspector (close and re-open it) to see changes for my color attribute ! is this normal? i dont think so ! the code i use : in my main method :
      CLASS_ATTR_LONG			(c, "togglevisibility", 0, t_myobject, togglevisibility);
      CLASS_ATTR_STYLE_LABEL	(c, "togglevisibility", 0, "onoff", "Toggle Color Attr visibility");
      CLASS_ATTR_RGBA			(c, "mycolor", 0, t_myobject, mycolor);
      CLASS_ATTR_STYLE			(c, "mycolor", 0, "rgba");
      CLASS_ATTR_INVISIBLE		(c, "mycolor", 0);
      in my object notify method :
      t_max_err myobject_notify(t_myobject *x, t_symbol *s, t_symbol *msg, void *sender, void *data)
      	t_symbol *name;
      	if (msg == gensym("attr_modified"))
      		name = (t_symbol *)object_method((t_object *)data, gensym("getname"));
      		if(name == gensym("togglevisibility"))
      			if (x->togglevisibility) object_attr_setlong(object_attr_get(x, gensym("mycolor")), gensym("invisible"), 0);
      			else object_attr_setlong(object_attr_get(x, gensym("mycolor")), gensym("invisible"), 1);
      	return jbox_notify((t_jbox *)x, s, msg, sender, data);
      Can someone tell me what i'm doing wrong or what i'm missing?
    • Nov 29 2012 | 9:26 am
      Hi Eliott,
      I don't think the "invisible" attribute is meant as a way to show/hide attributes in real-time. The most appropriate way to go in your situation would be the object_attr_setdisabled() function, but then again, it doesn't work for color attributes. Usually the way you refresh an attribute value in the inspector is with the object_attr_touch() function, however you are really trying to act on an attribute of an attribute, and I am pretty sure this approach won't work. Sorry I can't help you any further, but what you are trying to accomplish might not be possible with the current SDK.
      Having said this, I would like to be proven wrong by one of the C74 guys...
      - Luigi