Should be simple: How to get a matrix into and out of javascript?

codedorf's icon

Hi All,
My question is pretty simple. How do I get data from a jit.matrix into a javascript (where I will do processing on it), and then how do I output a matrix when I'm done processing? For instance...
In my patch I have a 11 plane jit.matrix with @name "test_table". I fill all cells in all planes with 64. I want to get that matrix into a javascript object.

My code looks like this:
function jit_matrix()
{
    var testMatrix = new JitterMatrix("test_table");
    outlet(0, testMatrix); // doesnt work
outlet(1, "final_table", testMatrix); // doesnt work
outlet(2, "final_table", testMatrix.name); // doesnt work
}
But I don't know what I'm doing, and there is no good documentation... The jitter javascript tutorials don't really ever cover this, except for very briefly, and there are no explanations.
Any help is greatly appreciated!!

codedorf out.

jvkr's icon

It is possible to access data in a matrix using the getcell and setcell instructions. There is the jstable-example.maxpat in the jitter-examples/javascript/other folder that shows how to use them. Remember that with matrices, not the actual data, but references are handed. I didn't try, but outputting the message 'jit_matrix final_table' might do it.

Rob Ramirez's icon

i've attached a basic example of two ways to reference a matrix using javascript.

js-matrix-ex.maxpat
Max Patch
process-matrix.js
js
codedorf's icon

Thank you thank you thank you both!
Although I'm still confused on how exactly javascript and jitter work together, the example helped immensely.

One question I had was: what does the frommatrix method do? I don't see the frommatrix method in the list of methods for the JitterMatrix object here: http://max-javascript-reference.tim-schenk.de/symbols/#gsc.tab=0

where did the method come from if it's not on the list?

Rob Ramirez's icon

it's a special method of the JS JitterMatrix object.
check out jitter tutorials 45 and 46.
https://cycling74.com/docs/max6/dynamic/c74_docs.html#jitterchapter45

elizabethkeen's icon

Go to this link.May be it helps you to an extent.
https://cycling74.com/forums/jitter-matrix-input-to-javascript/
For more web applications visit at:

codedorf's icon

Thanks guys -
I was able to successfully do what I set out to do with javascript. I wish there was more official information on how to use jitter & javascript, but oh well, glad there is at least a forum (& helpful community members) to help out with this kind of thing.

- Codedorf out

loadmess's icon

Thank you!
Makes me sad that this kind of documentation comes from a external source and not Cycling74 instead...
Thank You Tim Schenk!
http://max-javascript-reference.tim-schenk.de/