I apologize in advance for stupid questions, I'm really new to JS (in fact REALLY new...I've skimmed over stuff in the past, but now I'm building working scripts, so bear with me).
I started a new thread in the hopes that more js specific info will find its way here. The beginning of this thread really began here:
http://forum.ableton.com/viewtopic.php?f=35&t=128452
I figured out that you can assign global variables inside of functions without using the "var" prefix when making assignments (even though this is not really working as expected, either).
I am attempting to assign liveAPI variables inside of a function, so that the function can be called AFTER the Live API has instantiated itself. Loadbang() doesn't work. (Thanks, btw, to jayemell for some insight into a good way to deal with this, which I'm working on right now).
My current objective is to build a simple js to deal with the Launchpad's User2 controls. I've already accomplished this with the standard Max4Live objects, but I just can't leave well enough alone, and there a couple of things I see as being more advantageous in using js. I was able to build a script that worked last night, but it won't instantiate at load as it should, so I'm having to rethink some things. Not to mention the code is very cumbersome, I know there have to be some better ways to do this.
I have several questions, though. Right now, I have a constructor for each control on the launchpad, coupled with a callback for the same. In addition, I've built functions for each control to forward color values to the hardware. Again, cumbersome. I feel like there should be a way to call the variables containing the api_paths from outside the js, but haven't so far figured out how.
It looks like this:
Code: Select all
autowatch = 1
setinletassist(0, "grid input");
setoutletassist(0, "grid output");
cs = "0" // control_surface# to be replaced upon selection
function init()
{
_00 = new LiveAPI(this.patcher, return_00, "control_surfaces", cs, "controls", 2);
_00.property = "value";
}
function _00(val)
{
_00.call("send_value", val);
}
function return_00(v)
{
outlet(0, 0, 0, v.slice(-1));
}
Callbacks are working fine, but functions are not being called correctly, and I'm assuming this is because I'm assigning the control_surfaces / controls from inside a function.
I realize that it will require a static instance of each API path for every control I'm trying to access. But I'm trying to get around needing a seperate function for each one. Isn't there a way to reference the original API object after its constructed via an "init" from a variable inside another function? What I'd REALLY like to do is set up all the controls/callbacks and then use a function to route values to its appropriate destination, like:
Code: Select all
function sendvalue(control, value)
{
control.call("send_value", value);
}
Thanks for reading:) Collaboration/instruction/heavy reprimanding most welcome and eagerly anticipated. Like Eek the Cat says, "it never hurts to help!"
EDIT::
Is it possible to put LiveAPI contstructions inside an array? This would probably solve some of my problems....