Handling multiple different output matrices in Jitter MOP external

Connector's icon

I am working on a Jitter MOP c-external with two inputs and two outputs:

 mop = jit_object_new(_jit_sym_jit_mop, 2, 2);

As far as i understand, this would be the usual way to access the different input and output matrices:

in_matrix = jit_object_method(inputs, _jit_sym_getindex, 0);
in2_matrix = jit_object_method(inputs, _jit_sym_getindex, 1);

out_matrix = jit_object_method(outputs, _jit_sym_getindex, 0);
out2_matrix = jit_object_method(outputs, _jit_sym_getindex, 1);   

if (x && in_matrix && in2_matrix && out_matrix && out2_matrix) {

    in_savelock = (long)jit_object_method(in_matrix, _jit_sym_lock, 1);
    in2_savelock = (long)jit_object_method(in2_matrix, _jit_sym_lock, 1);
    out_savelock = (long)jit_object_method(out_matrix, _jit_sym_lock, 1);
    out2_savelock = (long)jit_object_method(out2_matrix, _jit_sym_lock, 1);

    jit_object_method(in_matrix, _jit_sym_getinfo, &in_minfo);
    jit_object_method(in2_matrix, _jit_sym_getinfo, &in2_minfo);
    jit_object_method(out_matrix, _jit_sym_getinfo, &out_minfo);
    jit_object_method(out2_matrix, _jit_sym_getinfo, &out2_minfo);
  
    jit_object_method(in_matrix, _jit_sym_getdata, &in_bp);
    jit_object_method(in2_matrix, _jit_sym_getdata, &in2_bp);
    jit_object_method(out_matrix, _jit_sym_getdata, &out_bp);
    jit_object_method(out2_matrix, _jit_sym_getdata, &out2_bp);

In this case it seems, that every output matrix has the same properties than the leftmost input matrix.

But I would need to define different types, planecounts, dim sizes for each input and output matrix like these ones inside the matrix_calc function:

out_matrix:

jit_matrix_info_default(&posMatrixInfo); //for out_matrix
posMatrixInfo.planecount = 3;
posMatrixInfo.dimcount = 1;
posMatrixInfo.dim[0] = posSize;
posMatrixInfo.type = _jit_sym_float32;
posMatrix = jit_object_new(_jit_sym_jit_matrix, &posMatrixInfo);

out2_matrix:

jit_matrix_info_default(&indexMatrixInfo); //for out2_matrix
indexMatrixInfo.planecount = 1;
indexMatrixInfo.dimcount = 1;
indexMatrixInfo.dim[0] = indexMatrixSize; 
indexMatrixInfo.type = _jit_sym_long;
indexMatrix = jit_object_new(_jit_sym_jit_matrix, &indexMatrixInfo);

So how and at wich point can i define my output matrices in the right way?

Rob Ramirez's icon

I believe you want to disable "typelink", "dimlink", and "planelink" attributes on the mop's input or outputs in the jitter object's init function. for example this is what jit.rgb2luma does to delink output planecount from the input.

// add mop
mop = jit_object_new(_jit_sym_jit_mop, 1, 1); // #inputs,#outputs
jit_mop_single_planecount(mop, 1);
jit_mop_single_type(mop, _jit_sym_char);
o = jit_object_method(mop, _jit_sym_getoutput, 1);
jit_attr_setlong(o, _jit_sym_planelink, 0);
jit_class_addadornment(_jit_rgb2luma_class, mop);

and then in the max object constructor:

max_jit_mop_setup_simple(x, o, argc, argv);
// 1-plane char out
m = max_jit_mop_getoutput(x, 1);
jit_object_method(m, _jit_sym_getinfo, &info);
info.type = _jit_sym_char;
info.planecount = 1;
info.dimcount = 2;
jit_object_method(m, _jit_sym_setinfo, &info);
max_jit_attr_args(x, argc, argv);

Connector's icon

ok. thanks for the hint!

Connector's icon

I'm still a bit confused about using _jit_sym_getinput and _jit_sym_getoutput the right way. In my external i use this code:

 mop = jit_object_new(_jit_sym_jit_mop, 2, 2); //setting 2 inlets and 2 outlets

 jit_mop_single_planecount(mop, 3);
 jit_mop_single_type(mop, _jit_sym_float32);

 i1 = jit_object_method(mop, _jit_sym_getinput, 0); //getting leftmost inlet with 0
 jit_attr_setlong(i1, _jit_sym_dimlink, 0);

 i2 = jit_object_method(mop, _jit_sym_getinput, 1); //getting second inlet with 1
 jit_attr_setlong(i2, _jit_sym_dimlink, 0);

 o1 = jit_object_method(mop, _jit_sym_getoutput, 1); //getting leftmost outlet with 1
 jit_attr_setlong(o1, _jit_sym_typelink, 0);
 jit_attr_setlong(o1, _jit_sym_planelink, 0);
 jit_attr_setlong(o1, _jit_sym_dimlink, 0);

 o2 = jit_object_method(mop, _jit_sym_getoutput, 2); //getting second outlet with 2
 jit_attr_setlong(o2, _jit_sym_typelink, 0);
 jit_attr_setlong(o2, _jit_sym_planelink, 0);
 jit_attr_setlong(o2, _jit_sym_dimlink, 0);

 jit_class_addadornment(_connector_lines_class, mop);

I am wondering if it is correct that there is a difference in setting the leftmost inlet index starting with 0 with _jit_sym_getinput and starting with the 1 for the leftmost outlet with _jit_sym_getoutput ?