interface MaxBridge
Index
Methods
- bindInlet(message, callback)
- bindJitterImage(callback, opts)
- bindJitterMatrix(callback, opts)
- getDict(name, callback)
- getJitterMatrix(name, callback)
- outlet(initial, args)
- setDict(name, dict)
- setJitterMatrix(name, matrix)
bindInlet(message, callback)
Bind a Max message to JavaScript callback.
Use the spread operator to handle messages with a variable number of arguments.
bindInlet(
message: string,
callback: (...args: any[] | undefined) => void,
): void;
| Name | Type | Description |
|---|---|---|
| message | string | The first element of the message received from Max. |
| callback | (...args: any[] | undefined) => void | The function to call when a message is received on the inlet. |
Examples
window.max.bindInlet("hello", (name) => {
console.log("Hello, " + name + "!");
});
window.max.bindInlet("sum", (a, b) => {
console.log("Sum:", a + b);
});
window.max.bindInlet("variableArgs", (...args) => {
console.log("Received arguments:", args);
});
bindJitterImage(callback, opts)
Register a callback to receive streaming Jitter matrices as images.
The callback will receive any Jitter matrices sent to jweb with a jit_matrix message from Max, converted to images. Image data is pre-swizzled from Jitter's ARGB to RGBA, so it drops straight into a canvas or webgl context with no per-pixel work. These images are put into a queue as they are received, and sent to the callback asynchronously. The streaming options control how the queue is managed, including its size and the behavior when it overflows.
bindJitterImage(
callback: (image: JitterImage & StreamingMetadata) => void,
opts?: StreamingOptions,
): void;
| Name | Type | Description |
|---|---|---|
| callback | (image: JitterImage & StreamingMetadata) => void | The function to call when a Jitter image is received. |
| optional opts | StreamingOptions | Optional streaming queue configuration. |
Examples
window.max.bindJitterImage(
(image) => {
console.log("Received Jitter image");
console.log("Image width:", image.width);
console.log("Image height:", image.height);
console.log("Timestamp:", image.timestamp);
},
{ queue: 20, drop: "newest" },
);
window.max.bindJitterImage((image) => {
ctx.putImageData(new ImageData(image.data, image.width, image.height), 0, 0); // 2D
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
w,
h,
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
image.data,
); // WebGL
});
bindJitterMatrix(callback, opts)
Register a callback to receive streaming Jitter matrices from Max.
The callback will receive any matrices sent to jweb with a jit_matrix message from Max. These matrices are put into a queue as they are received, and sent to the callback asynchronously. The streaming options control how the queue is managed, including its size and the behavior when it overflows.
bindJitterMatrix(
callback: (matrix: JitterMatrix & StreamingMetadata) => void,
opts?: StreamingOptions,
): void;
| Name | Type | Description |
|---|---|---|
| callback | (matrix: JitterMatrix & StreamingMetadata) => void | The function to call when a Jitter matrix is received. |
| optional opts | StreamingOptions | Optional streaming queue configuration. |
Example
window.max.bindJitterMatrix(
(matrix) => {
console.log("Received Jitter matrix");
console.log("Matrix type:", matrix.type);
console.log("Matrix dimensions:", matrix.dim);
console.log("Timestamp:", matrix.timestamp);
},
{ queue: 20, drop: "newest" },
);
getDict(name, callback)
Retrieve a dictionary from Max by its name.
The callback will be invoked asynchronously with the retrieved dictionary once it is available. See asynchronous messaging for more details.
getDict(name: string, callback: (dict: MaxDict | undefined) => void): void;
| Name | Type | Description |
|---|---|---|
| name | string | The name of the dictionary to retrieve. |
| callback | (dict: MaxDict | undefined) => void | The function to call with the retrieved dictionary, or undefined if not found. |
Example
window.max.getDict("myDict", (dict) => {
if (dict) {
console.log("Retrieved dictionary:", dict);
} else {
console.log("Dictionary not found.");
}
});
getJitterMatrix(name, callback)
Retrieve a Jitter matrix from Max by its name.
The callback will be invoked asynchronously with the retrieved Jitter matrix once it is available. The returned matrix will be null if it could not be read, meaning the name isn't registered, it has no data, or it's a type the bridge doesn't support. See asynchronous messaging for more details.
getJitterMatrix(
name: string,
callback: (matrix: JitterMatrix | null) => void,
): void;
| Name | Type | Description |
|---|---|---|
| name | string | The name of the Jitter matrix to retrieve. |
| callback | (matrix: JitterMatrix | null) => void | The function to call with the retrieved Jitter matrix, or null if the matrix could not be read |
outlet(initial, args)
Send a message from JavaScript to Max through the outlet.
to output an array, use window.max.outlet.apply
outlet(
initial: number | string,
...args: (number | string)[] | undefined
): void;
| Name | Type | Description |
|---|---|---|
| initial | number | string | the message prefix to outlet |
| args | (number | string)[] | undefined |
Examples
// output a string
window.max.outlet("foo");
// output a list
window.max.outlet("foo", 1, 2);
// output contents of array with prepended "foo" message
let ar = [1, 2, 3, 4];
window.max.outlet.apply(window.max, ["foo"].concat(ar));
setDict(name, dict)
Set a dictionary in Max by its name.
There is no special function to update a single key. To update a dictionary, call getDict to retrieve it, modify the desired keys, and then call setDict to save the changes.
setDict(name: string, dict: MaxDict): void;
| Name | Type | Description |
|---|---|---|
| name | string | The name of the dictionary to set. |
| dict | MaxDict | The dictionary to set in Max. |
Examples
let myDict = { key1: "value1", key2: 42 };
window.max.setDict("myDict", myDict);
window.max.getDict("myDict", (dict) => {
if (dict) {
dict.key1 = "newValue";
window.max.setDict("myDict", dict);
}
});
setJitterMatrix(name, matrix)
Set a Jitter matrix in Max by its name.
Calls are main-frame only (not exposed in iframes).
setJitterMatrix(name: string, matrix: JitterMatrix): void;
| Name | Type | Description |
|---|---|---|
| name | string | The name of the Jitter matrix to set. |
| matrix | JitterMatrix | The Jitter matrix to set in Max. |
Example
window.max.setJitterMatrix("mybuf", {
type: "char", // "char" | "long" | "float32" | "float64" (default "char")
planecount: 4,
dim: [640, 480],
data: myUint8Array, // an ArrayBuffer of samples, matching the specified type. Here it should be a Uint8Array since the type is "char".
});