![]() |
quickie | The quickie class and in-Max development |
As mentioned in the previous section, sending a "viewsource" message to any instance launches an editing environment. If the .java file for the object's peer Java class and the class file are in the same directory, the source code will be loaded into the editor window. One can make changes to the code and save from the editor window's File:Save menu item. One can also compile using the Java:Compile... menu item. Before compiling the MXJ Compile Window presents options for source location, compiler command, build directory, classpath, and compiler options. The default settings should work using standard installations of Max/MSP and Java. If the default path to your Java compiler isn't correct, or you would like to use a different Java compiler, you can use the browse button to choose a new compilation command. This setting will be remembered until it is changed again, even after exiting the application.
In the event that a .java file can't be found, a dissasembly of the .class bytecode is attempted. We currently use the JODE library (http://jode.sourceforge.net) to handle decompilation duties. If the class is decompiled from a .JAR library, the auto-generated source code must be saved to a new file before compilation.
After a successful compilation any changes made will only be reflected in subsequent instantiations of the class. All objects of the class that were instantiated before the class changed will continue to operate as instances of the old class. Furthermore, if you have not enabled the max.classloader.fromdisk option (as explained in Configuring), the class file will only reload if an instance of the class receives a "_zap" message. Otherwise Max will use the version of the class that it has cached from a previous instantiation. If max.classloader.fromdisk is enabled, every new instance of the class will load the .class file directly from disk. Although convenient for the developer, this option is by default off because it substantially slows down the creation of new mxj objects.
Another nice tool that the in-Max editing environment provides is the Class Reference window. Highlight any class and press command-D if using Mac or ctrl-D if using Windows. The Max Class Reference window that pops up provides a breakdown of the class's fields and methods.
Another way to access a class's source is through the quickie class. quickie takes as an argument the name of a class. For instance you might initialize a new Max object as "mxj quickie MyClass". If you then were to send a bang to or double-click on the newly created object, the editor environment would load with the MyClass code. If MyClass.java and MyClass.class cannot be found, the editor opens with a template class. This template class is defined by the contents a file called QUICKIE_PROTO which can be anywhere in Max's search path. By default QUICKIE_PROTO looks like this:
import com.cycling74.max.*;
public class MyClass extends MaxObject
{
public MyClass(Atom[] args)
{
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});
}
public void bang()
{
}
public void inlet(int i)
{
}
public void inlet(float f)
{
}
public void list(Atom[] list)
{
}
}