com.cycling74.max
Class MaxObject

java.lang.Object
  extended by com.cycling74.max.MaxObject
Direct Known Subclasses:
MSPObject

public class MaxObject
extends Object

Main object to extend to use with pd. The name of this class will reflect the name of the pdj object when it is instanciated.

Here is a basic guideline for using the MaxObject:

 
 import com.cycling74.max.*;

 public class example extends MaxObject {
 
    // called when arguments are used in object creation
    public example(Atom args[]) {
        for(int i=0;i<args.length;i++) {
           post("args:" + args[i].toString());
        }
    }
 
    // this method will be called when a float is sended to the object
    public inlet(float f) {
        post("hello float:" + f);
        outlet(0, f);
    }
 
    // this method will be called when symbol callme is sended to the object
    public callme(Atom args[]) {
        post("hello object:" + args[0]);
        outlet(0, args[0]);
    }
 
    // this method will be called when bang is sended to the object
    public bang() {
        post("hello bang");
        outletBang(0);
    }
 }
 

Compile this class by adding pdj.jar on the classpath and put the example.class in the classes directory found in your pdj home. You can also edit directly this class in the classes directory and pdj will try to compile it for you.


Field Summary
static String[] EMPTY_STRING_ARRAY
          Defined in the original MXJ API; don't know what it is used for...
static int[] NO_INLETS
          Use this to declare that your object has no inlets.
static int[] NO_OUTLETS
          Use this to declare that your object has no outlets.
 
Constructor Summary
protected MaxObject()
          Default constructor for MaxObject.
 
Method Summary
protected  void anything(String symbol, Atom[] args)
          Called by PD when pdj receives an un-overriden method.
protected static void bail(String errormsg)
          Bail will throw an exception upon object instanciation.
protected  void bang()
          Called by PD when pdj receives a bang from an inlet.
protected  void createInfoOutlet(boolean flag)
          Tells the constructor to create a info outlet.
protected  void declareAttribute(String name)
          Creates a attribute with default setter and getter.
protected  void declareInlets(int[] types)
          Declare the inlets used by this object.
protected  void declareIO(int in, int out)
          Quickie method for declaring both inlet and outlet that will use any type of message (DataTypes.ANYTHING)
protected  void declareOutlets(int[] types)
          Declare the outlets used by this object.
protected  void declareReadOnlyAttribute(String name)
          Creates a attribute with default getter no setter.
protected  void declareTypedIO(String ins, String outs)
          Used to defined typed input and output for this object.
protected  void embedMessage(String msg, Atom[] args)
          NOT USED IN PD.
static void error(String message)
          Will show an error message in the pure-data console.
 void gc()
          Useless, but in the original API.
static Object getContext()
          NOT USED IN PD. Throws UnsupportdOperationException
static com.cycling74.io.ErrorStream getErrorStream()
          Returns the error stream of PDJ.
 int getInfoIdx()
          Returns the index of the info outlet
protected  int getInlet()
          Returns the index of the inlet that has just received a message.
 int getInletType(int idx)
          Returns the type the inlet at index 'idx'.
 String getName()
          Returns the object name.
 int getNumInlets()
          Returns the number of inlets declared.
 int getNumOutlets()
          Returns the number of outlets declared.
 int getOutletType(int idx)
          Returns the type of the outlet at index 'idx'.
 MaxPatcher getParentPatcher()
          Returns the object representing the pd patch.
static com.cycling74.io.PostStream getPostStream()
          Returns the output stream of PDJ.
protected  void inlet(float f)
          Called by PD when pdj receives a float from an inlet.
protected  void inlet(int i)
          This will be called if pd sends a float and the float method is not overridden.
protected  void list(Atom[] args)
          Called by PD when pdj receives a list of atoms.
protected  void loadbang()
          Called by PD when the current patch issue a loadbang message.
 void notifyDeleted()
          This method is called when the object is deleted by the user.
static void ouch(String message)
          Will show an error message in the pure-data console and crash pure-data.
 boolean outlet(int outlet, Atom value)
          Sends atom value to outlet x.
 boolean outlet(int outlet, Atom[] value)
          Sends atoms to outlet x.
 boolean outlet(int outlet, byte value)
          Sends a byte to outlet x.
 boolean outlet(int outlet, byte[] value)
          Sends byte to outlet x.
 boolean outlet(int outlet, char value)
          Sends a char to outlet x.
 boolean outlet(int outlet, char[] value)
          Sends char to outlet x.
 boolean outlet(int outlet, double value)
          Sends a double to outlet x.
 boolean outlet(int outlet, double[] value)
          Sends doubles to outlet x.
 boolean outlet(int outlet, float value)
          Sends a float to outlet x.
 boolean outlet(int outlet, float[] value)
          Sends floats to outlet x.
 boolean outlet(int outlet, int value)
          Sends a int to outlet x.
 boolean outlet(int outlet, int[] value)
          Sends ints to outlet x.
 boolean outlet(int outlet, long value)
          Sends a long to outlet x.
 boolean outlet(int outlet, long[] value)
          Sends longs to outlet x.
 boolean outlet(int outlet, short value)
          Sends a short to outlet x.
 boolean outlet(int outlet, short[] value)
          Sends shorts to outlet x.
 boolean outlet(int outlet, String value)
          Sends a symbol to outlet x.
 boolean outlet(int outlet, String[] value)
          Sends symbols to outlet x.
 boolean outlet(int outlet, String message, Atom[] value)
          Sends message with argument to outlet x.
 boolean outletBang(int outlet)
          Sends a bang to outlet x.
 boolean outletBangHigh(int outlet)
           
 boolean outletHigh(int outlet, Atom[] value)
           
 boolean outletHigh(int outlet, double value)
           
 boolean outletHigh(int outlet, float value)
           
 boolean outletHigh(int outlet, int value)
           
 boolean outletHigh(int outlet, String value)
           
 boolean outletHigh(int outlet, String msg, Atom[] args)
           
static void post(String message)
          Will show an info message in the pure-data console.
protected  void save()
          NOT USED IN PD.
protected  void setInletAssist(int index, String message)
          NOT USED IN PD.
protected  void setInletAssist(String[] messages)
          NOT USED IN PD.
 void setName(String name)
          Sets the object name.
protected  void setOutletAssist(int index, String message)
          NOT USED IN PD.
protected  void setOutletAssist(String[] messages)
          NOT USED IN PD.
static void showException(String message, Throwable t)
          Show the exception in the pure-data console with a message.
static void showException(Throwable t)
          Show the exeception in the pure-data console.
 void viewsource()
          NOT USED IN PD.
 void zap()
          Refresh/reinitialize the PDJ classloader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_INLETS

public static final int[] NO_INLETS
Use this to declare that your object has no inlets.


NO_OUTLETS

public static final int[] NO_OUTLETS
Use this to declare that your object has no outlets.


EMPTY_STRING_ARRAY

public static final String[] EMPTY_STRING_ARRAY
Defined in the original MXJ API; don't know what it is used for...

Constructor Detail

MaxObject

protected MaxObject()
Default constructor for MaxObject. You can add an constructor that supports Atom[] to read object creation arguments. It is not defined in this API since it does not to force a 'super()' call in all the extended class.

Method Detail

error

public static void error(String message)
Will show an error message in the pure-data console.

Parameters:
message - the string to show

post

public static void post(String message)
Will show an info message in the pure-data console.

Parameters:
message - the string to show

ouch

public static void ouch(String message)
Will show an error message in the pure-data console and crash pure-data. Do not use if you have no friend left.

Parameters:
message - the message to show when you make pd crash

showException

public static void showException(Throwable t)
Show the exeception in the pure-data console.

Parameters:
t - the exception it self

showException

public static void showException(String message,
                                 Throwable t)
Show the exception in the pure-data console with a message.

Parameters:
message - the message that comes with the exception
t - the exception it self

getName

public String getName()
Returns the object name.

Returns:
the pdj object name

setName

public void setName(String name)
Sets the object name.

Parameters:
name - pdj object name

notifyDeleted

public void notifyDeleted()
This method is called when the object is deleted by the user.


bail

protected static void bail(String errormsg)
Bail will throw an exception upon object instanciation. This is usefull if you have a missing requirement and you want to cancel object creation.

Parameters:
errormsg - the error message to show

declareInlets

protected void declareInlets(int[] types)
Declare the inlets used by this object.

Parameters:
types - the type of message that this inlet will use.
See Also:
DataTypes

declareOutlets

protected void declareOutlets(int[] types)
Declare the outlets used by this object.

Parameters:
types - the type of message that this inlet will use.
See Also:
DataTypes

declareTypedIO

protected void declareTypedIO(String ins,
                              String outs)
Used to defined typed input and output for this object. Strings are used to define the type of inlet/outlet. For example, "ffi" will create a float/float/integer inlet/outlet. 'f' denotes a float, 'i' a int, 'm' a message, 'l' a list, 's' for a signal. Anything else will be considered as a outlet of type anything. PD doesn't type all data yet, so every inlet/outlet are typed as anything; except for signals.

Parameters:
ins - list of inlet to create
outs - list of outlet to create

declareIO

protected void declareIO(int in,
                         int out)
Quickie method for declaring both inlet and outlet that will use any type of message (DataTypes.ANYTHING)

Parameters:
in - the number of inlet to create
out - the number of outlet to create

declareAttribute

protected void declareAttribute(String name)
Creates a attribute with default setter and getter. The name used is actually a java field in the current class. Later, you can send 'a 10' and pdj will set 10 to your java field named 'a'. You can also use 'get a' that will return its value to the info outlet. The info outlet is the last outlet of your object.

Parameters:
name - name of the java field in this class to map.

declareReadOnlyAttribute

protected void declareReadOnlyAttribute(String name)
Creates a attribute with default getter no setter. The name used is actually a java field in the current class.

Parameters:
name - name of the java field in this class to map.

createInfoOutlet

protected void createInfoOutlet(boolean flag)
Tells the constructor to create a info outlet. The info outlet is used by attributes when the get method is used. The return value of the 'get' will be return to this outlet. The info outlet is always the last outlet of the object. By default, the info outlet is always created.

Parameters:
flag - false to prevent the creation of the info outlet

getInletType

public int getInletType(int idx)
Returns the type the inlet at index 'idx'. Not fully implemented, returns always DataTypes.ANYTHING with pdj

Parameters:
idx - the outlet position
Returns:
the DataType of the inlet

getOutletType

public int getOutletType(int idx)
Returns the type of the outlet at index 'idx'. Not fully implemented, returns always DataTypes.ANYTHING with pdj

Parameters:
idx - the outlet position
Returns:
the DataType of the outlet

getNumInlets

public int getNumInlets()
Returns the number of inlets declared.

Returns:
the number of inlets used by this object

getNumOutlets

public int getNumOutlets()
Returns the number of outlets declared.

Returns:
the number of outlets used by this object

loadbang

protected void loadbang()
Called by PD when the current patch issue a loadbang message.


getInlet

protected int getInlet()
Returns the index of the inlet that has just received a message.

Returns:
the index of the inlet

getInfoIdx

public int getInfoIdx()
Returns the index of the info outlet


outletBang

public final boolean outletBang(int outlet)
Sends a bang to outlet x.

Parameters:
outlet - the outlet number to use
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            float value)
Sends a float to outlet x.

Parameters:
outlet - the outlet number to use
value - the float value
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            float[] value)
Sends floats to outlet x.

Parameters:
outlet - the outlet number to use
value - the array of float to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            String value)
Sends a symbol to outlet x.

Parameters:
outlet - the outlet number to use
value - the symbol
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            String[] value)
Sends symbols to outlet x.

Parameters:
outlet - the outlet number to use
value - the array of symbol to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            byte value)
Sends a byte to outlet x.

Parameters:
outlet - the outlet number to use
value - the byte value
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            byte[] value)
Sends byte to outlet x.

Parameters:
outlet - the outlet number to use
value - the array of byte to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            char value)
Sends a char to outlet x.

Parameters:
outlet - the outlet number to use
value - the char value
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            char[] value)
Sends char to outlet x.

Parameters:
outlet - the outlet number to use
value - the array of char to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            short value)
Sends a short to outlet x.

Parameters:
outlet - the outlet number to use
value - the short value
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            short[] value)
Sends shorts to outlet x.

Parameters:
outlet - the outlet number to use
value - the array of short to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            int value)
Sends a int to outlet x.

Parameters:
outlet - the outlet number to use
value - the int value
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            int[] value)
Sends ints to outlet x.

Parameters:
outlet - the outlet number to use
value - the array of int to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            long value)
Sends a long to outlet x.

Parameters:
outlet - the outlet number to use
value - the long value
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            long[] value)
Sends longs to outlet x.

Parameters:
outlet - the outlet number to use
value - the array of longs to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            double value)
Sends a double to outlet x.

Parameters:
outlet - the outlet number to use
value - the double value
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            double[] value)
Sends doubles to outlet x.

Parameters:
outlet - the outlet number to use
value - the array of double to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            String message,
                            Atom[] value)
Sends message with argument to outlet x.

Parameters:
outlet - the outlet number to use
message - the message symbol name
value - the arguments
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            Atom value)
Sends atom value to outlet x. If it is a int/float, it will call outlet(int, float) otherwise outlet(int, String)

Parameters:
outlet - the outlet number to use
value - the atom value to send
Returns:
always true, since PD API returns void

outlet

public final boolean outlet(int outlet,
                            Atom[] value)
Sends atoms to outlet x. If the array contains only one item, outlet(outlet, Atom value) will be called. If the first element of the array is a float/int, list will be appended to the message. Otherwise, the first atom will be the message and the rest of it the arguments.

Parameters:
outlet - the outlet number to use
value - the arguments
Returns:
true or false if atom[] is empty

bang

protected void bang()
Called by PD when pdj receives a bang from an inlet. Use getInlet() to know which inlet has received the message.


inlet

protected void inlet(int i)
This will be called if pd sends a float and the float method is not overridden. Use getInlet() to know which inlet has received the message.

Parameters:
i - int value

inlet

protected void inlet(float f)
Called by PD when pdj receives a float from an inlet. Use getInlet() to know which inlet has received the message.

Parameters:
f - float value received from the inlet

list

protected void list(Atom[] args)
Called by PD when pdj receives a list of atoms. Use getInlet() to know which inlet has received the message.

Parameters:
args - the list

anything

protected void anything(String symbol,
                        Atom[] args)
Called by PD when pdj receives an un-overriden method. If you need to catch all messages, override this method. Use getInlet() to know which inlet has received the message.

Parameters:
symbol - first atom symbol representation
args - the arguments of the message

outletBangHigh

public final boolean outletBangHigh(int outlet)

outletHigh

public final boolean outletHigh(int outlet,
                                int value)

outletHigh

public final boolean outletHigh(int outlet,
                                float value)

outletHigh

public final boolean outletHigh(int outlet,
                                double value)

outletHigh

public final boolean outletHigh(int outlet,
                                String value)

outletHigh

public final boolean outletHigh(int outlet,
                                String msg,
                                Atom[] args)

outletHigh

public final boolean outletHigh(int outlet,
                                Atom[] value)

getPostStream

public static com.cycling74.io.PostStream getPostStream()
Returns the output stream of PDJ.

Returns:
the PrintStream output stream of PDJ

getErrorStream

public static com.cycling74.io.ErrorStream getErrorStream()
Returns the error stream of PDJ.

Returns:
the PrintStream error stream of PDJ

viewsource

public void viewsource()
NOT USED IN PD.


getContext

public static Object getContext()
NOT USED IN PD. Throws UnsupportdOperationException


getParentPatcher

public MaxPatcher getParentPatcher()
Returns the object representing the pd patch.


save

protected void save()
NOT USED IN PD.


setInletAssist

protected void setInletAssist(String[] messages)
NOT USED IN PD.


setInletAssist

protected void setInletAssist(int index,
                              String message)
NOT USED IN PD.


setOutletAssist

protected void setOutletAssist(String[] messages)
NOT USED IN PD.


setOutletAssist

protected void setOutletAssist(int index,
                               String message)
NOT USED IN PD.


embedMessage

protected void embedMessage(String msg,
                            Atom[] args)
NOT USED IN PD.


gc

public void gc()
Useless, but in the original API.


zap

public void zap()
Refresh/reinitialize the PDJ classloader.



This API is based on mxj for Max/MSP by Cycling74. Please see original MXJ implementation.