Skip to content

Instantly share code, notes, and snippets.

@esnho
Created September 20, 2020 10:49
Show Gist options
  • Save esnho/c6a86d82e8f18a812c9edef4448a529c to your computer and use it in GitHub Desktop.
Save esnho/c6a86d82e8f18a812c9edef4448a529c to your computer and use it in GitHub Desktop.
jitter set array to matrix issue
// init some variables
t_jit_matrix_info out2_minfo;
char* out2_bp;
jit_object_method(out2_matrix, _jit_sym_getinfo, &out2_minfo);
jit_object_method(out2_matrix, _jit_sym_getdata, &out2_bp);
// the array
long total = 30;
long* array = new long[total * 3];
// set mock data
long longCounter = 0;
for (longCounter = 0; longCounter < total * 3; longCounter++) {
array[longCounter] = longCounter;
}
// change matrix info
out2_minfo.dim[1] = 1;
out2_minfo.dim[0] = total;
out2_minfo.type = _jit_sym_long;
out2_minfo.planecount = 3;
// set matrix info, set array to matrix, retreive data from matrix
jit_object_method(out2_matrix, _jit_sym_setinfo_ex, &out2_minfo);
jit_object_method(out2_matrix, _jit_sym_data, array);
jit_object_method(out2_matrix, _jit_sym_getdata, &out2_bp);
// print matrix data to console
char *ip;
long i, j;
for (i=0; i < out2_minfo.dim[1]; i++) {
ip = out2_bp + i * out2_minfo.dimstride[1];
for (j=0; j < out2_minfo.dim[0]; j++) {
// you are now retrieving values for cell j i
long plane0val = (*ip++);
long plane1val = (*ip++);
long plane2val = (*ip++);
c74::max::object_post(in_matrix, "matrix val [%d, %d]: %d %d %d", j, i, plane0val, plane1val, plane2val);
}
}
@esnho
Copy link
Author

esnho commented Sep 23, 2020

as suggested int the forum updating the code to this make it works

https://cycling74.com/forums/how-to-set-an-array-of-long-to-jitter-matrix-properly/replies/1#reply-5f68ffd91ae2675932cd7e84

// init some variables
t_jit_matrix_info    out2_minfo;
int*                out2_bp;
jit_object_method(out2_matrix, _jit_sym_getinfo, &out2_minfo);
jit_object_method(out2_matrix, _jit_sym_getdata, &out2_bp);

// the array
int total = 30;
int* array = new int[total * 3];

// set mock data
int longCounter = 0;
for (longCounter = 0; longCounter < total * 3; longCounter++) {
    array[longCounter] = longCounter;
}

// change matrix info
out2_minfo.dim[1] = 1;
out2_minfo.dim[0] = total;
out2_minfo.type = _jit_sym_long;
out2_minfo.planecount = 3;
out2_minfo.flags = JIT_MATRIX_DATA_REFERENCE | JIT_MATRIX_DATA_PACK_TIGHT;
out2_minfo.size = out2_minfo.dim[0] * out2_minfo.planecount * sizeof(int);

// set matrix info, set array to matrix, retreive data from matrix
jit_object_method(out2_matrix, _jit_sym_setinfo_ex, &out2_minfo);
jit_object_method(out2_matrix, _jit_sym_data, array);
jit_object_method(out2_matrix, _jit_sym_getdata, &out2_bp);

// print matrix data to console
int *ip;
int i, j;
for (i=0; i < out2_minfo.dim[1]; i++) {
    ip = out2_bp + i * out2_minfo.dimstride[1];

    for (j=0; j < out2_minfo.dim[0]; j++) {
        // you are now retrieving values for cell j i
        int plane0val = (*ip++);
        int plane1val = (*ip++);
        int plane2val = (*ip++);
        c74::max::object_post(in_matrix, "matrix val [%d, %d]: %d %d %d", j, i, plane0val, plane1val, plane2val);

    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment