Forums > Dev

one question about pattr

March 8, 2008 | 8:33 am

Hi,

I am writing a UI matrix-like external.

So far I have something like:

typedef struct t_matrix {
long cells[4][4];
long ncolumns;
long nrows;
} t_matrix;

typedef struct t_myUIobj {
….
t_matrix *matrix;
….
} t_myUIobj;

In the new method I allocate memory for my matrix structure:

x->matrix = (t_matrix *)sysmem_newptr(sizeof(t_matrix));
if (x->matrix == NULL) {
error("out of memory");
return 0;
}

Now, I want to be able to set the cell states with an attribute, so in main I declare:

attr = attr_offset_array_new("cell", _sym_pointer, 3, attrflags,
(method)matrix_cell_get, (method)matrix_cell_set, 0L, 0L);
class_addattr(c, attr);

The 1st arg would be the column, the 2nd arg would be the row and the 3rd arg would be the state of the cell (0-1)

At this point I am stuck with one question:

I just want to get the state of a certain cell. I know the column and the row of the cell I want to get.
However the getter method needs to be prototyped as follows:

static t_max_err matrix_cell_get(t_matrix *x, void *attr, long *argc, t_atom **argv)

and I have no way to pass any arguments (column and row) to this method.
How do I declare the cell getter method ?

Thanks.

- Luigi

————————————————————
THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE SENDER BY E-MAIL AT SUPERBIGIO@YAHOO.COM AND DESTROY ALL COPIES OF THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC 1-207.
————————————————————

Never miss a thing. Make Yahoo your home page.

http://www.yahoo.com/r/hs


March 8, 2008 | 10:07 am

You can’t really do this with attributes – an attribute tends to hold a single value (even if that value consists of a list or a table or whatever). The idea of getting part of an attribute’s value is not part of the model.

I would do this with A_GIMME methods.

"getmatrixcell"
"setmatrixcell"

or whatever. Then, if you want the entire value of the matrix to be available to pattr, you can implement setvalueof and getvalueof and just output a list of the values stored in the matrix.

Alternately, you could create a bunch of attributes: "getcell00", "getcell01", etc. and have access to individual values that way, but what a pain, both to implement and to use.

jb


March 9, 2008 | 1:10 am

Jeremy,

as usual, thanks for your quick response.

Yes, I think I’ll implement it with regular A_GIMME methods.
That’s what makes the most sense in this situation.

Can you expand on this statement, please?

> Then, if you want the entire value of the matrix to be available to pattr, you can implement setvalueof and getvalueof and just output a list of the values stored in the matrix.

I am not sure I understand here…

How would you make the whole matrix available to pattr with the setvalueof and getvalueof methods ?

Thanks again.

- Luigi

—– Original Message —-
From: Jeremy Bernstein
Sent: Saturday, March 8, 2008 2:07:15 AM
Subject: [dev] Re: one question about pattr

You can’t really do this with attributes – an attribute tends to hold a single value (even if that value consists of a list or a table or whatever). The idea of getting part of an attribute’s value is not part of the model.

I would do this with A_GIMME methods.

"getmatrixcell"
"setmatrixcell"

or whatever. Then, if you want the entire value of the matrix to be available to pattr, you can implement setvalueof and getvalueof and just output a list of the values stored in the matrix.

Alternately, you could create a bunch of attributes: "getcell00", "getcell01", etc. and have access to individual values that way, but what a pain, both to implement and to use.

jb

Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping


March 9, 2008 | 1:37 am

On 9 mars 08, at 02:10, Luigi Castelli wrote:

> I am not sure I understand here…
>
> How would you make the whole matrix available to pattr with the
> setvalueof and getvalueof methods ?

You’ll have to unroll it I’d guess.

ej


March 10, 2008 | 10:33 pm

Yes.

This is the way I did a couple of custom function objects. You just
traverse the matrix and append everything into one big ol’ list.

b

On Mar 8, 2008, at 5:37 PM, Emmanuel Jourdan wrote:

> On 9 mars 08, at 02:10, Luigi Castelli wrote:
>
>> I am not sure I understand here…
>>
>> How would you make the whole matrix available to pattr with the
>> setvalueof and getvalueof methods ?
>
>
> You’ll have to unroll it I’d guess.
>
> ej
>

barry threw
Media Art and Technology

San Francisco, CA
Work: 857-544-3967
Email: bthrew (at) gmail (dot) com
Web: http://www.barrythrew.com


March 10, 2008 | 10:36 pm

Here is the code I used…hopefully it makes some sense.

t_max_err function_setvalueof(t_function *x, long ac, t_atom *av)
{
if (ac && av) {
function_clear(x, gensym("clear"), 0, 0);

int i;
t_atom values[2];

for (i = 0; i < ac; i += 2) {
values[0] = *(av + i);
values[1] = *(av + i + 1);
function_list(x, gensym("list"), 2, values);
}
}

return MAX_ERR_NONE;
}

t_max_err function_getvalueof(t_function *x, long *ac, t_atom **av)
{
t_funpair *bp;

long count = 0, size;

for (bp = x->f_list; bp; bp = bp->p_next) {
count++;
}

size = count;

if (ac && av) {
if (*ac && *av) {
// memory has been passed in; use it.
} else {
*av = (t_atom *)getbytes((short)(size * sizeof(t_atom) * 2));
}
}

if (!av)
return;

*ac = count*2;

for (count = 0, bp = x->f_list; bp; bp = bp->p_next, count += 2) {
atom_setfloat(*av+count,bp->p_x);
atom_setfloat(*av+count+1,bp->p_y);
}

return MAX_ERR_NONE;
}

On Mar 8, 2008, at 5:37 PM, Emmanuel Jourdan wrote:

> On 9 mars 08, at 02:10, Luigi Castelli wrote:
>
>> I am not sure I understand here…
>>
>> How would you make the whole matrix available to pattr with the
>> setvalueof and getvalueof methods ?
>
>
> You’ll have to unroll it I’d guess.
>
> ej
>

barry threw
Media Art and Technology

San Francisco, CA
Work: 857-544-3967
Email: bthrew (at) gmail (dot) com
Web: http://www.barrythrew.com


March 11, 2008 | 1:08 am

Hey Barry,

nice to see you are alive and kicking…

Thanks for your suggestion and the code. It does make sense.

The only hesitation I have in implementing something along those lines is the following:
appending all the matrix values into a big ol’ list will easily generate lists that are too large to be safely handled by Max.

For example:

a 64×64 matrix will have to generate a list of 4096 atoms.
a 128×128 matrix will generate a list of 16384 atoms.

As you know, lists of this size are not really Max compliant and I personally avoid them in my code.

Any thoughts ?

Thanks.

- Luigi

————————————————————
THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE SENDER BY E-MAIL AT SUPERBIGIO@YAHOO.COM AND DESTROY ALL COPIES OF THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC 1-207.
————————————————————

—– Original Message —-
From: barry threw
Sent: Monday, March 10, 2008 3:36:33 PM
Subject: Re: [dev] Re: one question about pattr

Here is the code I used…hopefully it makes some sense.

t_max_err function_setvalueof(t_function *x, long ac, t_atom *av)
{
if (ac && av) {
function_clear(x, gensym("clear"), 0, 0);

int i;
t_atom values[2];

for (i = 0; i < ac; i += 2) {
values[0] = *(av + i);
values[1] = *(av + i + 1);
function_list(x, gensym("list"), 2, values);
}
}

return MAX_ERR_NONE;
}

t_max_err function_getvalueof(t_function *x, long *ac, t_atom **av)
{
t_funpair *bp;

long count = 0, size;

for (bp = x->f_list; bp; bp = bp->p_next) {
count++;
}

size = count;

if (ac && av) {
if (*ac && *av) {
// memory has been passed in; use it.
} else {
*av = (t_atom *)getbytes((short)(size * sizeof(t_atom) * 2));
}
}

if (!av)
return;

*ac = count*2;

for (count = 0, bp = x->f_list; bp; bp = bp->p_next, count += 2) {
atom_setfloat(*av+count,bp->p_x);
atom_setfloat(*av+count+1,bp->p_y);
}

return MAX_ERR_NONE;
}

On Mar 8, 2008, at 5:37 PM, Emmanuel Jourdan wrote:

> On 9 mars 08, at 02:10, Luigi Castelli wrote:
>
>> I am not sure I understand here…
>>
>> How would you make the whole matrix available to pattr with the
>> setvalueof and getvalueof methods ?
>
>
> You’ll have to unroll it I’d guess.
>
> ej
>

barry threw
Media Art and Technology

San Francisco, CA
Work: 857-544-3967
Email: bthrew (at) gmail (dot) com
Web: http://www.barrythrew.com

Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


March 11, 2008 | 2:16 am

On Mar 10, 2008, at 6:08 PM, Luigi Castelli wrote:

> a 64×64 matrix will have to generate a list of 4096 atoms.
> a 128×128 matrix will generate a list of 16384 atoms.
>
> As you know, lists of this size are not really Max compliant and I
> personally avoid them in my code.
>
> Any thoughts ?

I might recommend you store as a file and use the filename for pattr.

-Joshua


March 11, 2008 | 6:08 pm

On 11 Mar 2008, at 02:16, Joshua Kit Clayton wrote:

> I might recommend you store as a file and use the filename for pattr.

…or bung them into a database and use pattr for the primary key.

Database support galore for free at http://www.loadbang.net .

– N.

Nick Rothwell / Cassiel.com Limited
http://www.cassiel.com
http://www.myspace.com/cassieldotcom
http://www.last.fm/music/cassiel
http://www.reverbnation.com/cassiel
http://www.linkedin.com/in/cassiel
http://www.loadbang.net


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