JavaQCView (Composition by dust)

Author: dust
License: MIT
Date: 2011.01.16
Compatibility: 10.6
Categories:
Required plugins:
(none)

this isn't really a composition its basically a java jni lib to render quartz composer in java. eventually i will have the messaging system working so you can send messages back and forth from qc to java....

right now it just loads a qc comp from the repo and displays it in java. the principles are derived from a deprecated apple dev example "qc cocoa component" circa 2005.

even though this builds a binary java app, i don't see why the lib couldn't be used in processing to display a qc comp.

don't know if the helps anybody but i certainly like being able to load a qc comp in java. the next step is to get published inputs and outputs working.

PreviewAttachmentSize
QCJ.zip7.82 MB

jrs's picture
Re: JavaQCView (Composition by dust)

Great idea - can't wait to have a play around

randall's picture
Re: JavaQCView (Composition by dust)

Impressive! Very excited to see more.

idlefon's picture
Re: JavaQCView (Composition by dust)

Brilliant! Will this shed any light on working Java in QC ie. being able to use processing sketches in QC?

cybero's picture
Re: JavaQCView (Composition by dust)

Well I ran this through XCode and although I get a java executable, it is black empty space, no rendering, successful build except for one warning

/Users/cybero/Desktop/QCJ/make/build.xml:59:0 /Users/cybero/Desktop/QCJ/make/build.xml:59: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

Interesting stuff though.

/////////////////////////////////////////// postscript ///////////////////////////////////////////

just updating XCode to the latest build - oops ;-)

////////////////////////////////////////// posts-postscipt/////////////////////////////////

and then again, post update , little or no difference, found three more error messages

/Users/cybero/Desktop/QCJ/src/native/JavaQCView.m:16:0 /Users/cybero/Desktop/QCJ/src/native/JavaQCView.m:16: warning: incomplete implementation of class 'JavaQCView'
 
 
/Users/cybero/Desktop/QCJ/src/native/JavaQCView.m:16:0 /Users/cybero/Desktop/QCJ/src/native/JavaQCView.m:16: warning: method definition for '-awtMessage:message:env:' not found
 
 
/Users/cybero/Desktop/QCJ/src/native/JavaQCView.m:16:0 /Users/cybero/Desktop/QCJ/src/native/JavaQCView.m:16: warning: class 'JavaQCView' does not fully implement the 'AWTCocoaComponent' protocol

& finally figured out it had nothing to do with the XCode update, and if I presented a different long path to file to be loaded in the JavaQCView.m file, then the applet worked well.

Cheers

:-)

[After all that]

It'd be nice to have like a facility to choose a file to load in. How can we get Kineme Audio Tools support into the Java Application? [by which I mean setting of composition dependent preferences, so you could publish up patch options, etc] Wouldn't it be neat if the OS X plugin support could be extended to Java Applets and applications? [like QB bundles the plugin]. I am unsure as to how broadly supportable plugin dependent comps would be in an environment without such frameworks and extensions.

I tried one of my KAT based comps and it renders the audio data and plays sound :-), sweet.

The facility to distribute QC java executables is still just a Mac only thing, due to framework dependencies, yeah?

dust's picture
Re: JavaQCView (Composition by dust)

sorry about that cybero. if your getting a can't find javaVM jni.h type of error that means you need to install the latest java developer tools update from apple. not java update 3 but the java dev update found in ADC downloads page. you would think updating x code would do this for you ?

i would say its mac specific only as it uses the qc framework, i think there maybe other type of cocoa or ns things you can do on pc in java ?. i don't have a pc so its all a guess right now ????? the ewat-stubs file is a bin jar file so reading it on a pc jvm would be possible but im not sure what the extent of the obj-c on a pc is to tell you what could be done and what couldn't in regards to frameworks.

i suppose those errors are saying that i need to start messaging system as the i have not fully implemented the component. apples dev docs say you don't have to implement messaging. they all say not to release anything. must have something to do with java garbage collection. you will get a bunch memory leakage reports in the console while this app launches, once the app is launched then there are no more leaks.

cybero's picture
Re: JavaQCView (Composition by dust)

Seems deliciously ironic that OpenCL [championed and proselytised by Apple, should probably prove to provide something that could be more easily Cindered than CoreImage.

Of course, one could go OpenGL for a lot of purposes. QC, very OS / Device dependent.

I shall have to take another look at my environment [Java especially].

Currently the project buildsĀ and runs.

Neat.

Java , being a Sun & partners thing is a notorious lag behind for 3rd party OS Java environment implementers , like Apple and Microsoft.

offonoll's picture
Re: JavaQCView (Composition by dust)

Would this work to implement QCompositions on the web?

dust's picture
Re: JavaQCView (Composition by dust)

pretty sure applets work on the web. i think cybero mentioned he made an applet ? interesting question though. maybe it might make the unsafe / safe qtz native qtz embed thing a bit easier to deal with ? will give it go. i want to incorporate messaging first but for what ever reason my messageID is null ? dealing with java in xcode is weird for me. i used the jni template to make this. i will get the hang of it soon. thinking that a drag and drop zone solution might be nest rather this hardcoded path.

dust's picture
Re: JavaQCView (Composition by dust)

hmmm interesting using processing sketches in qc. i will think about that for min and get back to you.

idlefon's picture
Re: JavaQCView (Composition by dust)

Looking forward to it :D!

djfil's picture
Re: JavaQCView (Composition by dust)

I also would like to test this. Though i haven't been able to build it.

error: JavaVM/AWTCocoaComponent.h: No such file or directory

But the .h file exists. Under:

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Headers

And the JavaVM path is:

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework

I'm building it in xcode 3.2.5 64bit

What Am i forgetting? I'm not used to work with xcode. Thanks for any help

idlefon's picture
Re: JavaQCView (Composition by dust)

Sorry for asking again , but did you have any success with this?

gtoledo3's picture
Re: JavaQCView (Composition by dust)

Using java as a framework in an application that runs a qc comp, and integrating Processing into QC so that it outputs an image that can be rendered via a qc plugin are peripherally related at best.

dust's picture
Re: JavaQCView (Composition by dust)

first install the normal java update 3 for os x 10.6...

http://support.apple.com/downloads/Java_for_Mac_OS_X_10_6_Update_3

after i did this all kinds of things showed up missing, particularly the java native stuff so this will totally ruin your java vm if you had previously your system set up for java before. to fix this you need to install.

"Java for Mac OS X 10.6 (10M3310) (Disk Image)"

http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/5.1.17.2.1...

not sure if that link will bring to the right page but its the developer downloads page just click on java from the list on the right hand side and get the latest java dev update from jan 06 2011.

this should build fine if you get the latest update. i think 10.6.6 kind of changed things for java. seems maybe apple is phasing java out of its pipeline ? i don't know.

sometimes i have to work in java and it bugs me that i can not render a qc view. obviously using qc in its native environment is ideal, but sometimes we don't live in an ideal world.

the syphon project seems to be the best solution to most of our inter application needs.

i did try the other night to do a gl to cl texture inter-op with quartz composer, thinking that it may be possible to just grab another programs gl texture and or buffer then use open cl to render the gl texture in quartz composer but qc doesn't like the cl mem functions. i know this is possible, and that maybe someday i would like to build a plugin that does this inter-op taking lets say a java gl texture then sharing that texture with open cl and rendering back into qc's gl context as a plugin output.

seems to me that may be the ideal solution but i have been using syphon or v002 screen grab to just get things into qc which is essentially the same thing i'm talking about.

as per making a java plugin for quartz composer, it may be possible with the cocoa java binding or what ever but doesn't seem like thats an ideal solution.

now i could see a python type of plugin for qc as good thing ?

vade's picture
Re: JavaQCView (Composition by dust)

The only way you are going to get texture or GPU resources from one application to another is with readback or with IOSurface. The texture contents and protected memory setups on modern OS's prohibit this sort of sharing unless it has been expressly 'opted in' by both applications. It wont work.

Now, if you load the java runtime within the application address space of say a Cocoa app, that is 100% possible, but its no longer "inter process" so to speak.

If you have are interested in getting some JNI code working with Syphon, I would love to see it. I have yet to have any time to really look into it. It seems you are getting a grip on it. If you can pull in a Syphon Image and render into a JOGL view, or take a JOGL texture and send it to Syphon, that would be really helpful. Myself and Tom would be more than willing to help if there are hiccups along the way.

Let me know.

djfil's picture
Re: JavaQCView (Composition by dust)

Not yet.

cc1obj: error: /var/folders/XT/XTVVGCcmH3WcozpfCGSD7U+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/AppKit-brihgptzhchjmbfsjcnlwbaibgbd/AppKit.h: No such file or directory

cc1obj: error: one or more PCH files were found, but they were invalid

cc1obj: error: use -Winvalid-pch for more information

dust's picture
Re: JavaQCView (Composition by dust)

The interop cl / gl mem share is totally possible but like you said you need to set up memory allocations in gl to grab it as a reference cl. this means you have to switch ownerships, but you can not do that unless define a shared context. the pdf i have isn't exactly clear on if this shared context is in reference to same address space or if it is only a shared context between cl and gl ? either way these cl mem commands are not possible in a qc cl kernel. thanks though vade, this sharing gl resources with cl is a bit confusing, that is why i thought it may be possible. if you didn't say anything i would have kept trying as the ucdavis docs i have totally say sharing gl resources is possible.

I checked out syphon for unity and qtz + max, looked for ofx syphon couldn't find that one. i know it exists. i watched a keynote from the guy who runs the open kinect git and he mentioned ofx syphon being one of the newer additions etc.. I will checkout the syphon project again and have a look at it.

Im thinking it might be easier to run a syphon in a java view rather than the other way around. I don't remember how you built the syphon framework but your example server client apps are extern c and can render to a nsview then this cocoa component would render it.

i will see what i can do maybe have a look at the unity plugin as the jni is sort of similar in those regards.

dust's picture
Re: JavaQCView (Composition by dust)

oh man the only time i have got one of those errors is when i was changing names around and stuff or if i have tried building the same project with the same name in the same spot many many times or did a combination of changing names and building many many times without cleaning.

what i would do is trash the build folder completely not just the debug folder save the project and restart your computer to clean out the x code cache.

cwright's picture
Re: JavaQCView (Composition by dust)

dust wrote:
The interop cl / gl mem share is totally possible but like you said you need to set up memory allocations in gl to grab it as a reference cl. this means you have to switch ownerships, but you can not do that unless define a shared context. the pdf i have isn't exactly clear on if this shared context is in reference to same address space or if it is only a shared context between cl and gl ?

not quite -- GL and CL have different contexts entirely; however, you can create a CL context associated with a GL context, and share resources between the two freely. This is exclusively in terms of the same address space -- shared contexts have exactly zero to do with cross-address space resources. The only (and by only, I mean it) ways to move gl/cl resources between processes are 1) IOSurface ("free") or 2) manual IPC (via mach shmems or posix shmem -- the former is complex but flexible, the latter is simpler but more constrained) ("decidedly not free"). For any non-trivial usage, it will be IOSurface or bust. There is no option 3.

dust wrote:
Im thinking it might be easier to run a syphon in a java view rather than the other way around. I don't remember how you built the syphon framework but your example server client apps are extern c and can render to a nsview then this cocoa component would render it.

i will see what i can do maybe have a look at the unity plugin as the jni is sort of similar in those regards.

Why is there so much emphasis on java? I'm genuinely curious; it's not a well-supported platform on OS X, and it provides no real benefits in this context. obj-c is a much saner approach to this stuff. I don't think java even has IOSurface bindings, so you're going to have to write a JNI interface to that, and ensure that you get it right. OR you could just use C, and get IOSurface for free...

vade's picture
Re: JavaQCView (Composition by dust)

Er, of course OpenGL and OpenCL resource sharing is doable, that was never in question ;) You have to init your GL context so it has a valid pixel format, and init your compute context with the proper compute device and pass in the share context so it knows they are compatible. Apple has example code for this.

If you have played with GL context sharing, its similar.

The issue with Java is getting down to the lower level CGLContextObjs and 'owning' the pixel formats passed in, allowing you to set up share contexts and compute contexts as you need them.

You could totally set up a GL and CL share context yourself in a QC plugin.

I dont know what you are asking about address space, if you are in a single app, all APIs regardless of what they are share the same variable. a CL context pointer is in the address space of the application that spawned it just like a GL context or a void*.

djfil's picture
Re: JavaQCView (Composition by dust)

=) Basic stuff. Sory.

That solved my problem.

It works.

Thank you, very much.

And you say this would work in applets. I wonder if i can change qtz file in real time, or it just reads and "reproduce" to java.

Thanks again

dust's picture
Re: JavaQCView (Composition by dust)

i don't know what the emphasis is on java. i was just messing around one afternoon, as i wanted to contribute to someones svn that uses java with eclipse and i like to use obj qc++ ? so i was seeing how hard it would be to get the deprecated java qc view running.

honestly java is like flash to me a sort of last resort that makes me cringe inside when ever anybody says they want to do a group project in either language. hey i made some really cool things with macromedia during the shockwave era so its not like i don't know how to use either tech.

it just seems these technologies apples isn't really supporting much. i do however think both technologies have a huge constituency still in other markets. maybe not that much so on these boards for obvious reasons but thought some people might be able to get some use out of it ?

i must say i really like programming in objective qc++.its not an easy language to understand at first in comparison to java. i mean java was like ok i can read that but the first time i saw cocoa it looked like russian. nobody at my university uses quartz or cocoa... nobody is teaching them either so its kind of like i have to use java sometimes.

i just built an app to meet the mac store specs using qtz. freaking awesome.... its literally possible to build a mac app without writing a single line of code. seriously i don't think apple could make it any easier for people.

in xcode you go file> new cocoa project >file > add xib > drag n' drop a composition and build. viola. obviously adding a custom patches and binding a core data model to your published parameters requires a bit of code.

i may be wrong though ? it might be possible to bind a core data model to a composition in interface builder without writing code. well you would still need to write at least a few lines of code to make a custom patch and load it.