Is functionality within Java possible?

    May 11 2012 | 1:47 am
    Hi list,
    I want to make a java wrapper for the object to make some slab thingies easier to do.
    But I immediately run into a fundamental problem: I can't get the input and output of a object work.
    I basically did this: 1. I instantiated a JitterObject with ' new JitterObject("") '. 2. I made the 'anything' method forward all incoming data to this JitterObject via the 'call' method. 3. I set up a JitterListener to listen to outcoming textures when the slab is done processing them.
    The JitterListener however doesn't seem to register the out coming 'jit_gl_texture' messages.
    Also, when I use the 'call' method, no Atom[] array is returned, in stead I get only null.
    So much for the straightforward solution. So I tried sending out the resulting textures (with their names defined in the 'capture' attribute) simply after receiving incoming jit.matrices. That only gives me a black window. So I tried sending out the resulting textures after any of the messages that the JitterListener dóes register. Still no luck.
    As you can see in the java file (attached) and the max patch (I tried to comment it all quite clearly), I've tried basically every point that I could think of to send out the resulting texture. Without success.
    Can anybody tell me how to make a shader / slab work within Java code?
    Thank you to anyone pointing me in the right direction!
    - tarik

    • May 11 2012 | 9:47 am
      There's a get-only attribute called out_name that will give you the name of the that is the slab's output. You can use its value to chain together slabs and texture other objects. You can use the relevant attr getting java methods to get its value, but here's a patcher version:
    • May 11 2012 | 10:43 am
      Thanks! But the 'out_name' attribute gives the exact same name as the 'capture' attribute that I send out through the mxj outlet. So the outcoming textures are named correctly I believe. Only, for some reason, they are empty at the moment that I send them. (btw, just to be sure, I just now tested the use of the out_name attribute in my Java file, which as expected gave the same results). I think there might be a timing problem: I might be sending out the texture while its being created, or right before or something.
      I believe I would be helped a lot if a JitterListener could actually see when the object sends out the resulting texture. But for some reason it seems to ignore this.
    • May 11 2012 | 11:01 am
      Oh wow, I found the staggeringly simple answer:
      In 'normal' max, sending a object a matrix or a texture will make it automatically process a texture.
      Within Java however, this does NOT happen automatically. The texture does not get drawn until you explicity give it the "draw" command.
      A subtle inconsistency which got me thinking in waaay too complex ways.
    • Jan 13 2015 | 10:50 pm
      hi Tarik, I know this topic is a bit old, but it is so hard to find anything about jitter and java when you want to do more than the basic example in the doc.
      I'm trying to do the same thing and did make the "draw" call but it won't display anything. Could you share your java code please?
      I've posted my problem here too
      I could only make the display something. I then replace by a exactly the same way but it won't display anything.
    • Jan 13 2015 | 11:23 pm
      Hi Robotpapier,
      here an example from off the top of my head.
      JitterObject slab = new JitterObject("", "renderContext"); JitterObject hapPlayer = new JitterObject("", "renderContext");
      public void bang(){"jit_gl_texture", hapPlayer.getAttr("out_name");"draw"); outlet(0, "jit_gl_texture", slab.getAttr("out_name"); }
      public void read(String filePath){"read", filePath); }
      This should copy a texture from the to and output it from outlet 0. Of course you have to replace "renderContext" with the actual name of your render context...
      Hope it helps.
    • Jan 14 2015 | 1:26 am
      Hi Django! You are a lifesaver, was about to let down the java version of my patch and was kinda sad, but you made my day and I'm back in da game again :), thanks!
      Besides i'm working on Max 6 and am trying Max 7 too, the same java code works on Max 6 but not on Max 7 32 bits. I've checked that in "patcher mode" is working.
      Here is the working class for Max 6.1 32 bits Windows for hap player :
      public class myHapClass extends MaxObject {
      	private JitterObject myWindow; 
      	private JitterObject myHapMovie;
      	private JitterObject myVideoplane;
      	private JitterObject myRender;
      	public myHapClass(){	
      		declareInlets(new int[]{ DataTypes.ANYTHING}); 
      		declareOutlets(new int[]{ DataTypes.ANYTHING});
      		// jit.window
      		this.myWindow = new JitterObject("jit.window","myWindow");		
      		this.myWindow.setAttr("depthbuffer", 0); 	
      		this.myWindow.setAttr("fsaa", 1);
      		this.myVideoplane = new JitterObject("","myWindow");
      		this.myVideoplane.setAttr("transform_reset", 2);
      		this.myRender = new JitterObject("","myWindow");
      		this.myRender.setAttr("erase_color", new int[] {0,0,0,1} );
      		this.myHapMovie = new JitterObject("");		
      		this.myHapMovie.setAttr("drawto", "myWindow"); // won't work if the context is not set
      		// this.myHapMovie.setAttr("autostart", 0); // I've also tested this mentionned in another post but it doesn't change anything
      	public void bang() {"draw");"erase");"jit_gl_texture",this.myHapMovie.getAttr("out_name"));"drawclients");"swap");
      Max 6 works but Max 7 displays blank black screen, did you by chance tried hap on Max 7 and if yes knows what could be the problem?
    • Jan 14 2015 | 1:46 am
      ohh, sorry, it's working now, was just a path problem ^^
    • Jan 15 2015 | 1:32 am
      Re, just wanted to report that although this.myHapMovie.freePeer() draws an error in the max console ( invalid extension called), it is effectively freed.
      Not freeing the object won't draws the error but will cause crash if the object is reused.
    • Jan 15 2015 | 5:34 pm
      that error can be ignored.