I am stuck trying to write a Max4Live patch which listens to ControlSurface components in the Live Object Model, specifically ButtonElement and ButtonMatrixElement.
I am using the 'js' object to run some JavaScript code which creates LiveAPI objects on those elements to observe their "value" property, similarly to how it is described in https://cycling74.com/forums/topic/how- ... 7zJlpN96Rt
Code: Select all
function test() {
var api = new LiveAPI(sample_callback, "control_surfaces 1");
if (!api) {
post("no api object\n");
return;
}
post("api.mode", api.mode ? "follows path" : "follows object", "\n");
post("api.id is", api.id, "\n");
post("api.path is", api.path, "\n");
post("api.children are", api.children, "\n");
post("api.getcount(\"controls\")", api.getcount("controls"), "\n");
post("Iterating over control list\n");
var length = api.getcount("controls");
for(var i=0; i<length; i++){
api.path = "control_surfaces 1 controls " + i;
post("api.id is", api.id, "\n");
post("object name is", api.get("name"), "\n");
post("api.type is", api.type, "\n");
post("api.children are", api.children, "\n");
// Find objects by name
var name = api.get("name");
// Find the button matrix element
if(name == "Button_Matrix"){
post("Found Button Matrix\n");
var matrixListener = new LiveAPI(matrixListenerCallback);
matrixListener.path = api.path;
matrixListener.property = "value";
}
// Find a single button
if(name == "7_Clip_7_Button"){
post("Found Button 7_Clip_7\n");
post("Button's api.type is", api.type, "\n");
var buttonListener = new LiveAPI(buttonListenerCallback);
buttonListener.path = api.path;
buttonListener.property = "value";
}
}
}
function sample_callback(args) {
// nothing
}
function matrixListenerCallback(args){
post("matrixListenerCallback:", args, "\n");
}
function buttonListenerCallback(args){
post("buttonListenerCallback:", args, "\n");
}
// Called on bang message being received
function bang() {
post("Initial bang()\n");
test();
}
When a bang message is sent to the js object running the script it successfully retrieves the objects, and creates LiveAPI instances whose callback triggers with the initial bang as the value. The Max Console shows the following:
Code: Select all
js: api.id is -90
js: object name is 7_Clip_7_Button
js: api.type is ButtonElement
js: api.children are canonical_parent
js: Found Button 7_Clip_7
js: Button's api.type is ButtonElement
js: buttonListenerCallback: id -90
js: buttonListenerCallback: value bang
js: call send_value( 0 ) id 0
js: api.id is -91
js: object name is Button_Matrix
js: api.type is ButtonMatrixElement
js: api.children are canonical_parent
js: Found Button Matrix
js: call height result is 8
js: matrixListenerCallback: id -91
js: matrixListenerCallback: value bang
Am I observing the wrong property?
What is the correct way to listen to control surface elements in max4live?
Thanks a lot for your help!
/Mario