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.
IndexProgramming Questions & HelpIntegration › Max with Processing GUI
Page Index Toggle Pages: 1
Max with Processing GUI (Read 1607 times)
Max with Processing GUI
Jan 25th, 2007, 5:17pm
 
I have a MIDI controller going through Max into an mxj object which allows the controller to act as a "meta-controller" -- for example, allowing me to switch MIDI channels or have higher level control over CCs. All of the above is in Java without the Processing libraries, developed in Eclipse.

I want to visualize what I'm controlling using a Processing window, so I wrote a PApplet that does that. There are two difficulties I'm having:

- Is there a 'right way' of giving the PApplet a reference to my meta-controller object, so it can visualize it? Right now, instead of saying:

Code:
PApplet.main(new String[]{"MyApplet"}); 



I say:

Code:
MyApplet applet = new MyApplet(metaController); 



And then call a method that acts like PApplet.main() to setup the window and whatnot. (If PApplet.main() returned PApplet, I would have used that and passed the metaController via a separate method -- it'd be great if the meat of main() was in another method that returned the PApplet, and main() simply called that method).

- The way I have is working for now, except: if I close the Java window before closing Max, CPU usage goes to 99% for Max and it takes a few minutes to stop the Max process. Also, if I close the patch alone, the Java window remains. Do I need to stop() the sketch before closing the window? Any ideas?

I'm very familiar with maxlink and other UDP solutions to Max + Processing communication, but it wouldn't be right for this project -- it would be unwieldy to send all the visualization information across the subnet.
Re: Max with Processing GUI
Reply #1 - Jan 29th, 2007, 6:39pm
 
The solution to the second problem is to not call System.exit() inside the windowClosing listener, but call dispose() instead. See How to Make Frames.

If anyone has a better solution to my first question, let me know. Again, it would be great if there were a method in PApplet:

Code:
public static PApplet makeApplet(String[] args); 



Which would do the same thing as Papplet.main() right now, except it returns the PApplet. (PApplet.main() would call makeApplet(), of course).
Re: Max with Processing GUI
Reply #2 - May 23rd, 2007, 4:34pm
 
Don't know if you already got this working, but I managed to get Processing running in Max today, via mxj.

First, I made an mxj wrapper for the Max "box":

Code:

package kompose;

import processing.core.*;
import com.cycling74.max.*;

public class Kompose_GUI extends MaxObject
{
GUILoader gui;
public Kompose_GUI()
{
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});

declareIO(1,4);

gui = new GUILoader();
}
}

Then I created a loader for the Processing window, based on the "Embedded" example from the processing.core docs:

Code:

package kompose;

import java.awt.BorderLayout;
import java.awt.Frame;
import processing.core.*;

public class GUILoader extends Frame
{
public GUILoader()
{
setLayout(new BorderLayout());
setSize(1024, 712);
setVisible(true);
PApplet embed = new Main();
add(embed, BorderLayout.CENTER);
embed.init();
}
}


Seems pretty good, though tryng to hide/show it with setVisible() causes Max some serious anxiety! Hope this helps.

cheers,

J.
Re: Max with Processing GUI
Reply #3 - May 23rd, 2007, 4:36pm
 
Oh yeah, just a note that you have to either include core.jar as a dynamic class in the max java config file, or put a copy of core.jar in your c74/java/lib directory.

J.
Re: Max with Processing GUI
Reply #4 - May 24th, 2007, 11:19am
 
Well, now that I've got Processing loded into Max via mxj, I need to actually communicate with it. Everything I can find online is suggesting that, once I have the applet (or PApplet, in this case), I should be able to call the public methods of that applet/PApplet. But I can only call public methods of PApplet, not my sketch's PApplet, which obviously extends PApplet. So... I'm confused.

Any light to be shed?

J.
Re: Max with Processing GUI
Reply #5 - May 24th, 2007, 12:22pm
 
hehe... talking to myself, apparently.

I found it in another thread. I had embedded the PApplet, not my extending class. Sorry for the spam.

J.
Re: Max with Processing GUI
Reply #6 - Nov 26th, 2007, 8:34pm
 
jbmaxwell -- did you have any difficulties with closing Max vs. closing your patch vs. closing the Processing window? If not, I'll go your route. I will be revisiting this issue within the next week for another project and it'd be nice to have a "clean" solution.
Page Index Toggle Pages: 1