Reply To: Receive Syphon input into Processing Sketch?

Home Forums Syphon Syphon Implementations – User Receive Syphon input into Processing Sketch? Reply To: Receive Syphon input into Processing Sketch?


hey guys, I made some progress with the client side in JSyphon.

To avoid writing a JNFTypeCoercion protocol to convert the native SyphonImage class to the Java counterpart, I just return the texture id, width and height in a dictionary with (string, int) key-value pairs.

I managed to get a notification in Processing when a new frame is available in the client, so things look promising, but when I retrieve the dictionary, all the values are zero.

I committed all the changes to the repo. Just in case, here is the native code I added to return the dictionary with the image information:

JNIEXPORT jobject JNICALL Java_jsyphon_JSyphonClient_newFrameDataForContext(JNIEnv * env, jobject jobj)
jobject imgdata = nil;

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

[(SyphonNameboundClient*)mClient lockClient];
SyphonClient *client = [(SyphonNameboundClient*)mClient client];
SyphonImage* img = [client newFrameImageForContext:CGLGetCurrentContext()];

NSSize texSize = [img textureSize];

NSNumber *name = [NSNumber numberWithInt:[img textureName]];
NSNumber *width = [NSNumber numberWithFloat:texSize.width];
NSNumber *height = [NSNumber numberWithFloat:texSize.height];
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:
name, @”name”,
width, @”width”,
height, @”height”,

JNFTypeCoercer* coecer = [JNFDefaultCoercions defaultCoercer];
[JNFDefaultCoercions addMapCoercionTo:coecer];

imgdata = [coecer coerceNSObject:dic withEnv:env];

[(SyphonNameboundClient*)mClient unlockClient];

[pool drain];

return imgdata;

The dictionary object is passed correctly to Java, but as I said, all the values are set as zero.

My experience with Objective-C and JNI is limited, let me know if you see anything obviously wrong.