How do I copy one matrix to another?

Sep 2, 2010 at 10:18pm

How do I copy one matrix to another?

Hi.

I’m just having a first stab into using Jitter as a way of buffering output to a Launchpad. That is I have two 2D 8×8 matrices.

I ‘render’ the state of the button matrix into one Jitter matrix then compare each cell with a second ‘stored’ matrix outputting updates to the Launchpad for cells that are different in the rendered matrix.

At the end of the process I need to copy the ‘rendered’ matrix into the ‘stored’ matrix for use next time around.

I went looking for an object that would copy a matrix but couldn’t find anything. Is there such a thing? Or do I need to iterate & copy by hand?

In the same vain my method for finding updated buttons is to jit.iter the rendered matrix and compare with the equivalent cell in the stored matrix. Is there an easier path to this that outputs the differences between two matrices? I saw jit.change but that seems just about the degree of change, not the actual differences.

Any help would be much appreciated.

Thanks.

Matt

#52124
Sep 2, 2010 at 10:47pm

Looks like a combination of jit.spill & jit.fill can do the job more easily than manually iterating.

But maybe there’s an easier way still?

M

#187261
Sep 2, 2010 at 10:56pm

Hi Matt,

Could you post what you have so far? Maybe that will give me a better idea of what you are up to.

-Ben

#187262
Sep 3, 2010 at 5:53pm

you could use [jit.op @op -] —that should tell you the difference on a cell-by-cell basis. maybe you’ll need an absolute value there too, not sure.

For copying, I’m not sure… could you do a workaround with [jit.submatrix] but just use the whole thing? seems weird though.

Maybe a message to a matrix: copymatrix @sourcematrix
would copy the source matrix to the one you’re sending the message to. feature request? probably I’m missing something though.

#187263
Sep 3, 2010 at 6:49pm

To set matrix B to have the contents of matrix A, you simply send A to B. (More specifically, you cause matrix A to send a ‘jit_matrix’ message to matrix B.) The trick, though, is to suppress thruput on matrix B by setting its @thru attribute to 0 (it’s 1 by default), so that you can set and recall its contents independently.

So if matrix A is the one that has the most recent Launchpad settings, and matrix B is the one that has the previous Launchpad settings, you can bang matrix B to get it to send out the previous settings, compare those to the settings of matrix A, and then set the contents of matrix B to be those of matrix A. Something like this (note that matrix B has @thru 0):

– Pasted Max Patch, click to expand. –
#187264
Sep 3, 2010 at 10:02pm

what I do for comparing long lists or matrices is simply add them together and then modulo. That gives you a “toggle” function that can be set up for any number of stages. Quite handy.

#187265
Sep 4, 2010 at 12:03am

@wetterberg can you elaborate a bit with the modulo? wondering how you’re doing that and what you get from it. always interesting to hear new tactics…

#187266

You must be logged in to reply to this topic.