Long time, no see. I've written an awful lot of Javascript for Max For Live code since last I appear here, and a paper or two...
I have lots of utilities and little toys to show off in the next few weeks, including a Morse code generator and a generalized command mapper program... but I have some questions.
To start, I'd like to walk through the entire LOM tree and "print it out". But this reasonable task has run into many difficulties.
1. PROBLEM: the LOM it isn't a tree - in fact, there are cycles.
SOLUTION: The documentation warns you of this. Just keep track of which IDs you've seen already and don't recurse into them a second time.
2. PROBLEM: live.children is SNAFUED for objects that don't have children.
If you go to a path location that has an object of type 'list' or 'tuple', live.children is NOT empty - instead it's a two element array looking like ['No', 'children'] (!).
SOLUTION: (Hack) look at types and don't recurse into bad types.
3. PROBLEM: calling live.children consistently crashes Live for reproducible values of live.path.
Code: Select all
function run() {
var live = new LiveAPI(this.patcher);
live.path = [ 'this_device',
'canonical_parent',
'canonical_parent',
'master_track',
'mixer_device',
'cue_volume',
'canonical_parent',
'canonical_parent', // Doesn't crash if this line is commented out.
];
outlet(0, live.id);
for (var i = 0; i < live.children.length; ++i) {
outlet(0, live.children[i]);
}
};
The "canonical_parent" child seems a bit... dodgy anyway. I disallow following those children.
4. How do I find the list of parameters on an object? I don't see any form of reflection.
SOLUTION (proposed horror): keep massive tables from object type (e.g. DeviceParameter) to the parameters.
there must be a better way...?
5. How do I iterate through or index things that are of type "list" or "tuple" - like "control_surfaces"?
SOLUTION: ??
6. Many parameters I'd want to set seem to be read only...
What's the Javascript equivalent of live.remote?
Thanks in advance, great Max For Live gurus!