Setting the currently selected track (javascript)

Learn about building and using Max for Live devices.
Post Reply
Gravis
Posts: 104
Joined: Sat Jul 28, 2007 4:47 am

Setting the currently selected track (javascript)

Post by Gravis » Thu Jul 22, 2010 11:08 pm

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
iMac G5 2.16 | Echo AudioFire12 | Xone 92 | Live 8 + M4L | Trigger Finger | Monome 256 | Kenton Killamix Mini | Truth 3031A

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: Setting the currently selected track (javascript)

Post by amounra93 » Fri Jul 23, 2010 4:13 am

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 :)
http://www.aumhaa.com for Monomod and other m4l goodies.

Gravis
Posts: 104
Joined: Sat Jul 28, 2007 4:47 am

Re: Setting the currently selected track (javascript)

Post by Gravis » Sun Jul 25, 2010 5:10 pm

When running your code i get an error ....

jsliveapi: set: no valid object id

:(

Any ideas?
iMac G5 2.16 | Echo AudioFire12 | Xone 92 | Live 8 + M4L | Trigger Finger | Monome 256 | Kenton Killamix Mini | Truth 3031A

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: Setting the currently selected track (javascript)

Post by amounra93 » Sun Jul 25, 2010 8:01 pm

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.
http://www.aumhaa.com for Monomod and other m4l goodies.

Gravis
Posts: 104
Joined: Sat Jul 28, 2007 4:47 am

Re: Setting the currently selected track (javascript)

Post by Gravis » Tue Jul 27, 2010 8:33 pm

That's working great amounra93

Cheers man!
iMac G5 2.16 | Echo AudioFire12 | Xone 92 | Live 8 + M4L | Trigger Finger | Monome 256 | Kenton Killamix Mini | Truth 3031A

Post Reply