ricardomatias / ableton-live

A library for communicating with Live via WebSockets, works both in NodeJS and in the Browser.
https://ricardomatias.net/ableton-live/
79 stars 10 forks source link

Give access to the canonical path #19

Closed soimon closed 1 year ago

soimon commented 1 year ago

This is part of a set of pull requests aimed at reducing the amount of data being transmitted when using this (excellent 🙏) library extensively, often causing me timeouts in high performance situations. I've split my improvements in different features for your convenience, but I'd be happy to help combine them.

This PR adds a getter for the canonical path of retrieved objects:

track.path; // live_set tracks 4

This opens up the possibility to retrieve the index of an object, and query more effectively.

Example

This example uses my first PR #18 for adding a single child getter.

async function getClipSlotFromSelectedSceneOnTrack(trackName: string) {
    const selectedScene = await live.songView.children('selected_scene');
    const selectedSceneIndex = Number(selectedScene.path.split(' ').pop());
    const track = await findTrackByName(trackName);
    const clipSlot = track?.child('clip_slots', selectedSceneIndex);
    return clipSlot;
}
ricardomatias commented 1 year ago

Thanks for the PR @soimon. This is a good feature to add. The issue that I'm having is that the following code, always returns an undefined path. I couldn't find a working example for it:

const tracks = await live.song.children('tracks');
const track = tracks[0];
console.log(track.path);
soimon commented 1 year ago

Thanks for your quick response! Have you updated the amdx? I'm not sure how to cleanly update and commit the actual plugin, so I've only pushed the unfrozen live-api.js. When using my local copy this is the result:

const tracks = await live.song.children('tracks');
const track = tracks[0];
console.log(track?.path); // live_set tracks 0

If that's note the case, I might have missed some code when splitting my fork into pull requests. (Haven't been able to find anything though)

Andonvr commented 1 year ago

This is a good feature to have! As far as I can see, the path is needed to call functions.

ricardomatias commented 1 year ago

This is part of 0.0.10!

Thanks @soimon, I've added directly to the new release your changes based on your code for accessing the path. I've a footnote to the commit referencing your work, hope that's okay with you.

soimon commented 1 year ago

Totally fine! Glad to have it committed.