Matrix to texture in new thread

Aug 10, 2011 at 4:30pm

Matrix to texture in new thread

Hi everyone,

I started getting curious about java, when I heard of the threading ability. So the first thing I tried, was to read movies to textures in a seperate thread. (probably not a wise starter point :)

With the help of an example in this forum and the WritingMaxExternalsInJava.pdf I came up with the code below.

Luckily it worked, but it brings my cpu to its knees quickly.
(I bang the mxj 25 times per second.)

Probably I’m way off of how java threading should be used (I’m a newbie with only a little javascript experience).

import com.cycling74.jitter.JitterMatrix;
import com.cycling74.jitter.JitterObject;
import com.cycling74.max.Atom;
import com.cycling74.max.MaxObject;

public class ThreadedMoviePlayer extends MaxObject
{
private Thread t1;
private JitterObject myplayer1;
private JitterMatrix mymatrix1;
private JitterObject mytex1;
private JitterObject myplayer2;
private JitterMatrix mymatrix2;
private JitterObject mytex2;

public ThreadedMoviePlayer ()
{
mytex1 = new JitterObject(“jit.gl.texture”,”mywind”);
mytex1.setAttr(“name”,”too1″);
myplayer1 = new JitterObject(“jit.qt.movie”);
mymatrix1 = new JitterMatrix(4, “char”, 1280, 720);
mytex2 = new JitterObject(“jit.gl.texture”,”mywind”);
mytex2.setAttr(“name”,”too2″);
myplayer2 = new JitterObject(“jit.qt.movie”);
mymatrix2 = new JitterMatrix(4, “char”, 1280, 720);
}

public void read(final String path)
{
myplayer1.send( “asyncread”, path );
myplayer2.send( “asyncread”, path );
}

public void bang()
{
if (t1 != null)
{ t1 = null ; }

t1 = new Thread()
{
public void run()
{
myplayer1.matrixcalc(mymatrix1, mymatrix1);
mytex1.send(“jit_matrix”, mymatrix1.getName() );
myplayer2.matrixcalc(mymatrix2, mymatrix2);
mytex2.send(“jit_matrix”, mymatrix2.getName() );
}
};

t1.start();

}
}

Anyway, I’m reading in this forum for over two years now (this is my first post) and I just love it. I learned so much by reading posts and looking at example patches. So thanks to all the great people sharing their knowledge…

Cheers,
David

#58410

You must be logged in to reply to this topic.