Forums > Javascript

Get a matrix from a patcher to javascript?

October 20, 2011 | 4:16 pm

Hello,

Could Anyone explain how to get a matrix from a patcher and process it inside javascript.
What kind of function do I need in JS?

Tutorials explain how to send a processed matrix from javascript out of the [js] object with the outlet() method, to the patcher but not how to retrieve a matrix inside the [js] FROM the patcher.

Thanks.


October 20, 2011 | 4:47 pm

Here’s how to get a matrix object in JS with the same data as the input matrix name.

function jit_matrix(name) {
// create matrix with the same name as the input matrix
var mat = new JitterObject("jit.matrix", name);
var cell = mat.getcell(0, 0);
post("res: "+cell+"n");
}


October 21, 2011 | 2:10 pm

Okay, thank you, nice, but how do I process the matrix now?
Does it need to be inside the function itself. After several attempt this not works:

////////////////////////////////////////////////////
var mydimmap = new JitterObject("jit.dimmap");
mydimmap.invert = [1, 1];

var mtrx2 = new JitterMatrix(4, "char", 320, 240 );
mtrx2.adapt = 1;

function jit_matrix(ext)
{
var mtrx = new JitterObject("jit.matrix", ext);
mtrx2.frommatrix(mtrx);
mtrx2.matrixcalc(mtrx, mydimmap);
outlet(0, "jit_matrix", mydimmap.name);
}

////////////////////////////////////////////////////

>>> Javascript TypeError: mtrx2.matrixcalc is not a function, line 15

I can’t achieve to process the matrix inside another function anymore.
This lacks in the JS tutorials.


October 22, 2011 | 12:32 pm

Okay, after a good night I go this way:

/////////////////////
process&output2.js

autowatch = 1;

var mtrx = new JitterMatrix(4, "char", 320, 240);
var opfloat;

function recupop(v)
{
opfloat = v;
}

function bang()
{
mtrx.op("*", opfloat);
}

function jit_matrix(ext)
{
{
mtrx.name = ext;
}

{
bang();
}
outlet(0, "jit_matrix", mtrx.name);
}
//////////////////////////

– Pasted Max Patch, click to expand. –

October 22, 2011 | 12:40 pm

I am aware that this code is elementary for programmers, but I’m not, I’m only an artist and I think Max is really interesting for its accessibility and documentation. Such basic code should be in the doc because it would allow to gain some days … yes. I think we need needs more JS basic tutorials …

Anyway thanks for the example, Wes, on how to retrieve the matrix in JS.
(more, more, more ;-)


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