Forums > Java

bang() always returns doesn't understand bang()

May 1, 2009 | 9:27 pm

I’ve been trying to use Jitter ob3d objects in java with automatic set to zero, when i try and bang using the .bang() method the api tells they have I get doesn’t understand "bang" in the max console.

Does anyone else have this problem?


May 1, 2009 | 9:33 pm

here is an example

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

public class textureTest extends MaxObject {

	JitterObject texture;
	JitterObject gridshape;

	private static final String[] INLET_ASSIST = new String[]{
		"inlet 1 help"
	};
	private static final String[] OUTLET_ASSIST = new String[]{
		"outlet 1 help"
	};

	public textureTest(Atom[] args) {

		declareInlets(new int[]{DataTypes.ALL});
		declareOutlets(new int[]{DataTypes.ALL});

		setInletAssist(INLET_ASSIST);
		setOutletAssist(OUTLET_ASSIST);

		texture = new JitterObject("jit.gl.texture");
		texture.setAttr("drawto", "test");
		texture.setAttr("name", "tex2");

		gridshape = new JitterObject("jit.gl.gridshape");
		gridshape.setAttr("drawto", "test");
		gridshape.setAttr("shape", "plane");
		gridshape.setAttr("texture", "tex2");
		gridshape.setAttr("automatic", 1);
	}

	public void bang() {
		//gridshape.bang(); //< -- this line causes trouble !!
	}

	public void read(String s) {
		texture.send("read", new Atom[] { Atom.newAtom(s) });
	}

	public void notifyDeleted() {
		texture.freePeer();
		gridshape.freePeer();
	}

}

May 9, 2009 | 11:17 pm

could someone try compiling this and explaining why it raises does not understand bang ?

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

public class test extends MaxObject
{

	JitterObject sketch;

	private static final String[] INLET_ASSIST = new String[]{
		"inlet 1 help"
	};
	private static final String[] OUTLET_ASSIST = new String[]{
		"outlet 1 help"
	};

	public test(Atom[] args)
	{
		sketch = new JitterObject("jit.gl.sketch");
		declareInlets(new int[]{DataTypes.ALL});
		declareOutlets(new int[]{DataTypes.ALL});

		setInletAssist(INLET_ASSIST);
		setOutletAssist(OUTLET_ASSIST);

	}

	public void bang()
	{
	//just pass it on
	sketch.bang();
	//try again
	sketch.send("bang");
	}
}

May 16, 2009 | 6:15 pm

I have never used the jitter api, but as far as I could tell from the reference, neither of the jit.gl objects you used above support the bang message. Why do you want to send it?


May 26, 2009 | 3:05 pm

Gridshape supports bang, you need to bang it to draw it if you have automatic turned off. According to the api all Jitter Objects inherit the bang method.


May 26, 2009 | 3:51 pm

Are we using the same version of the api? On my machine, the only classes contained in javadocs at java-docapi-jitter are:

JitterEvent
JitterListener
JitterMatrix
JitterNotifiable
JitterObject

A native jitter object can not inherit a java object. As far as the I can tell form the docs, JitterObject is simply a front-end that sends messages to a native "peer". If you replace

gridshape.bang();

with

post(gridshape.understands("bang"));

what does it print?


May 26, 2009 | 4:03 pm

Sorry perhaps the space between Jitter and Object confused matters. I’m using the api with Max 5.07 and the api docs state JitterObject contains a method bang, since the gridshape or sketch in the mxj is an instance of JitterObject it should respond to the method. The objects when in normal patcher use respond to bangs.

I’m checking out what understands spits out now.


May 26, 2009 | 4:15 pm

post(gridshape.understands("bang") + "n");

returns false in the console.


May 27, 2009 | 12:30 pm

Well this implies that the C object initialized by mxj really don’t understand the bang message.

crx091081gb wrote on Tue, 26 May 2009 10:15
since the gridshape or sketch in the mxj is an instance of JitterObject it should respond to the method

No, your gridshape variable holds an instance of a JitterObject. This is a java object that can call native code to initiate native jitter objects (in the constructor) and send messages to them. jit.gl.gridshape is NOT instance of JitterObject, so JitterObject won’t know about which method the actual object may support. This is what the understands() method is for.

Quote:
The objects when in normal patcher use respond to bangs

Really? Can you put up an example patch where jit.gl.gridshape supports bang?


May 27, 2009 | 12:32 pm

Btw, I shouldn’t use the term C object here. They are native objects, though surely written in C.


May 27, 2009 | 12:40 pm

This is an example

– Pasted Max Patch, click to expand. –

Believe me now?

I got an email back from technical support and apparently bang calls the objects draw method so I’m going to try calling that.


May 27, 2009 | 1:00 pm

Success, calling .call("draw") whenever I want it to draw does the trick.

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

public class bangTest extends MaxObject
{

JitterObject gridshape;

private static final String[] INLET_ASSIST = new String[]{
"inlet 1 help"
};
private static final String[] OUTLET_ASSIST = new String[]{
"outlet 1 help"
};

public bangTest(Atom[] args)
{
gridshape = new JitterObject("jit.gl.gridshape");
gridshape.setAttr("drawto", "example");
gridshape.setAttr("shape", "plane");
gridshape.setAttr("automatic", 0);
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});

setInletAssist(INLET_ASSIST);
setOutletAssist(OUTLET_ASSIST);

}

public void bang() {
gridshape.send("draw");
}
}

– Pasted Max Patch, click to expand. –

This works


June 2, 2009 | 2:07 pm

Nice, strange that this method is not documented in the reference though. Is ‘draw’ a generic OpenGL function?


June 2, 2009 | 2:27 pm

It is documented here

Messages and attributes common to the GL group

Bang is supposed to call it, maybe this is handled by something that is not exposed to the jitter java api hence having to call it by name?

If you try sending "draw" from a message box it has the same effect as bang. I suppose it’s left in to differentiate it from drawraw.


June 2, 2009 | 3:10 pm

Aha, I didn’t notice that page. You’re probably right about the method not being exposed, that is a bug in JitterObject then.

Maybe it would be nice to create java wrappers for the jit.gl objects to call them more java-style? Methods could be ported like this for instance:

public void dim(int x, int y) {
    peer.send("dim", new Atom[]{ new Atom(x), new Atom(y) });
}

Takes a lot of work though, maybe not worth it..


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