com.cycling74.max
Class MaxPatcher

java.lang.Object
  extended by com.cycling74.max.MaxPatcher

public class MaxPatcher
extends java.lang.Object

MaxPatcher can be used in conjunction with MaxBox to dynamically modify and create patchers on the fly. The interface exposed is very similar to the functionality exposed by the js javascript external and thus much of that documentation for that external is applicable well.

 public class maxpatchertest extends MaxObject {
              
       public void makepatcher()
       {

               MaxPatcher p  = new MaxPatcher(50,50,200,200);
               MaxBox b11 = p.newDefault(20,20,"toggle",null);
               MaxBox b21 = p.newDefault(50,20,"toggle",null);
               MaxBox b31 = p.newDefault(80,20,"toggle",null);
                                 p.getWindow().setVisible(true);
               p.getWindow().setTitle("TEST PATCH");
              
       }
        
 }
   

created on 22-Jun-2004


Constructor Summary
  MaxPatcher(int x1, int y1, int x2, int y2)
          creates a MaxPatcher.
protected MaxPatcher(long p_patcher)
           
 
Method Summary
 void connect(MaxBox b1, int outlet, MaxBox b2, int inlet)
          Connect a patch line from box b1 to box b2 with default color.
 void connect(MaxBox b1, int outlet, MaxBox b2, int inlet, int color)
          Connect a patch line from box b1 to box b2.
 void disconnect(MaxBox b1, int outlet, MaxBox b2, int inlet)
          Disconnect a patch line from box b1 to box b2.
 boolean equals(java.lang.Object o)
           
protected  void finalize()
           
 MaxBox[] getAllBoxes()
          get a list of all boxes contained in this patcher.
 int getCount()
           
 java.lang.String getFilePath()
           
 java.lang.String getName()
           
 MaxBox getNamedBox(java.lang.String name)
          get the MaxBox contained in this patcher by name.
 int[] getOffset()
           
 int[] getOrigin()
           
 java.lang.String getParentMaxClass()
           
 java.lang.String getPath()
          get the absolute filesystem path of the file defining the patcher.
 MaxWindow getWindow()
           
 int hashCode()
           
 boolean isBPatcher()
           
 boolean isLocked()
           
 MaxBox newDefault(int x, int y, java.lang.String maxclassname, Atom[] args)
          Create a new MaxBox in this patcher.
 MaxBox newObject(java.lang.String msg, Atom[] args)
          Create a new MaxBox in this patcher.
 long send(java.lang.String msg, Atom[] args)
          send an arbitrary message to the patcher.
 void setBackgroundColor(int r, int g, int b)
          set the background color.
 void setLocked(boolean b)
          Set whether or not this patcher is locked.
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MaxPatcher

protected MaxPatcher(long p_patcher)

MaxPatcher

public MaxPatcher(int x1,
                  int y1,
                  int x2,
                  int y2)
creates a MaxPatcher. The patcher is created in a non visible state. To see the patcher use the setVisible method on its MaxWindow.

Parameters:
x1 - upper left corner x in absolute screen coordinates.
y1 - upper left corner y in absolute screen coordinates.
x2 - lower right corner x in absolute screen coordinates.
y2 - lower right corner y in absolute screen coordinates.
Method Detail

getPath

public java.lang.String getPath()
get the absolute filesystem path of the file defining the patcher.

Returns:
the absolute filesystem path of the file defining the patcher

send

public long send(java.lang.String msg,
                 Atom[] args)
send an arbitrary message to the patcher. See the help file for the max external thispatcher to see the sorts of messages you might want to send.

Parameters:
msg - the message to send thispatcher
args - arguments for the message to thispatcher. can be null.

setBackgroundColor

public void setBackgroundColor(int r,
                               int g,
                               int b)
set the background color.

Parameters:
r - red component
g - green component
b - blue component

isBPatcher

public boolean isBPatcher()
Returns:
true if this patcher is a bpatcher.

getNamedBox

public MaxBox getNamedBox(java.lang.String name)
get the MaxBox contained in this patcher by name. The name of max boxes are set via the Object menu of the max application or programatically using the MaxBoxclass.

Parameters:
name - the scripting name of the box you want a reference to
Returns:
a MaxBox instance representing the named box or null if no box named name exists in the patcher.

getAllBoxes

public MaxBox[] getAllBoxes()
get a list of all boxes contained in this patcher. Note that this will not recurse into subpatches but you can do that yourself by testing if a particular box is a subpatcher via the MaxBox isPatcher and getting a reference to it's MaxPatcher via it's getSubPatcher() method.

Returns:
array containing all the MaxBox instances contained within this patch.

newDefault

public MaxBox newDefault(int x,
                         int y,
                         java.lang.String maxclassname,
                         Atom[] args)
Create a new MaxBox in this patcher. Arguments can be passed as well. The example bellow shows how to create a non-UI object.
        MaxPatcher p = getParentPatcher();
        MaxBox b = p.newDefault(80,20,"newobj",Atom.parse("@text \"makenote 127 4n\" @textcolor 0. 0. 1. 1."));
To create a UI object:
        MaxPatcher p = getParentPatcher();
        MaxBox b = p.newDefault(100,50,"button",Atom.parse("@bgcolor 0. 0. 1. 1. @fgcolor 1. 0. 0. 0.8"));

Parameters:
x - location of x in patcher relative coordinates.
y - location of y in patcher relative coordinates.
maxclassname - the name of the max class you which to create an instance of in the patcher.
args - arguments to use when instantiating the max class.
Returns:
a new MaxBox or null on failure

newObject

public MaxBox newObject(java.lang.String msg,
                        Atom[] args)
Create a new MaxBox in this patcher. Using raw max patcher file syntax. For Example:
        --Create an instance of bpatcher containing noise~.help in patcher p.

     p.newObject("bpatcher",Atom.parse("10 10 100 100 0 0 noise~.help 0"));

Parameters:
maxclassname - the name of the max class you which to create an instance of in the patcher.
args - arguments to use when instantiating the max class.
Returns:
a new MaxBox or null on failure

connect

public void connect(MaxBox b1,
                    int outlet,
                    MaxBox b2,
                    int inlet,
                    int color)
Connect a patch line from box b1 to box b2.

Parameters:
b1 - MaxBox source
outlet - outlet of the box b1 from which to originate the connection
b2 - MaxBox dest
inlet - inlet of the box b2 to which the connection is terminated
color - int representing the color index of the patchline.

connect

public void connect(MaxBox b1,
                    int outlet,
                    MaxBox b2,
                    int inlet)
Connect a patch line from box b1 to box b2 with default color.

Parameters:
b1 - MaxBox source
outlet - outlet of the box b1 from which to originate the connection
b2 - MaxBox dest
inlet - inlet of the box b2 to which the connection is terminated

disconnect

public void disconnect(MaxBox b1,
                       int outlet,
                       MaxBox b2,
                       int inlet)
Disconnect a patch line from box b1 to box b2.

Parameters:
b1 - MaxBox source
outlet - outlet of the box b1 from which the connection originates
b2 - MaxBox dest
inlet - inlet of the box b2 to which the connection terminates

getWindow

public MaxWindow getWindow()
Returns:
the top level window containing this patcher.

getName

public java.lang.String getName()
Returns:
the name of the patcher.

isLocked

public boolean isLocked()
Returns:
true if this patcher is currently locked.

getParentMaxClass

public java.lang.String getParentMaxClass()
Returns:
the name of the parent max class for this patcher.

getOffset

public int[] getOffset()
Returns:
2 element int array containing the offset of the current display of this patcher.

getOrigin

public int[] getOrigin()
Returns:
two element int array representing the origin of the patcher

getCount

public int getCount()
Returns:
the number of boxes contained within this patcher.

getFilePath

public java.lang.String getFilePath()
Returns:
the file path of the file containing this patcher as a max style path.

setLocked

public void setLocked(boolean b)
Set whether or not this patcher is locked.

Parameters:
b - true to lock

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object