Forums > Dev

attributes and "edit" button

July 13, 2011 | 6:57 pm

Is there a way to have an attribute modifiable in the inspector with the grey "Edit" button, which makes the usual white text-editing window pop up? Just like for the "Menu Items" attribute for [umenu]…

Thanks,
Daniele


July 13, 2011 | 7:47 pm

yes there is… use a "text_large" attribute style.

- Luigi


July 13, 2011 | 9:17 pm

Thanks Luigi.
It works, but I’m having some troubles to get it right.
With which kind of attributes can I use this edit menu?
Can’t I use it with a CLASS_ATTR_SYM_VARSIZE attribute (with comma automatically parsed to be the tokens for cutting symbols)?


July 13, 2011 | 10:02 pm

well, I think it depends what you are trying to do with it.

I personally haven’t used it with CLASS_ATTR_SYM_VARSIZE, but I am not sure your approach is gonna work.
If the user inserts numeric values between commas I don’t see how Max could turn them automatically into symbols. You might have to write a custom accessor to do that, but you risk of making things more complicated than they need to be…

A better, more general way might be to use CLASS_ATTR_ATOM_VARSIZE.
You can typecheck the arguments yourself and still parse commas away.

There might be other ideas, but I don’t know exactly your scenario, so I can’t really give you a definite answer.

Hope this helps anyway…

- Luigi


July 13, 2011 | 10:40 pm

Thanks Luigi for your patience.
I’m now trying to define my attribute

CLASS_ATTR_ATOM_VARSIZE(c, "voicenames", 0, t_roll, voicenames_as_atomlist, num_voices, 10);
CLASS_ATTR_STYLE_LABEL(c,"voicenames",0,"text_large","Voice Names");
CLASS_ATTR_DEFAULT_SAVE_PAINT(c,"voicenames",0,"");
CLASS_ATTR_ACCESSORS(c, "voicenames", (method)NULL, (method)myobj_setattr_voicenames);

and fill my "voicenames_as_atomlist" (t_atom* [10]) in the accessor with something like

for (i = 0; i < ac; i++) {
if (atom_gettype(av+i) == A_SYM)
atom_setsym(x->voicenames_as_atomlist[i], atom_getsym(av+i));
else if (atom_gettype(av+i) == A_LONG)
atom_setlong(x->voicenames_as_atomlist[i], atom_getlong(av+i));
[etc.]
}

Yet, although everything seems to be correct with the accessor (and the "voicenames_as_atomlist" seems correctly filled), I only see a bunch of … in my white edit window.
I’m pretty sure I’m missing some basic step of the thing…


July 14, 2011 | 12:09 am

Assuming you are writing a UI object, I can see that you are not initializing your voicenames_as_atomlist[] array.
You have an array of 10 atoms, so you could do something like the following to solve your problem:

CLASS_ATTR_DEFAULT_SAVE_PAINT(c,"voicenames",0,"0 0 0 0 0 0 0 0 0 0");

or if you prefer:

CLASS_ATTR_DEFAULT_SAVE_PAINT(c,"voicenames",0,"         ");

The above will not work in a standard – not UI – object and you will have to initialize your atom list in the new method.

Cheers.

- Luigi


July 14, 2011 | 1:41 am

Hello Luigi, thanks again.
Actually, I had it initialized in the new method. Plus, even if I changed all things by hands in the inspector, I always ended up with lists.

I switched back to standard SYM_ARRAYS (I feel at home!) and everything works fine. No need of comma parsing and all… Only I have no white editor! :-)


July 14, 2011 | 7:51 am

Hi Daniele,

I didn’t try it personally, but did you consider using atom_setparse() in your accessor?

Best,
Ádám


July 14, 2011 | 12:10 pm

Uhm… thanks Ádám, but I don’t completely understand: does it mean that my "text_large" attribute should be a long single string, which then should be only parsed internally?

Meanwhile I have solved the issue with the CLASS_ATTR_ATOM_VARSIZE (just a rough programming error).
I was just wondering if there were a way to parse automatically a list of atoms with respect to commas (as the umenu object does). As far as I know atom_setparse() parses an unique string into a sequence of atoms, isn’t it?


July 14, 2011 | 1:02 pm

Yes, that was my idea (the ‘using a single large string and then parse its content internally’). But as I told, I didn’t test it, so I can’t tell whether this was more efficient or not than the use of CLASS_ATTR_ATOM_VARSIZE…


Viewing 10 posts - 1 through 10 (of 10 total)