Page 1 of 1

Setting the currently selected track (javascript)

Posted: Thu Jul 22, 2010 11:08 pm
by Gravis
I've tried using the track id

Code: Select all

var track = new LiveAPI(this.patcher, "live_set tracks " + currentlySelectedTrackNumber);

var view = new LiveAPI(this.patcher, "live_set view");
view.set("selected_track", track.id);

I've tried using the track object itself

Code: Select all

var track = new LiveAPI(this.patcher, "live_set tracks " + currentlySelectedTrackNumber);

var view = new LiveAPI(this.patcher, "live_set view");
view.set("selected_track", track);
Clearly im missing something with this set method. Care to provide the missing link anyone?

Cheers

Re: Setting the currently selected track (javascript)

Posted: Fri Jul 23, 2010 4:13 am
by amounra93
You have to provide it with the tracks id. If you haven't already created the ids, I'd do it like this:

Code: Select all

api=new LiveAPI(this.patcher, "live_set");
track_selector=new LiveAPI(this.patcher, "live_set", "view");
api.goto("tracks", selected_track_number);
track_selector.set("selected_track", api.id);
I think that last bit will work (api.id)....I always forget how to do that exactly. But it will work, you may have to phrase it differently (e.g. api.get("id") or something). I'm pretty sure its correct how it stands, I just can't check it presently.

Cheers :)

Re: Setting the currently selected track (javascript)

Posted: Sun Jul 25, 2010 5:10 pm
by Gravis
When running your code i get an error ....

jsliveapi: set: no valid object id

:(

Any ideas?

Re: Setting the currently selected track (javascript)

Posted: Sun Jul 25, 2010 8:01 pm
by amounra93
Here you go. This will work as-is, just paste the code into a js and save it, then feed it a command "select_track n" from max.

Code: Select all

autowatch = 1;

api=new LiveAPI(this.patcher, "live_set");
track_selector=new LiveAPI(this.patcher, "live_set", "view");

function select_track(track_number)
{
    api.goto("live_set", "tracks", track_number);
    track_selector.set("selected_track", "id", api.id);
}
Cheers.

P.S. There is probably some more efficient way to do this with one API object, but I can't think of how. You CAN do it with one live.object and one live.path in Max.

Re: Setting the currently selected track (javascript)

Posted: Tue Jul 27, 2010 8:33 pm
by Gravis
That's working great amounra93

Cheers man!