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 & HelpSyntax Questions › Use of Processing libraries inside of Java apps
Page Index Toggle Pages: 1
Use of Processing libraries inside of Java apps (Read 811 times)
Use of Processing libraries inside of Java apps
Aug 30th, 2009, 2:48am
 
Hello, I'm currently trying to get the proMIDI library to work inside of a Java application as opposed to a Processing sketch.

It requires that I instantiate a MidiIO like this:

Code:
midiIO = MidiIO.getInstance(this); 



However, the argument given to getInstance has to be a PApplet. In processing, this is no problem, but in Java, it complains that it doesn't receive a PApplet and therefore, it doesn't instantiate. The Javadocs of proMIDI say that you can instantiate without any arguments, like this:

Code:
midiIO = MidiIO.getInstance(); 



But this doesn't work either.

So I'm asking you guys, does anyone of you have any experience with using Processing libraries inside of Java? And what do you do when the library needs a PApplet as argument?

Thanks in advance...
Re: Use of Processing libraries inside of Java apps
Reply #1 - Aug 30th, 2009, 3:04am
 
midiIO = MidiIO.getInstance(new PApplet());?
(untested)
It can be more complex than that with some libraries, which might expect to be run inside a PApplet.
Re: Use of Processing libraries inside of Java apps
Reply #2 - Aug 30th, 2009, 3:14am
 
Hey thanks, but for that to work, the Java app would have to have access to a PApplet class.

I can try to get it working with an empty class and see what happens, but I guess it won't work because it'll need to access some methods from a 'real' PApplet class.

My best guess is I have to somehow change my main class so it emulates a PApplet... thereby including methods that proMIDI might access, I'll take a look at the source code.

But the thing that strikes me is that proMIDI was made for Processing and Java. Surely there must be another way of doing this kind of stuff...
Re: Use of Processing libraries inside of Java apps
Reply #3 - Aug 30th, 2009, 3:32am
 
This is the error I get, pretty logical...

Code:
Exception in thread "main" java.lang.NoClassDefFoundError: processing/core/PApplet
at promidi.MidiIO.getDeviceInfo(MidiIO.java:180)
at promidi.MidiIO.getAvailablePorts(MidiIO.java:210)
at promidi.MidiIO.<init>(MidiIO.java:131)
at promidi.MidiIO.getInstance(MidiIO.java:155)
Re: Use of Processing libraries inside of Java apps
Reply #4 - Aug 31st, 2009, 10:00am
 
Okay, I fixed the problem.

Instead of worrying how to give a PApplet class to the getInstance() method I copied the entire source code of proMIDI to my source instead of just referencing to the library and adjusted all references to PApplet in the MidiIO class to accept my GUI class.

Works great!
Page Index Toggle Pages: 1