We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Processing and maxMspJitter (Read 1315 times)
Processing and maxMspJitter
Dec 2nd, 2005, 7:46pm
 
Hi, I really enjoy working in processing, but since I also work with vj setups in max msp and jitter from cycling74.com, I am curious if there is a way to map a processing application into a layer in jitter (this is the part of max that deals with realtime video).

It is already now possible to create graphics in max by writing javascript and java inside max, but I find the processing syntax less complicated to use.

Mixing processing with the video layers in max msp jitter would be an awsome thing to do. What do you think?

Re: Processing and maxMspJitter
Reply #1 - Dec 2nd, 2005, 10:28pm
 
I've played with it a bit using an experimental variant of MaxLink (http://jklabs.net/maxlink), but I ran into serious speed problems.  Jitter's matrix format is pretty different from Processing packed int colors, and I found the conversion to be painfully slow.

Having said that, I'm no graphics expert or code optimizing whiz.  If anyone has an idea for how to do this quickly, I'd be more than happy to give it another try.

Another thing I haven't tried is using Processing to generate OpenGL graphics for a Jitter target window.  Anyone know if this would even be possible?  That might be the ideal solution...
Re: Processing and maxMspJitter
Reply #2 - Dec 3rd, 2005, 6:48pm
 
what sort of speed problems? what's the matrix format for the colors? is there another way to send the color data over?

we'd love to do a better job supporting max/jitter because of the overlap between our communities..
Re: Processing and maxMspJitter
Reply #3 - Dec 3rd, 2005, 7:34pm
 
Jitter matrices can be comprised of various types and layers -- I've been playing with a 3 layer (RGB) int matrix.  On each frame, the Max object runs through the pixels array and caculates each component using PApplet.red() and so on, then copies the data into a Jitter matrix.

Jitter 1.5 came out in July, and it's the first version with Java access to Jitter matrices.  My 30-day demo has expired, and it's a $189 upgrade (which I don't have any use for, aside from this Jitter/Processing object).

In my test case, I'm actually driving the frames with a bang command, which is how most Jitter objects behave.  Here's the rough code I have so far:

Code:

package jk;

import processing.core.PApplet;
import com.cycling74.jitter.JitterMatrix;
import com.cycling74.max.MaxObject;

public class p5jit extends MaxObject {


PApplet p5;

int width, height;

JitterMatrix matrix;


public p5jit() {


bail("need a sketch name");

}


public p5jit(String sketchName) {


initSketch(sketchName);


post("inited sketch");

}


private void initSketch(String sketchName) {


try {



Class c = Class.forName(sketchName);



p5 = (PApplet) c.newInstance();




p5.init();



p5.noLoop();




width = p5.width;



height = p5.height;




System.out.println("creating " + width + " by "+height + " matrix");



matrix = new JitterMatrix(3, "char", width, height);



} catch (Exception e) {



e.printStackTrace();


}

}


protected void bang() {


p5.redraw();


p5.loadPixels();


copyPixels();


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

}



private void copyPixels() {


int planeCount = matrix.getPlanecount();


int[] offset = {0,0};



for (int d = 0; d < planeCount; d++) {



for (int j = 0; j < height; j++) {




offset[1] = j;




int[] row = getRow(d, j);




matrix.copyArrayToVectorPlanar(d, 0, offset, row, width, 0);



}


}

}


private int[] getRow(int index, int y) {


int[] r = new int[width];


for (int x = 0; x < width; x++) {



int c = p5.pixels[y * width + x];



r[x] = getColor(index, c);


}


return r;

}


private int getColor(int index, int c) {


switch (index) {


case 0:



return (int) p5.red(c);


case 1:



return (int) p5.green(c);


case 2:



return (int) p5.blue(c);


default:



return 0;


}

}

}

Re: Processing and maxMspJitter
Reply #4 - Dec 3rd, 2005, 8:11pm
 
this should speed things up a great deal:

Code:

private int[] getRow(int index, int y) {
int[] outgoing = new int[width];
int offset = y*width;

switch (index) {
case 0:
for (int x = 0; x < width; x++) {
outgoing[offset + x] = (p5.pixels[offset + x] >> 16) & 0xff;
}
break;
case 1:
for (int x = 0; x < width; x++) {
outgoing[offset + x] = (p5.pixels[offset + x] >> 8) & 0xff;
}
break;
case 2:
for (int x = 0; x < width; x++) {
outgoing[offset + x] = p5.pixels[offset + x] & 0xff;
}
break;
}
return outgoing;
}


not sure if this function is still needed, but this is what the optimized version would look like:

Code:

private int getColor(int index, int c) {
switch (index) {
case 0: return (c >> 16) & 0xff; // red
case 1: return (c >> 8) & 0xff; // green
case 2: return c & 0xff; // blue
default: return 0;
}


red(), green() etc are all really slow (see notes in teh docs). also, you're not guaranteed to have the functions inline properly (PApplet.red() might sometimes get inlined) so called getColor() repeatedly will be slow because the switch() is inside of that.

other things that would speed things up.. if outgoing[] can re-use its int array, that'll save a lot of time, becuase the overhead for creating (and unloading) an array of ints will be high. i.e. only creating a single int[] array that's used over and over again by calls to getRow().

also using P3D will be faster than the JAVA renderer because the loadPixels() overhead will go away.

also, if getRow() isn't really needed, you may as well copy that whole matrix in one go, that way you don't have to deal with the overhead of calling getRow() multiple times, and creating the array of ints for the row, and doing the switch statement repeatedly.

i can't go much further without knowing more about how it's set up.. like if copyArrayToVectorPlanar() needn't deal with rows, then you might be in better shape.. but the changes listed should give you a large speed boost..
Re: Processing and maxMspJitter
Reply #5 - Dec 3rd, 2005, 9:00pm
 
Thanks Ben -- that looks much better.  I'll see if I can test it out on a machine that doesn't have an expired demo.  If it works, that Jitter upgrade may be worth it...
Re: Processing and maxMspJitter
Reply #6 - Dec 1st, 2006, 12:24pm
 
Has anyone got any further with this idea? I've tried the code examples above and the closest I can get to having anything run is:

error: java.lang.ClassCastExceptioon
error:  at jk.p5jit.initSketch(p5jit.java:37)
error:  at jk.p5jit.<init>(p5jit.java:25)

Is there another way to stream the output from processing to jitter?
Page Index Toggle Pages: 1