basic question

glBeatriz's icon

Hi
I´m doing my first tests in Java. In my class, I have created a jit.op object and a jit.matrix but...how do I make jit.op "work" (that is, operate on the matrix) using Java? I assume that I need to use a functionality of the JitterObject class?
Thanks in advance!

//Java class///////////////////////////////////////

import com.cycling74.max.*;
import com.cycling74.jitter.*;

public class myJitterMatrix extends MaxObject {

    float value; //my attribute
    JitterMatrix jm = new JitterMatrix();
    JitterMatrix temp = new JitterMatrix();
    JitterObject jop = new JitterObject("jit.op");

    //mxj object constructor
    myJitterMatrix()
    {
        declareAttribute("value");
        declareIO(1,1);
        createInfoOutlet(true);

        //value = 0.5f; //similar to (float)0.5

        jop.send("op", "*");
        jop.setAttr("value", value);
    }

    public void jit_matrix(String s)
    {
        jm.frommatrix(s); //copy contents of incoming matrix into jm
        temp.setinfo(jm); //sets to temp the characteristics of jm
        jop.matrixcalc(temp, jm);

        outlet(0, "jit_matrix", jm.getName());
    }

    public void notifyDeleted()
    {
        jop.freePeer();
    }
}

//PATCH///////////////////////////////////////////////////

Max Patch
Copy patch and select New From Clipboard in Max.

1476.patch.zip
zip
efe's icon

Hey Bea!
take a look at the following example there is a filtered noise matrix used for generating a geometry(hence the 12 planes). You can modify the source in order to achieve what you want.
Important things to notice:
1-Check how the objects are declared and their attributes set; in most of the cases as strings
2-The java-jitter classes require a bang from the patcher(just like any other max object). That's why you have a method called bangnoise() which updates the state of the noise matrix every time there is a bang. The method bang() takes care of outputting the matrix: the outlet method is responsible of that.
3-The java-jitter classes follow the same logic as the max patcher, that's why you calculate the noise matrix first and then you update it with the expression matrix.
4-You can bind directly your class to the max objects by using the matrices declared on it, check the sketch object on the max patcher.

change the source and let me know how it goes. Post your results here as we are lacking a good amount of resources for people willing to jump into jitter-java.

cheers!

-emmanuel

1481.NoiseExpr3.zip
zip
glBeatriz's icon

thanks Emmanuel, but the problem seems to be when I apply the line
jop.matrixcalc(inputmatrix, outputmatrix);

then each time the mxj object receives a new matrix, I receive a message in the max window saying "1229870672 calling matrixcalc on jit_op"

I did exactly this example but creating a [jit.expr] object instead of a [jit.op] object and everything worked fine, so I guess it must be some specific issue with jit.op (??).

New code (practically the same) here

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

import com.cycling74.max.*;
import com.cycling74.jitter.*;

public class jitterOp extends MaxObject {

    JitterMatrix jm;
    JitterMatrix matrixOutput;

    JitterObject jop;

    //constructor
    public jitterOp()
    {
        declareIO(1,1);
        declareAttribute("num");

        jm = new JitterMatrix();
        jm.setAttr("planecount", 4);
        jm.setAttr("type", "char");
        jm.setAttr("dim", new int[]{320, 240});

        matrixOutput = new JitterMatrix();
        matrixOutput.setinfo(jm);

        jop = new JitterObject("jit.op");
        jop.setAttr("op", "*");

    }

    public void jit_matrix (String s)
    {
        jm.frommatrix(s); //copy contents of incoming matrix into jm

        jop.setAttr("val", num);
        jop.matrixcalc(jm, matrixOutput);

        outlet(0,"jit_matrix", matrixOutput.getName());

    }

}

////patch////////

Max Patch
Copy patch and select New From Clipboard in Max.