jit_matrix_newcopy()

Jan 20, 2008 at 7:35pm

jit_matrix_newcopy()

Hi,
I’m trying to use jit_matrix_newcopy(), but no matter what I try it seems to
return an empty or invalid matrix.

void *m_copy = jit_object_method(m, _jit_sym_newcopy, 0L);

and

void *m_copy = jit_object_method(m, _jit_sym_newcopy, _jit_sym_newcopy, 0L);

both without luck. I know m is a valid matrix, because if I use m directly
in the follow up code everything is fine. The reason why i want to copy it
is that I’m doing some destructive operations on it and its not copied by
default because I’m not using the MOP. Am I overlooking something?

Thijs

#35455
Jan 21, 2008 at 1:18am

Hi Thijs,

Two possibilities I can think of:

1. You might be calling this on a t_mop_io object and not actually on
a t_jit_matrix object. It is actually a t_mop_io object which is
passed in to most matrix_calc methods and this object contains the
actual matrix (and requires calling getmatrix to get the real matrix
pointer). So this might be a possibility.

2. You are expecting the data to be copied. As it currently stands
the data itself is not copied and it is simply equivalent to calling
getinfo on the source and then object_new(_jit_sym_jit_matrix,
&info). You need to call the frommatrix method on the destination
with the source to copy the data.

Hope this helps. If not, please send us more example code which would
better determine the context you are trying to do this in and
specifically what you are trying to do.

- Joshua

On Jan 20, 2008, at 11:35 AM, Thijs Koerselman wrote:

> Hi,
>
> I’m trying to use jit_matrix_newcopy(), but no matter what I try it
> seems to return an empty or invalid matrix.
>
> void *m_copy = jit_object_method(m, _jit_sym_newcopy, 0L);
>
> and
>
> void *m_copy = jit_object_method(m, _jit_sym_newcopy,
> _jit_sym_newcopy, 0L);
>
> both without luck. I know m is a valid matrix, because if I use m
> directly in the follow up code everything is fine. The reason why i
> want to copy it is that I’m doing some destructive operations on it
> and its not copied by default because I’m not using the MOP. Am I
> overlooking something?
>
> Thijs
>
>

#120898
Jan 21, 2008 at 11:53pm

Hi Joshua,

So the data is not being copied the way I’m currently trying to do it, but
I’m not working with t_mop_io objects. So even though its not what I
intended it shouldn’t make a difference to my output at the moment. I posted
a bit of my code below, please have a look, maybe I’m doing something
stupid. The first bit is taken literally from the jit_gl_videoplane example.
The reason for copying this is that my object is ob3d, so there’s no MOP.
The incoming matrix is altered destructively. That goes against how jitter
objects normally function, because it affects all object using that same
matrix as their input. Atm I’m solving that by just putting an extra
jit.matrix object in front of my one, so the original data is copied and
thus still available to other object in the patch in its original form.

What would be the easiest way to copy the data? I’m a bit puzzled by the
_matrix_conv_info struct. Is that optional? I just like to make a plain 1:1
copy.

Thijs

void foo_jit_matrix(foo *x, t_symbol *s, int argc, t_atom *argv)

{

t_symbol *name;

void *m, m_copy;

if ((name=jit_atom_getsym(argv)) != _jit_sym_nothing) {

m = jit_object_findregistered(name);

if (!m) {

error(“foo: couldn’t get matrix object!”);

return;

}

}

// copy input matrix because we do destructive things to it

m_copy = jit_object_method(m, _jit_sym_newcopy, 0L);

// process the incoming matrix

foo_matrix_calc(x, m);

}

void foo_matrix_calc(foo *x, void *in_matrix)

{

long in_savelock;

t_jit_matrix_info in_minfo;

char *in_bp;

long dimcount,planecount,dim[JIT_MATRIX_MAX_DIMCOUNT];

// lock matrix

in_savelock = (long) jit_object_method(in_matrix,_jit_sym_lock,1);

// get info

jit_object_method(in_matrix,_jit_sym_getinfo,&in_minfo);

// get data pointer

jit_object_method(in_matrix,_jit_sym_getdata,&in_bp);

etc.


On Jan 21, 2008 1:18 AM, Joshua Kit Clayton wrote:

> Hi Thijs,
>
> Two possibilities I can think of:
>
> 1. You might be calling this on a t_mop_io object and not actually on
> a t_jit_matrix object. It is actually a t_mop_io object which is
> passed in to most matrix_calc methods and this object contains the
> actual matrix (and requires calling getmatrix to get the real matrix
> pointer). So this might be a possibility.
>
> 2. You are expecting the data to be copied. As it currently stands
> the data itself is not copied and it is simply equivalent to calling
> getinfo on the source and then object_new(_jit_sym_jit_matrix,
> &info). You need to call the frommatrix method on the destination
> with the source to copy the data.
>
> Hope this helps. If not, please send us more example code which would
> better determine the context you are trying to do this in and
> specifically what you are trying to do.
>
> – Joshua
>
>
> On Jan 20, 2008, at 11:35 AM, Thijs Koerselman wrote:
>
> > Hi,
> >
> > I’m trying to use jit_matrix_newcopy(), but no matter what I try it
> > seems to return an empty or invalid matrix.
> >
> > void *m_copy = jit_object_method(m, _jit_sym_newcopy, 0L);
> >
> > and
> >
> > void *m_copy = jit_object_method(m, _jit_sym_newcopy,
> > _jit_sym_newcopy, 0L);
> >
> > both without luck. I know m is a valid matrix, because if I use m
> > directly in the follow up code everything is fine. The reason why i
> > want to copy it is that I’m doing some destructive operations on it
> > and its not copied by default because I’m not using the MOP. Am I
> > overlooking something?
> >
> > Thijs
> >
> >
>
>

http://www.nano-soundworks.com

#120899
Jan 21, 2008 at 11:55pm

oops, correction:

foo_matrix_calc (x, m);

should be

foo_matrix_calc (x, m_copy);

On Jan 21, 2008 11:53 PM, Thijs Koerselman

wrote:

> Hi Joshua,
>
> So the data is not being copied the way I’m currently trying to do it, but
> I’m not working with t_mop_io objects. So even though its not what I
> intended it shouldn’t make a difference to my output at the moment. I posted
> a bit of my code below, please have a look, maybe I’m doing something
> stupid. The first bit is taken literally from the jit_gl_videoplane example.
>
> The reason for copying this is that my object is ob3d, so there’s no MOP.
> The incoming matrix is altered destructively. That goes against how jitter
> objects normally function, because it affects all object using that same
> matrix as their input. Atm I’m solving that by just putting an extra
> jit.matrix object in front of my one, so the original data is copied and
> thus still available to other object in the patch in its original form.
>
> What would be the easiest way to copy the data? I’m a bit puzzled by the
> _matrix_conv_info struct. Is that optional? I just like to make a plain 1:1
> copy.
>
> Thijs
>
>
> void foo_jit_matrix(foo *x, t_symbol *s, int argc, t_atom *argv)
>
> {
>
> t_symbol *name;
>
> void *m, m_copy;
>
> if ((name=jit_atom_getsym (argv)) != _jit_sym_nothing) {
>
> m = jit_object_findregistered (name);
>
> if (!m) {
>
> error (“foo: couldn’t get matrix object!”);
>
> return;
>
> }
>
> }
>
>
> // copy input matrix because we do destructive things to it
>
> m_copy = jit_object_method (m, _jit_sym_newcopy, 0L);
>
>
> // process the incoming matrix
>
> foo_matrix_calc (x, m);
>
> }
>
>
> void foo_matrix_calc(foo *x, void *in_matrix)
>
> {
>
> long in_savelock;
>
> t_jit_matrix_info in_minfo;
>
> char *in_bp;
>
> long dimcount,planecount,dim[JIT_MATRIX_MAX_DIMCOUNT ];
>
>
> // lock matrix
>
> in_savelock = (long) jit_object_method (in_matrix,_jit_sym_lock,1);
>
> // get info
>
> jit_object_method(in_matrix,_jit_sym_getinfo ,&in_minfo);
>
> // get data pointer
>
> jit_object_method(in_matrix,_jit_sym_getdata ,&in_bp);
>
>
> etc.
> …
> …
> …
>
>
>
> On Jan 21, 2008 1:18 AM, Joshua Kit Clayton wrote:
>
> > Hi Thijs,
> >
> > Two possibilities I can think of:
> >
> > 1. You might be calling this on a t_mop_io object and not actually on
> > a t_jit_matrix object. It is actually a t_mop_io object which is
> > passed in to most matrix_calc methods and this object contains the
> > actual matrix (and requires calling getmatrix to get the real matrix
> > pointer). So this might be a possibility.
> >
> > 2. You are expecting the data to be copied. As it currently stands
> > the data itself is not copied and it is simply equivalent to calling
> > getinfo on the source and then object_new(_jit_sym_jit_matrix,
> > &info). You need to call the frommatrix method on the destination
> > with the source to copy the data.
> >
> > Hope this helps. If not, please send us more example code which would
> > better determine the context you are trying to do this in and
> > specifically what you are trying to do.
> >
> > – Joshua
> >
> >
> > On Jan 20, 2008, at 11:35 AM, Thijs Koerselman wrote:
> >
> > > Hi,
> > >
> > > I’m trying to use jit_matrix_newcopy(), but no matter what I try it
> > > seems to return an empty or invalid matrix.
> > >
> > > void *m_copy = jit_object_method(m, _jit_sym_newcopy, 0L);
> > >
> > > and
> > >
> > > void *m_copy = jit_object_method(m, _jit_sym_newcopy,
> > > _jit_sym_newcopy, 0L);
> > >
> > > both without luck. I know m is a valid matrix, because if I use m
> > > directly in the follow up code everything is fine. The reason why i
> > > want to copy it is that I’m doing some destructive operations on it
> > > and its not copied by default because I’m not using the MOP. Am I
> > > overlooking something?
> > >
> > > Thijs
> > >
> > >
> >
> >
>
>
>
> –
> http://www.nano-soundworks.com
>

http://www.nano-soundworks.com

#120900
Jan 22, 2008 at 12:19am

Like Joshua suggested, I think you want:

jit_object_method(m,_jit_sym_getinfo,&info);

m_copy = jit_object_new(_jit_sym_jit_matrix, &info); //Create the matrix
//jit_object_method(m_copy,_jit_sym_getinfo,&info); //If the matrix already exists

jit_object_method(m_copy,_jit_sym_frommatrix,m,NULL);

instead of:

m_copy = jit_object_method (m, _jit_sym_newcopy, 0L);

Jean-Marc

Thijs Koerselman wrote:
> Hi Joshua,
>
> So the data is not being copied the way I’m currently trying to do it,
> but I’m not working with t_mop_io objects. So even though its not what
> I intended it shouldn’t make a difference to my output at the moment.
> I posted a bit of my code below, please have a look, maybe I’m doing
> something stupid. The first bit is taken literally from the
> jit_gl_videoplane example.
>
> The reason for copying this is that my object is ob3d, so there’s no
> MOP. The incoming matrix is altered destructively. That goes against
> how jitter objects normally function, because it affects all object
> using that same matrix as their input. Atm I’m solving that by just
> putting an extra jit.matrix object in front of my one, so the original
> data is copied and thus still available to other object in the patch
> in its original form.
>
> What would be the easiest way to copy the data? I’m a bit puzzled by
> the _matrix_conv_info struct. Is that optional? I just like to make a
> plain 1:1 copy.
>
> Thijs
>
>
> void foo_jit_matrix(foo *x, t_symbol *s, int argc, t_atom *argv)
>
> {
>
> t_symbol *name;
>
> void *m, m_copy;
>
> if ((name=jit_atom_getsym (argv)) != _jit_sym_nothing) {
>
> m = jit_object_findregistered (name);
>
> if (!m) {
>
> error (“foo: couldn’t get matrix object!”);
>
> return;
>
> }
>
> }
>
>
> // copy input matrix because we do destructive things to it
>
> m_copy = jit_object_method (m, _jit_sym_newcopy, 0L);
>
>
> // process the incoming matrix
>
> foo_matrix_calc (x, m);
>
> }
>
>
> void foo_matrix_calc(foo *x, void *in_matrix)
>
> {
>
> long in_savelock;
>
> t_jit_matrix_info in_minfo;
>
> char *in_bp;
>
> long dimcount,planecount,dim[JIT_MATRIX_MAX_DIMCOUNT ];
>
>
> // lock matrix
>
> in_savelock = (long) jit_object_method (in_matrix,_jit_sym_lock,1);
>
> // get info
>
> jit_object_method(in_matrix,_jit_sym_getinfo ,&in_minfo);
>
> // get data pointer
>
> jit_object_method(in_matrix,_jit_sym_getdata ,&in_bp);
>
>
> etc.
> …
> …
> …
>
>
>
> On Jan 21, 2008 1:18 AM, Joshua Kit Clayton
> > wrote:
>
> Hi Thijs,
>
> Two possibilities I can think of:
>
> 1. You might be calling this on a t_mop_io object and not actually on
> a t_jit_matrix object. It is actually a t_mop_io object which is
> passed in to most matrix_calc methods and this object contains the
> actual matrix (and requires calling getmatrix to get the real matrix
> pointer). So this might be a possibility.
>
> 2. You are expecting the data to be copied. As it currently stands
> the data itself is not copied and it is simply equivalent to calling
> getinfo on the source and then object_new(_jit_sym_jit_matrix,
> &info). You need to call the frommatrix method on the destination
> with the source to copy the data.
>
> Hope this helps. If not, please send us more example code which would
> better determine the context you are trying to do this in and
> specifically what you are trying to do.
>
> – Joshua
>
>
> On Jan 20, 2008, at 11:35 AM, Thijs Koerselman wrote:
>
> > Hi,
> >
> > I’m trying to use jit_matrix_newcopy(), but no matter what I try it
> > seems to return an empty or invalid matrix.
> >
> > void *m_copy = jit_object_method(m, _jit_sym_newcopy, 0L);
> >
> > and
> >
> > void *m_copy = jit_object_method(m, _jit_sym_newcopy,
> > _jit_sym_newcopy, 0L);
> >
> > both without luck. I know m is a valid matrix, because if I use m
> > directly in the follow up code everything is fine. The reason why i
> > want to copy it is that I’m doing some destructive operations on it
> > and its not copied by default because I’m not using the MOP. Am I
> > overlooking something?
> >
> > Thijs
> >
> >
> > jitter-dev@cycling74.com
>
> jitter-dev@cycling74.com

>
>
>
>
> —
> http://www.nano-soundworks.com
> ————————————————————————
>
>

#120901
Jan 22, 2008 at 12:41am

On Jan 21, 2008, at 4:19 PM, Jean-Marc Pelletier wrote:

> Like Joshua suggested, I think you want:
>
> jit_object_method(m,_jit_sym_getinfo,&info);
>
> m_copy = jit_object_new(_jit_sym_jit_matrix, &info); //Create the
> matrix
> //jit_object_method(m_copy,_jit_sym_getinfo,&info); //If the matrix
> already exists
>
> jit_object_method(m_copy,_jit_sym_frommatrix,m,NULL);
>
> instead of:
>
> m_copy = jit_object_method (m, _jit_sym_newcopy, 0L);

Yes. Or the slightly simpler following should also be equivalent:

m_copy = jit_object_method (m, _jit_sym_newcopy, 0L);
jit_object_method(m_copy,_jit_sym_frommatrix,m,NULL);

Essentially, the newcopy method should create a new matrix copying
the dimensions, planecount and type, but not actually copying the
data. Kind of dumb, I know, but that’s how it works.

-Joshua

#120902
Jan 22, 2008 at 12:49am

Jean-Marc Pelletier wrote:
> //jit_object_method(m_copy,_jit_sym_getinfo,&info); //If the matrix
> already exists

Oops, should be:
jit_object_method(m_copy,_jit_sym_setinfo,&info); //If the matrix
already exists

#120903
Jan 22, 2008 at 9:44am

Thanks guys! I finally understand how newcopy works:-) I thought it was the
equivalent of creating a new matrix with the same name, sharing the same
data. That’s why I expected the output to be still the same no matter if the
data was actually copied.
So the conversion matrix argument is an optional thing, thats perfect. You
might want to mention that in the API. And to avoid confusion maybe change
de description of newcopy, since it says “Constructs instance of
t_jit_matrix, copying from input. ” hmm ;-)

Thanks again for helping out.

Thijs

On Jan 22, 2008 12:49 AM, Jean-Marc Pelletier wrote:

> Jean-Marc Pelletier wrote:
> > //jit_object_method(m_copy,_jit_sym_getinfo,&info); //If the matrix
> > already exists
>
> Oops, should be:
> jit_object_method(m_copy,_jit_sym_setinfo,&info); //If the matrix
> already exists
>
>

http://www.nano-soundworks.com

#120904

You must be logged in to reply to this topic.