Forums > Dev

modifying simplejit to iterate through a jitter matrix and fill it, example?

May 27 2010 | 2:58 am

if someone can explain, this might be helpful for others who are having similar issues understanding what is going on in the SDK-

I’m looking at simplejit in the c SDK, and I’m having a hard time understanding just what’s going on in terms of filling the matrix with data.
I can see the jit_simple_vector function is the one that is copying data into the location at each pointer, but how it is doing it I’m not totally sure of. I would like to modify it so that I can iterate through a matrix and put new data in each plane, depending on which plane it is, for example.
I might be going about this totally wrong- feel free to straighten my brains.

I read that the line *++op = tmp*gain; means "multiply the value of x->gain (a user-supplied value, could be whatever) and the current input cell coordinate value, and store that new value in the (next) output cell position" i say next because of the pointer arithmetic going on with the ++op.

1) I’m not sure why that is *++op = tmp*gain; …but in the second else statement, it’s *op = tmp*gain;
…so, that’s how it’s essentially copying data into the matrix, but precisely how?

2) what is the while(–n) and the while(n–) doing? (pointer arithmetic, but what is it implying?)

3) what is the if/else surrounding those blocks for?

the function is here, or look at simplejit in c SDK example code to see how it’s called etc:
void jit_simple_vector(t_jit_simple *x, long n, t_jit_op_info *in, t_jit_op_info *out)
double gain = x->gain;
T *ip;
T *op;
long is,
long tmp;

ip = ((T *)in->p);
op = ((T *)out->p);
is = in->stride;
os = out->stride;

if ((is==1) && (os==1)) {
while (–n) {
tmp = *++ip;
*++op = tmp * gain;
else {
while (n–) {
tmp = *ip;
*op = tmp * gain;
ip += is;
op += os;

May 27 2010 | 9:24 pm

This is really an example for demonstrating C++ template programming for Jitter. I think you might be better off starting in some other part of the Jitter SDK. However, here’s a few answers to your questions.

1. *++op = tmp * gain; is only for the case on single plane data, or multiplane data which this example I believe makes seem like a single plane. in the following one, you’ll see that op += os does the pointer increment.

2. Personally I think that this example is a little confusing in it’s use of pre vs post inc/decrement, but the reason this was perhaps done was from some legacy ppc strategy where pre-inc/dec was faster. –n and n– aren’t pointer arithmetic themselves, just the number of items in a row (vector).

3. if section is regarding the stride between elements to process.

Again, I don’t think this is the best place to start. Unlike the "simplemax" and "simplemsp" projects, "simplejit" (perhaps should be called "simplejitcpp").

I think if you (re)read the provided Jitter SDK chapters, more will become clear.

May 27 2010 | 9:55 pm

JKC- thanks for your comments. I’m using C++ because I’m implementing a C++ library and working on getting the data into a jitter matrix, and this was the the easiest to understand example besides Graham Wakefield’s template. I’ve been looking at a bunch of other examples, like luke’s jit.eclipse which helped a bit.

regarding question 2) – that makes sense. I realize now what is going on, with n being simply the number of row vectors, and it just subtracts from them til there’s no more to process. My problem was that I couldn’t figure out how to reference anything longer than a row vector, which was silly, because if that’s the case I shouldn’t have been trying to do my data copying in that function anyway.

I’d love to see an example that simply iterates through a matrix, and essentially does a setcell but with pointer arithmetic, inserting an int counter value at each position. I came up with a hacky solution, but I’m sure there’s a cleaner one. (gotta figure out why my code crashes when i use (not very)large matrices as input to my object , 36 x 36 approx or bigger crashes it…)

May 28 2010 | 4:53 am

just realized my pointer iterator code must be what is wrong, since it doesn’t crash Max when I post() my data instead of setting it. trying to understand a solid example of how to iterate through an existing matrix and set float32 data in each cell, via pointer arithmetic and such, if anyone has any suggestions…

Oct 31 2011 | 8:35 am

After spending a few minutes with the control, the simplest display scenario is very simple. In fact, creating the collection source I think will be the most challenging…to determine what is the appropriate metadata that you need and want to display to your users to interact with in your application.

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

Forums > Dev