Reiteration of LiveApi.call() methods
Is it possible to store a LiveApi.replace_selected _notes function as an index in an array?
I'm looking for a way to call this around a 60 times without using a for loop.
(the iteration is too slow)
It's gotta fall within the other calls in the sequence and I'd like to be able to say pass in an array containing the calls when they need to be executed. Is something like this possible? if so could anybody point me in the right direction? Thanks!
i'm not familiar with the LiveApi, but JavaScript functions are first-class; in other words, yes, you can store them in an array.
You can also do closures and store those...
var myarray = [];
for(var i=0; i != somelength; i++) {
myarray.push(function(x) { myfunction(x, i); });
}
// later...
var somex;
var resultArray = myarray.map(function(f) { f(somex); });
Hey thanks for the response! I have been able to get normal functions to work but for some reason the call to set the notes isn't recognized when i pass in an array! :(
I keep getting the error "No operation in progress" When i try something such as this;
noteCall[0] = clipApi.call(noteArray);
with(clipApi){
call("replace_selected_notes");
call("notes",1);
noteCall[0];
call("done");
}
}
Anybody else have any idea how to approach this?
Again, I don't know much about Live, but your first line seems strange; don't you need to specify a function to call? I imagine that notearray
refers to an array, and not a function. Also, i think maybe you think that the first line is storing the function; it's not. It's storing the result.
Actually, your statement that "the iteration is too slow" is kind of strange. Unless the liveapi gives you access to some sort of parallelization engine, doing something 60 times should take about the same amount of time in a for loop as any other way.
editClip = new LiveAPI(this.patcher, null, "live_set tracks " + track + " clip_slots " + scene + " clip");
// Typecasting? In javascript? Yessert!
Array.prototype.noteToLiveAPI = function () {
var timeNumber = Number(this[2]);
this[2] = timeNumber.toFixed(3);
var durationNumber = Number(this[3]);
this[3] = durationNumber.toFixed(3);
return this;
};
function addNote(addNum, addTime, addVelocity) {
// simply adds one note - no need to get and replace every note.
var tempNoteArray = ["note", addNum, addTime, 0.0625, addVelocity, 0];
var newLength = noteArray.length + 1;
editClip.call("deselect_all_notes"); // CALL
editClip.call("replace_selected_notes"); // CALL
editClip.call("notes", 1); // CALL
editClip.call(tempNoteArray.noteToLiveAPI()); // CALL
editClip.call("done"); // CALL
}
D:
i thought my edit went through. sigh. i the point i was trying to make is that they should run pretty much the same. with or without the call "cached" to an array...
well, what do you need to do 60 times? are you using the same LiveAPI object? is that object observing anything? what are you trying to accomplish overall?
Hi there!
Sorry I've been offline for awhile tangled up in another non Max related project.
Anyway, What I am trying to do is instantly create up to 60 notes with one operation.
I am looking for a short way to accomplish this:
function list(args){
args = arrayfromargs(arguments);
with(clipApi){
call("replace_selected_notes");
call("notes",32);
call("note", args[0],args[1],0.125,100,0);
call("note", args[2],args[3],0.125,100,0);
call("note", args[4],args[5],0.125,0,0);
call("note", args[6],args[7],0.125,0,0);
call("note", args[8],args[9],0.125,100,0);
call("note", args[10],args[11],0.125,100,0);
call("note", args[12],args[13],0.125,100,0);
call("note", args[14],args[15],0.125,100,0);}
etc...variable amount up to 60
without having to type in all of the calls. Some way to store the number of note calls and parameters I will need and call them all at once rather than using a for loop because the for loop will put them in one after the other.
like this:
for(i=0;i
call("replace_selected_notes");
call("notes",1);
call("note", args[0],args[1],0.125,100,0);}
Happens one at a time.
I hope this makes sense. I am only using one API object and it is not observing anything. Should it be?
Thanks for you time on this matter!
Either way you are making the calls one at a time. This is the nature of both our JS object and the Live API.
I would bet the for loop is faster.
-A