Forums > Javascript

jit.repos in js not working as expected

January 2, 2010 | 9:00 pm

Okay, I’ve struggled with this for 24 hours, I need some help.

I’ve done this in Max w/standard objects, it works fine. When I move it to JS, things get wonky.

I’ve already finished a patch for the Launchpad that works as a generative sequencer (like Nodal or Elysium). I’m trying to recode it for efficiency, as I barrelled through the initial coding just as a proof of concept, and at l/4 or 1/8 note resolutions it works fine, but at higher rez’s its not stable timing wise. So this is the main engine for interpretation, as I’ve rewritten it.

The code I’m posting is supposed to deal with eight different jit.matrices, each one being a different direction. Each time it receives a bang, it should advance the square in whatever ever direction the plane its inserted on is moving.

The problem I’m having is that jit.repos is doing the repositioning, but its not removing the old location. There should be a progressing square on the matrixctl, but instead its additive. Please, someone tell me what I’m doing wrong here, or confirm that there is something amiss with the JS implementation of the jit.repos object, because my forehead is bleeding from all this head-beating-against-wall activity I’ve been doing.

I should mention this patch is for M4L, but I’ve tried the same JS in Max and it behaves the same. I’ve also posted over at Ableton.

I expect someone is going to tell me I should be using particles for this, and there is a really nice tutorial in the docs….well, I know, but I have my own reasons for doing things this way. As far as I can tell, this should work.

I’m not providing the patch, just the js. Hook up a 16×16 matrixctl to outlet(0) to see what is going on, and input three coordinates (direction 1-8, x, y) to get the "plinko" started. Banging in the input should advance time (or hook up a metro to it). Lemme know if anyone has the slightest clue what I’m talking about. Thanks in advance.

Cheers :)



setinletassist(0,"pulse input");
setinletassist(1,"launchpad input");
setinletassist(2,"program input");

var boundmode=1

var dir=[]
var potential=[]
var interp=0
var dump=[]
x_adj=[1, 0, -1, 1, -1, 1, 0, -1];
y_adj=[1, 1, 1, 0, 0, -1, -1, -1];


function list(d,x,y)  //drops the plinko
    post("x", x, "y", y, "val", potential[4].getcell(x,y));

function init()   //init parameters
        dir[n] = new JitterObject("jit.repos");  //the misbehaving object
        dir[n].boundmode=boundmode;              //in question
        dir[n].mode=1;                           //with its attributes
        dir[n].outputmode="Normal";              //< --don't know about this
        potential[n] = new JitterMatrix(1, "char", 16, 16);//direction planes
        potential[n].setall(0);                            //and init

    potential_new = new JitterMatrix(1, "char", 16, 16);  //sum matrix
    potential_new.setall(0);                              //and init
    program = new JitterMatrix(16, "char", 16, 16);       //not relevant
    repos = new JitterMatrix(2, "char", 16, 16);      //lookup matrix
    repos.setall(0,0);                                //for dir repos object
    potential_sum= new JitterMatrix(1, "char", 16, 16); //eval matrix
    post("matrices instantiated:)n");

function update_potential()  //  advance particles to new position each turn
    potential_sum.clear;     //clear eval matrix
        potential_new.clear;   // clear summing matrix
        dir[n].offset_x=x_adj[n];    //offset update for each plane
        dir[n].matrixcalc([potential[n],repos],potential_new);  //the trouble
        potential[n].frommatrix(potential_new);  //place it back in original
        potential_sum.op("+", potential[n], potential_sum); //sum potentials

function roll_random()
    random=Math.floor(Math.random()*8)+1;  //not relevant

function bang()
            var interp=0;
            interp=parseInt(potential_sum.getcell(xx,yy));//anything there?
                //post(xx,yy,interp, "n");
                dump=program.getcell(xx, yy);  //if so, look up program
                post("dump", dump,"n");       //and post results
                disp_potential(xx,yy);      //display in matrixctl


function clear_display()   //clear display each turn
    outlet(0, "clear");

function disp_potential(x,y) //send values to display
outlet(0, x, y, 1);

January 3, 2010 | 8:07 am

Never mind, I figured it out. I was making a couple of assumptions that were incorrect.

In case anyone is interested, the corrected function that was failing looks like this:

function update_potential()
        potential_sum.op("+", potential[n], potential_sum);
Viewing 2 posts - 1 through 2 (of 2 total)