class Max

Singleton Max object, controlling the Max environment.

Use the singleton instance of this object to control the Max environment. In the context of JavaScript executed in Max, the global Max singleton is always bound to an object named max.

Example 1

var arch = max.arch;
// The max object is already bound to the singleton Max object

post(arch);
// Prints the architecture of the current Max application.

In addition to the properties and methods described here, you can also use the global Max object to call methods as defined in Controlling Max with Messages.

Example 2

// Message box contents:
; max preempt 1

// JavaScript equivalent:
max.preempt(1);

Properties

apppath string read-only

The pathname of the Max application

arch "arm64" | "x86" | "x64" read-only

The architecture of the Max application

cmdkeydown number read-only

Command key state

1 if the command (Macintosh) or control (Windows) key is currently held down.

ctrlkeydown number read-only

Control key state

1 if the control key is currently held down.

frontpatcher Patcher read-only

The Patcher object of the frontmost patcher window

The Patcher object of the frontmost patcher window, or a nil value if no patcher window is visible. You can traverse the list of open patcher windows with the next property of a Wind object.

isplugin number read-only

Whether the js object is in a plugin

Will be 1 if the js object is in a plugin, and 0 otherwise. This will generally only be 1 if the js object is loaded as a Max device in a Max vst~ object.

isruntime number read-only

True if the current Max environment does not allow editing.

Returns 1 if the currently executing Max application environment does not allow editing, 0 if it does.

loadbangdisabled number read-only

True if the user disabled loadbang.

1 if the user has disabled loadbang for the currently loading patch. If your object implements a loadbang method, it can test this property and choose to do nothing if it is true.

mainthread number read-only

Whether the current code is executing on the main thread.

Returns 1 if the current code is executing on the main thread, 0 otherwise.

optionkeydown number read-only

Option/alt key state

1 if the option (Macintosh) or alt (Windows) key is currently held down

os string read-only

The name of the operating system

The name of the platform (e.g., “windows” or “macintosh”)

osversion string read-only

The current OS version number

shiftkeydown number read-only

Shift key state

1 if the shift key is currently held down

time number read-only

Current scheduler time in milliseconds.

Will be a floating point value.

version string read-only

Max application version number

Will be in string form, like "835"

Methods

getattr

Get the value of the named attribute

getattr(name: string): number | string | any[];
NameTypeDescription
namestringthe name of the attribute to retrieve
Return Valuenumber | string | any[]the value of the attribute, as an array if the attribute value is a list

getattrnames

Available attributes of the Max global object

getattrnames(): string[];
NameTypeDescription
Return Valuestring[]the available attributes

getcolor

Get the value of the named color in the current theme

getcolor(name: string): [number, number, number, number];
NameTypeDescription
namestringthe name of the color to retrieve
Return Value[number, number, number, number]the RGBA color as an array of four numbers between 0. and 1.

getrefdict

Get a Dict containing the reference page information for the named Max class

getrefdict(classname: string): Dict;
NameTypeDescription
classnamestringthe name of the Max class
Return ValueDicta Dict containing reference page information

message

Send a message to the Max global object

message(name: string, ...args: any[]): any;
NameTypeDescription
namestringthe message name
argsany[]arguments to the message
Return Valueany

setattr

Set the value of the named attribute

setattr(name: string, value: any): void;
NameTypeDescription
namestringthe name of the attribute to set
valueanythe value of the attribute to set

setcolor

Set the value of the named color

This method is only available in the new v8 javascript engine objects.

setcolor(name: string, ...args: number[]): void;
NameTypeDescription
namestringthe name of the color to set
argsnumber[]the RGBA color values