Launch Ableton scene from Javascript

kmll's icon

Can anyone please advise what call I can make in javascript to launch a scene in Ableton Live. The path using the API i believe is e.g "live_set scenes 0" and then the function to call is "fire" but I am not sure how to put this in javascript syntax and it would be very good if anyone can advise.

Lee's icon

Hi, try this:

var lom_api = new LiveAPI( callback, 'path live_set scenes 0' );
lom_api.call( 'fire' );

kmll's icon

Thanks for the advise but I get the following error:
js: testapi.js: Javascript ReferenceError: callback is not defined, line 2

Lee's icon

Hi, you need to supply a callback function also. in this case, it doesn't need to do anything (unless you want to start doing things when the scene is launched)

function callback() {
}

kmll's icon

Thanks again but I still do not get it to work.. Now I get:
jsliveapi: set path: invalid path
jsliveapi: call fire: no valid object set

This is my code:

function bang(){
    var lom_api = new LiveAPI( callback, 'path live_set scenes 3' );
    lom_api.call( 'fire' );
}
    
    
function callback() {
}

Lee's icon

sorry, my bad, you don't need to 'path' in the string for js, just the 'live_set scenes 3') - get confused sometimes switching between the 2 :)

kmll's icon

Ah thanks - it works fine now? Just a quick quick question regarding the callback. I have seen in some other examples that "this.patcher" has been used instead of "callback". Do you know the difference?

Lee's icon

maybe that's a way of not having to specify a callback if you're not interested in it... that would be my guess

Lee's icon

Looking at the docs:

Legacy note: previous versions of the LiveAPI object required the jsthis object's this.patcher property as the first argument. For backward-compatibility, this first argument is still supported, but is no longer necessary.

So if you don't need a callback you can omit that parameter - I've just tested this and it works, but at one point this didn't work and you needed to pass 2 parameters in (maybe something broke and is now fixed)

kmll's icon

Ok great:) Good to get this verified. Thanks again Lee for very good help with this post!