MFL : Scene name search
I made this patch to perform keyword based search in the names of the scenes of a liveset and select the first scene containing that keyword. I came with something that seems to work but I'm pretty new to max and this live api stuff. If such a device can appeal to you, can you please test it and, for those who know this kind of stuff, can you please comment on mistakes or possible improvements. I struggled to make this one and would like to start on solid ground !
Thanks !
For now the search is case sensitive, is there a way to make that this is not the case ? (not sure about the english version for this...). [coll] maybe ?
New version btw...
Anyone ?
bump for the 'case sensitive' question at least...
New version 1.12 : http://www.maxforlive.com/library/device/1281
The case sensitive question is solved, btw.
Please comment patching.
Personally, I find iterating over Live API properties (tracks, scenes, devices, paramaters, etc) in Max like pulling teeth. I tend to go to javascript and use the LiveAPI js object in these cases.
The following patch will give you the 'scene indexes' (starting from 0) for all scenes with names containing the provided saerch string.
Save the following as 'sceneSearch.js':
autowatch = 1;
var api;
function getApi()
{
if (undefined === api) {
api =new LiveAPI();
}
return api;
}
function sceneSearch(searchString)
{
var api = getApi();
api.path = 'live_set';
var sceneCount = api.getcount('scenes');
var foundScenes = new Array();
for (var sceneIndex = 0; sceneIndex < sceneCount; sceneIndex++) {
api.path = 'live_set scenes ' + sceneIndex;
var sceneName = new String(api.get('name'));
if (-1 !== sceneName.toLowerCase().indexOf(searchString.toLowerCase())) {
foundScenes.push(sceneIndex);
}
}
if (0 === foundScenes.length) {
foundScenes.push('-');
}
outlet(0, foundScenes);
}
I am aware that this js doesn't do as thorough a search as your max implementation (e.g. no regex replacements of underscores/dashes into spaces), but I really wanted to demonstrate how much more succinct the API iteration side of things can be...
Thanks WillyC, This looks pretty concise ! But I don't know anything about Javascript. What should I do with these lines of code ? I tried to paste them in a text editor but it didn't let me save it with a .js extension.
There's a strange behaviour with this and I can't understand why : after making a search, if I copy / paste or duplicate scenes, the second time I do one of these actions, the device selects back the scene I previously searched. I looked at the patch but can't understand why. So I thought maybe this could be a bug in the api, even if I know I just start working with live.api. Can somenone please confirm this, and maybe tell me where this comes from ? You can DL it here : http://www.maxforlive.com/library/device.php?id=1281.