The
Hybrid Max-Java Application
Learning Objectives:
1.
Flow of Control (Max)
á asd IMPORTANT!!! Follow these instructions exactly:
File -> New -> Java Project
Under ÒProject NameÓ type ÒclassesÓ
Under ÒProject LayoutÓ select ÒUse project folder as root for sources and class
filesÓ
á
If you get the error
ÒA project with this name already existsÓ then cancel. Check the project folder (look under
Z:/workspace-win32/ for a folder called classes). If the folder has two sub-directories called ÒbinÓ and ÒsrcÓ
then this means the project has been created already but with the project
layout option that is incompatible with the MaxMSP set-up that we require. Rename the project or delete it
(depends on whether you have classes within it that you want to preserve) and
re-create the project following the steps above.
ExampleApplication1.maxpat
2.
Flow of Control (Java)
3.
Control Flow: Differences between Max and Java
Java VM running
ExampleApplication1.class
á Upon start up, the Java VM loads the class
ÒExampleApplication1Ó (as well as all other classes that are additionally
specified)
á The VM looks for the special method in that class
that is called ÒmainÓ
á It invokes the first line of the main method
á It invokes each line, one after the other
á When the last line of the main method is finished,
the Java VM stops running and closes
MaxMSP running
ExampleApplication1.maxpat
á Upon start up, it initialize all of its objects,
which will start up the Java VM
á Upon start up, the Java VM loads the class
ÒExternal Mxj ObjectÓ (as well as all other classes that are additionally
specified)
á The VM looks for the special method in that class
that is called ÒmainÓ
á The ÒExternal Mxj ObjectÓ application is designed
to initialize and then to stop and wait for incoming events
á The plugged-in component specifies what should
happen (if anything) when an incoming event is received
á When an event is received, the method with the name
corresponding to the eventÕs message gets invoked.
á The application is designed to keep running until
Max is stopped.
4.
Flow of Control (Max-Java Hybrid)
5.
Modification of the Max-Java Hybrid (Eclipse)
1. In Eclipse, make a change in the java code in HelloServices.java (e.g., instead of printing ÒHello!Ó to the console, print something else)
2. Save the code. Compilation will begin automatically. You can assure yourself of this by checking the time stamp of the file HelloServices.class ; if it doesnÕt, have a look at Project Ý Build Automatically. Ensure there is a check mark next to ÒBuild AutomaticallyÓ)
3. Switch to MaxMSP.
4. Close the current patch and re-open the current patch using one of the following:
a. File Ý Open Recent (select patch from list) [not necessary to close first]
b. Go to the file in the file browser and double click to (re)open it
Why do we need to do
this?
The Java Virtual
Machine running within MaxMSP needs to be told to use the new version of the
bytecode instead of the old version.
The only way to do this is to re-open the patch. If you neglect to do
steps 5a and 5b, then the old version of the bytecode will remain loaded. Any changes you made to the java
application will not be put into effect.
5. Re-open the patch ExampleApplication2.maxpat and run