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

Add typings for argument childProps in Properties.children() #20

Open soimon opened 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 is a first attempt at typing the childProps argument in Properties.children().

live.song.children('tracks', ['name', 'current_monitoring_state']);
// The property array is typed and has autocompletion for all property names present on the raw entry

It even includes rudimentary autocompletion for nesting children:

({} as Track).children('clip_slots', ['has_stop_button', 'will_record_on_start']);
({} as Track).children('clip_slots', ['playing_status', {name:'clip', initialProps:['legato']}]);

I haven't managed to get autocompletion working when the nested child is an array type though:

({} as Song).children('tracks', ['has_midi_input', {name:'clip_slots', initialProps:[/* Nothing here unfortunately, as clip_slots is an array property */]}]);

Once this bug is ironed out of the type definitions, you should be able to recursively select anything you want in one query (as far as I could tell the js on the M4L side already supports nesting).

ricardomatias commented 1 year ago

I apologise for the overdue feedback, let me know if you have interest in updating the PR to the current state. I think this would be a great feature to add to the library.

soimon commented 12 months ago

I apologise for the overdue feedback, let me know if you have interest in updating the PR to the current state. I think this would be a great feature to add to the library.

No problem. I have completed the project that prompted my pull request streak, but I'll revisit this when I have the time again. In my last attempt, I reached the limit of my TypeScript typing ability. If that's still the case, I'll share the steps I'm struggling with to better clarify the issue.