Classes


Last modified: 2013-2-27

Class Patcher

Extends Maxobj.

The Patcher object is a Javascript representation of a Max patcher. You can find, create, modify, and iterate through objects within a patcher, send messages to a patcher that you would use with the thispatcher object, etc. There are currently three ways to get a Patcher:



Patcher in Cycling '74 Reference

Class Summary
Constructor Attributes Constructor Name and Description
<private>  
No constructor.
Field Summary
Field Attributes Field Name and Description
Maxobj get 
box
If the patcher is a subpatcher, the box property returns the Maxobj that contains it.
Number get 
Number of objects in the patcher
String get 
The patcher’s file path on disk
Maxobj get 
If the patcher contains objects, this is the first one in its list.
Boolean get 
The patcher's locked state.
String get 
Returns “patcher”
String get/set 
The patcher's name (its window title, without any brackets that appear for subpatchers)
String get 
Returns the Max class name of the parent object if this is a subpatcher, or a nil value if this is a top-level patcher.
Patcher get 
If the patcher is a subpatcher, this returns the parent patcher.
Array get/set 
X/Y coordinate array for the scroll offset of a patcher is window
Array get/set 
X/Y coordinate array for the patcher's fixed origin
Wind get 
A Javascript representation of the window associated with the patcher.
Fields borrowed from class Maxobj:
background, canhilite, colorindex, fontface, fontname, fontsize, hidden, hint, ignoreclick, js, nextobject, patcher, rect, selected, valid, varname
Method Summary
Method Attributes Method Name and Description
void 
apply(function)
For all objects in a patcher, calls the function with the each object's Maxobj as an argument.
void 
applydeep(function)
Same as apply() except that applydeep() recurses into subpatchers (depth first).
void 
applydeepif(action_function, test_function)
Same as applyif() except that applydeepif() recurses into subpatchers
void 
applyif(action_function, test_function)
For all objects in a patcher, run the test_function for each object's Maxobj as an argument.
void 
bringtofront(object)
Moves the object to the front of the current layer to which it is assigned (either background or foreground).
void 
connect(from_object, outlet, to_object, inlet)
Connects two objects (of type Maxobj) in a patcher.
void 
disconnect(from_object, outlet, to_object, inlet)
Disconnects an existing connection between two objects (of type Maxobj) in a patcher.
Maxobj 
getlogical(function)
Calls the function on each object in a patcher, passing it as a Maxobj argument to the function.
Maxobj 
getnamed(name)
Returns the first object found in a patcher with the given name.
void 
hiddenconnect(from_object, outlet, to_object, inlet)
Connects two objects (of type Maxobj) in a patcher with a hidden patch cord.
Maxobj 
newdefault(left, right, classname, additional)
Creates a new object of class classname in a patcher using the specified parameters and return a Maxobj (see below) that represents it.
Maxobj 
newobject(classname, params)
Creates a new object of Max class classname in a patcher using the specified parameters and returns a Maxobj (see below) that represents it.
void 
remove(object)
Removes the object (a Maxobj passed as an argument) from a patcher.
void 
sendtoback(object)
Moves the object to the back of the current layer to which it is assigned (either background or foreground).
Methods borrowed from class Maxobj:
annotation, color, help, message, notify, subpatcher, understands
Class Detail
<private>

Patcher

()
No constructor. The Patcher object is a Javascript representation of a Max patcher. You can find, create, modify, and iterate through objects within a patcher, send messages to a patcher that you would use with the thispatcher object, etc.

Any message to a patcher that you can send in Max (via the thispatcher object) you can send in Javascript in js.
Example:
// left, top, bottom, right: global screen coordinates
// of the Patcher window
var p = new Patcher(left,top,bottom,right);

// Uses 100,100,400,400 as default window coordinates.
p = new Patcher();

p = this.patcher;
// makes the patcher take up the whole screen
p.fullscreen(1);
// make an editable patcher dirty
p.dirty();
Field Detail
{Maxobj get}

box

If the patcher is a subpatcher, the box property returns the Maxobj that contains it. To traverse up to the top-level patcher:
Example:
var prev = 0;
var owner = this.patcher.box;
while (owner) {
	prev = owner;
	owner = owner.patcher.box;
}
if (prev)
	post("top patcher is",prev.patcher.name);

{Number get}

count

Number of objects in the patcher

{String get}

filepath

The patcher’s file path on disk

{Maxobj get}

firstobject

If the patcher contains objects, this is the first one in its list. You can iterate through all objects in a patcher using the nextobject property of a Maxobj.

{Boolean get}

locked

The patcher's locked state. This property is read-only in the runtime version of Max.
Default Value:
0

{String get}

maxclass

Returns “patcher”

{String get/set}

name

The patcher's name (its window title, without any brackets that appear for subpatchers)

{String get}

parentclass

Returns the Max class name of the parent object if this is a subpatcher, or a nil value if this is a top-level patcher.

{Patcher get}

parentpatcher

If the patcher is a subpatcher, this returns the parent patcher. Otherwise it returns a nil value.

{Array get/set}

scrolloffset

X/Y coordinate array for the scroll offset of a patcher is window

{Array get/set}

scrollorigin

X/Y coordinate array for the patcher's fixed origin

{Wind get}

wind

A Javascript representation of the window associated with the patcher. For more information, see the Wind Object.
Method Detail
{void}

apply

(function)
For all objects in a patcher, calls the function with the each object's Maxobj as an argument. Does not recurse into subpatchers. The following example prints the name of each object's class in the Max window:
Example:
function printobj(a) {
	post(a.maxclass);
	post();
	return true;
	// iterfun must return true to continue
	// iterating, else stops
}

this.patcher.apply(printobj);
Parameters:
{Function} function
 

{void}

applydeep

(function)
Same as apply() except that applydeep() recurses into subpatchers (depth first).
Example:
function printobj(a) {
	post(a.maxclass);
	post();
	return true;
	// iterfun must return true to continue
	// iterating, else stops
}

this.patcher.applydeep(printobj);
Parameters:
{Function} function
 

{void}

applydeepif

(action_function, test_function)
Same as applyif() except that applydeepif() recurses into subpatchers
Example:
//TODO
Parameters:
{Function} action_function
{Function} test_function
 

{void}

applyif

(action_function, test_function)
For all objects in a patcher, run the test_function for each object's Maxobj as an argument. If the test_function returns true, the action_function is executed with the Maxobj as an argument.
Example:
//TODO
Parameters:
{Function} action_function
{Function} test_function
 

{void}

bringtofront

(object)
Moves the object to the front of the current layer to which it is assigned (either background or foreground). You can change the layer by setting the background property of a Maxobj.
Example:
//TODO
Parameters:
{Maxobj} object
 

{void}

connect

(from_object, outlet, to_object, inlet)
Connects two objects (of type Maxobj) in a patcher. Indices for the outlet and inlet arguments start at 0 for the leftmost inlet or outlet.
Example:
p = this.patcher;
a = p.newobject("toggle",122,90,15,0);
b = p.newobject("toggle",122,140,15,0);

p.connect(a,0,b,0);
Parameters:
{Maxobj} from_object
{Integer} outlet
{Maxobj} to_object
{Integer} inlet
 

{void}

disconnect

(from_object, outlet, to_object, inlet)
Disconnects an existing connection between two objects (of type Maxobj) in a patcher. Indices for the outlet and inlet arguments start at 0 for the leftmost inlet or outlet.
Example:
p = this.patcher;
a = p.newobject("toggle",122,90,15,0);
b = p.newobject("toggle",122,140,15,0);
p.hiddenconnect(a,0,b,0);

p.disconnect(a,0,b,0);
Parameters:
{Maxobj} from_object
{Integer} outlet
{Maxobj} to_object
{Integer} inlet
 

{Maxobj}

getlogical

(function)
Calls the function on each object in a patcher, passing it as a Maxobj argument to the function. If the function returns true, the iteration stops and the Maxobj object is returned as the value of the getlogical() method. Otherwise getlogical() returns a nil value.
Example:
// search for an object with a negative left coordinate
function neg_left(a){
	r = a.rect;
	// rect is a property that returns an array
	if (r[0] < 0)
		return 1;
	else
		return 0;
}
e = patcher.getlogical(neg_left);
if (e)
	e.rect[0] = 0;
Parameters:
{Function} function
 

{Maxobj}

getnamed

(name)
Returns the first object found in a patcher with the given name. The name is a local name as specified by the Name... dialog in a patcher, not the name of a send or receive object. You can also set an object's name using the varname property of a Maxobj.
Example:
//TODO
Parameters:
{String} name
 

{void}

hiddenconnect

(from_object, outlet, to_object, inlet)
Connects two objects (of type Maxobj) in a patcher with a hidden patch cord. Arguments are the same as for the connect message above.
Example:
p = this.patcher;
a = p.newobject("toggle",122,90,15,0);
b = p.newobject("toggle",122,140,15,0);

p.hiddenconnect(a,0,b,0);
Parameters:
{Maxobj} from_object
{Integer} outlet
{Maxobj} to_object
{Integer} inlet
 

{Maxobj}

newdefault

(left, right, classname, additional)
Creates a new object of class classname in a patcher using the specified parameters and return a Maxobj (see below) that represents it.

The newdefault() method also accepts additional arguments for non-user interface objects that represent the created object’s typed-in arguments.
Example:
a = patcher.newdefault(122,90,"toggle");
//or
a = patcher.newdefault(122,115,"pack", "rgb", 255, 128, 64);
Parameters:
{Integer} left
{Interger} right
{String} classname
{mixed} additional
arguments
 

{Maxobj}

newobject

(classname, params)
Creates a new object of Max class classname in a patcher using the specified parameters and returns a Maxobj (see below) that represents it.
Example:
a = patcher.newobject("toggle",122,90,15,0);
Parameters:
{String} classname
{mixed} params
 
Returns:
Maxobj

{void}

remove

(object)
Removes the object (a Maxobj passed as an argument) from a patcher.
Example:
//TODO
Parameters:
{Maxobj} object
 

{void}

sendtoback

(object)
Moves the object to the back of the current layer to which it is assigned (either background or foreground). You can change the layer by setting the background property of a Maxobj.
Example:
//TODO
Parameters:
{Maxobj} object
 

©2012-2013
Max MSP Documentation copied to JsDoc by Tim Schenk SEO Frelancer Berlin. Some examples are by him. Some descriptions of classes, interfaces, properties, methods or events are by him. Until now, most of it is a copy. Published with permission of Cycling '74. This document might be wrong or incomplete. All informations without any warranty. All trademarks are the property of their respective owners. Documentation generated by JsDoc Toolkit on 2013-2-27