Forums > Dev

getting jit_sym_pointer style attributes

January 21, 2007 | 7:34 am

could someone please illustrate how to use the jit_sym_pointer
attribute type? here’s some sample code for roughly what I’m trying
to do:

// jit.foo.c

attr = jit_object_new(_jit_sym_jit_attr_offset, "pointer",
_jit_sym_pointer, attrflags | JIT_ATTR_SET_OPAQUE |
JIT_ATTR_GET_OPAQUE_USER,
(method)0L /*get*/, (method)0L /*set*/, calcoffset(t_jit_foo,
pointer));
jit_class_addattr(_jit_foo_class, attr);

// jit.bar.c
// x->foo is a pointer to a foo object
void *attr = jit_object_attr_get(x->foo, gensym("getpointer"));
long ac;
void *av;
jit_attr_get(x->foo, attr, &ac, &av);

the docs online list a jit_attr_get() method, but I don’t see that
locally.
do I just want to do something with jit_object_method(x->foo, gensym
("getpointer"))?

ultimately I’m trying to move a struct between two objects, am I
approaching this correctly?

best,

r.


January 21, 2007 | 10:04 am

attr = jit_object_new(_jit_sym_jit_attr_offset, "pointer",
_jit_sym_pointer, attrflags | JIT_ATTR_SET_OPAQUE |
JIT_ATTR_GET_OPAQUE_USER,
(method)0L /*get*/,
(method)0L /*set*/, calcoffset(t_jit_foo,
pointer));
jit_class_addattr(_jit_foo_class, attr);

The above code is for creating attributes of objects that are symbol
based. As an example, jit.gl.texture @type is a symbol based
attribute that can take values like "float32", "char", etc. which are
all symbols. If you want to pass a struct between objects, you want a
method, not an attribute and most likely it will be an A_CANT type
attribute that is only accessible from C.

Here’s an example from the init() function

jit_class_addmethod(_jit_myobject_class,
(method)jit_myobject_get_struct, "get_struct",
A_CANT, 0L);

t_struct * jit_myobject_get_struct(t_jit_myobject *x)
{
return x->struct;
}

wes


January 22, 2007 | 7:16 pm

On 07-01-21, at 0204, Wesley Smith wrote:
> attr = jit_object_new(_jit_sym_jit_attr_offset, "pointer",
> _jit_sym_pointer, attrflags | JIT_ATTR_SET_OPAQUE |
> JIT_ATTR_GET_OPAQUE_USER,
> (method)0L /*get*/,
> (method)0L /*set*/, calcoffset(t_jit_foo,
> pointer));
> jit_class_addattr(_jit_foo_class, attr);
>
>
> The above code is for creating attributes of objects that are symbol
> based. As an example, jit.gl.texture @type is a symbol based
> attribute that can take values like "float32", "char", etc. which are
> all symbols. If you want to pass a struct between objects, you want a
> method, not an attribute and most likely it will be an A_CANT type
> attribute that is only accessible from C.
>
thanks wes. I was confused by this bit from the sdk docs:

"The type argument specifies the attribute type, which may be one of
the following symbols: _jit_sym_char, _jit_sym_long,
_jit_sym_float32, _jit_sym_float64, _jit_sym_symbol, _jit_sym_atom,
_jit_sym_object, or _jit_sym_pointer. The latter two are only useful
for private attributes as these types are not exposed to, or
converted from Max message atom values."
(http://cycling74.com/twiki/bin/view/ProductDocumentation/
JitterSdkObjectModel#Attributes)

seems like jit.gl.texture @type is a symbol based attribute that is
at the very least exposed to max, no? and with your explanation it
could be _jit_sym_atom, not _jit_sym_pointer or _jit_sym_object.

> Here’s an example from the init() function
>
> jit_class_addmethod(_jit_myobject_class,
> (method)jit_myobject_get_struct, "get_struct",
> A_CANT, 0L);
>
> t_struct * jit_myobject_get_struct(t_jit_myobject *x)
> {
> return x->struct;
> }
>
yeah this was my initial plan, but I thought I’d see if I could use
the attribute system since it’s already there. thanks.

r.


January 22, 2007 | 7:32 pm

> "The type argument specifies the attribute type, which may be one of
> the following symbols: _jit_sym_char, _jit_sym_long,
> _jit_sym_float32, _jit_sym_float64, _jit_sym_symbol, _jit_sym_atom,
> _jit_sym_object, or _jit_sym_pointer. The latter two are only useful
> for private attributes as these types are not exposed to, or
> converted from Max message atom values."
> (http://cycling74.com/twiki/bin/view/ProductDocumentation/
> JitterSdkObjectModel#Attributes)
>

Wow, you learn something new every day. I’ve never seen
_jit_sym_atom, _jit_sym_object, or _jit_sym_pointer used in any code
before but that could definitely be useful for what you’re trying to
do. To follow up on the example I gave, jit.gl.texture @type is
_jit_sym_symbol. The naming conventions of these variables goes as
follows … _jit_sym prefix means that the variable is a t_symbol * in
the Jitter API. So, _jit_sym_atom would be a t_symbol * in the Jitter
API with the value gensym("atom").

wes


January 22, 2007 | 7:59 pm

On 07-01-22, at 1132, Wesley Smith wrote:
>
> Wow, you learn something new every day. I’ve never seen
> _jit_sym_atom, _jit_sym_object, or _jit_sym_pointer used in any code
> before but that could definitely be useful for what you’re trying to
> do.
>
yep, that’s why I was hoping for a quick example from whoever
conjured them up ;)

r.


January 22, 2007 | 8:05 pm

Ok,
To go back to this:
attrflags = JIT_ATTR_SET_OPAQUE |JIT_ATTR_GET_OPAQUE_USER;

attr = jit_object_new(_jit_sym_jit_attr_offset, "pointer",
_jit_sym_pointer, attrflags
(method)0L /*get*/, (method)0L /*set*/,
calcoffset(t_jit_foo, pointer));
jit_class_addattr(_jit_foo_class, attr);

I misread the code and didn’t notice the _jit_sym_pointer thing.
Basically it wil allow you to store a pointer to some place in memory,
putting the value in the t_jit_foo struct member variable pointer.
Sorry for the confusion. Just try it out and see what happens.

wes


January 22, 2007 | 8:13 pm

FWIW, there’s a bunch of publicly accessible attributes which are of
type atom, and a handful of places where we’ve used object
attributes. I don’t think the pointer attr type has gotten a lot of
use, so there might be bugs there. Just to reiterate the SDK doc,
pointer or object attributes are *exclusively* for private access
from within C.

You can do this Ritchie to share a struct between objects, not that
it’s much more straightforward in this case to use attributes instead
of some other accessor method like Wesley suggested. The pointer or
object atom should be passed back as an A_OBJ atom in the attribute
getter. You should be able to use the standard jit_attr_getobj() call
to retrieve either pointer or object entries.

Let us know if you encounter any problems.

-Joshua


January 22, 2007 | 8:32 pm

On 07-01-22, at 1205, Wesley Smith wrote:
> Ok,
> To go back to this:
> attrflags = JIT_ATTR_SET_OPAQUE |JIT_ATTR_GET_OPAQUE_USER;
>
> attr = jit_object_new(_jit_sym_jit_attr_offset, "pointer",
> _jit_sym_pointer, attrflags
> (method)0L /*get*/, (method)0L /*set*/,
> calcoffset(t_jit_foo, pointer));
> jit_class_addattr(_jit_foo_class, attr);
>
> I misread the code and didn’t notice the _jit_sym_pointer thing.
> Basically it wil allow you to store a pointer to some place in memory,
> putting the value in the t_jit_foo struct member variable pointer.
> Sorry for the confusion. Just try it out and see what happens.
>
yeah I mostly understand attaching the attribute to a pointer in my
source object, but am unclear on how to retrieve it with the
destination object. see my original message and the jit_attr_get()
call that I’m not sure about.

r.


January 22, 2007 | 9:27 pm

On 07-01-22, at 1213, Joshua Kit Clayton wrote:
>
> You can do this Ritchie to share a struct between objects, not that
> it’s much more straightforward in this case to use attributes
> instead of some other accessor method like Wesley suggested. The
> pointer or object atom should be passed back as an A_OBJ atom in
> the attribute getter. You should be able to use the standard
> jit_attr_getobj() call to retrieve either pointer or object entries.
>
thanks joshua. so for a pointer I have to explicitly write a getter,
instead of just passing it’s offset and 0L for the getter method? I
thought it would be easier if that were the case, but with a manual
getter I may just do my own accessor. even though a custom accessor
is likely easier at this point, it’s still nice to try to understand
what’s going on here =)

I don’t see a jit_attr_getobj() call here, did you mean
jit_attr_getsym() or is my sdk out of whack?

r.


January 22, 2007 | 10:14 pm

On Jan 22, 2007, at 1:27 PM, ritchie argue wrote:

> thanks joshua. so for a pointer I have to explicitly write a
> getter, instead of just passing it’s offset and 0L for the getter
> method? I thought it would be easier if that were the case, but
> with a manual getter I may just do my own accessor.

Sorry for any confusion. No, you don’t need a custom getter. Wes
suggested writing an A_CANT method bound to the symbol get
which returns the pointer. Not that many more lines of code than
adding an attribute. The default attribute accessors work fine for
declaring

> I don’t see a jit_attr_getobj() call here, did you mean
> jit_attr_getsym() or is my sdk out of whack?

Sorry, no Jitter API utility function like I thought there was. You
should be able to use the standard max one from ext_obex.h:

t_object* object_attr_getobj(void *x, t_symbol *s);

In general you can use these functions interchangeably with the
Jitter attribute API, as Max and Jitter attributes have been
consolidated since Max 4.5 and Jitter 1.5.

Otherwise, you can just look at the atom returned from a standard ac/
av attribute getter call, and grab the A_OBJ val, as demonstrated in
this utility function.

void *atom_getobj(t_atom *a)
{
t_object *b=NULL;

if (a) {
switch (a->a_type) {
case A_OBJ: b = a->a_w.w_obj; break;
}
}
return b;
}

Let us know if this doesn’t work for you.

-Joshua


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