javascript equivalent to the python _framework classes in M4L?

sysex's icon

In my recent project I built in JS via the LveAPI a companion for a control surface script which runs with the Ableton Python interpreter - mostly to send OSC stuff to a lemur template. I found myself writing functionality which one can find mostly in the _Framework classes, too. I'd like to stay in JS / M4L - for me its much easier to develop this way and I can setup a UI so on.

Is there anything like a port of the _Framework to JS for M4L?

I know that one cannot draw a session rectangle on the session view - but maybe 90% of the python API can be done with JS in M4L - I thought I'd better ask before starting something on my own.

I'm curios if I missed some JS-repo and in general I'd like to know your thoughts on this :-)

Iain Duncan's icon

Personally, I had a lot of success with the Python approach, what is it about that approach that is not working for you? I may be able to help there. I've not done M4L in JS because the JS object is not nearly as nice to me as Python. But that may be just my taste! :-)

sysex's icon

I find the Python API interesting for the following aspects:
1) There are already the _framework classes and you don't have to invent it yourself
2) The Midi interface is without the dreaded Ableton limitations - some controllers I can get to work via M4L and the Midi from the Ableton tracks - it just won't work
3) The JS LiveAPI implementation is weird. Sometimes strange things happen, listeners for certain properties can't be removed and overall the API is just not cool to use

Disadvantages compared to the JS LiveAPI
1) You can't create a user interface, at most hacks where e.g. like ClyphX a special syntax of track names is used as input for a Python-Scrypt
2) Connection to Max world only via LiveAPI by querying for the constrol surface and calling the function of interest

Disadvantages on both:
1) no debugging :-(
2) no testing unless one mocks the API relevant interfaces

in respect of mocking and testing would be also interesting if one has already wrote a stub library of the JS LiveApi or the Python-Api.

In the meantime the Python-Ableton-development-cycle has improved a little bit, because the Python scripts are reinterpreted when the project is reloaded, so that you can quickly test with CMD+n if a change has worked
I must admit that this was one of the worst reasons why I decided to quit using python scripts.

Before Max 7 I used only python because at this time "require" was not supported in MAX's JS implementation and one has to write everyting in a big fat JS-File which was a desaster LOL

I am curious . how do you develop with python scripts ? Do you import the decompiled _Framework classes in order to have better IDE support. But it all still comes down to debugging by reading Live log isn't it? Do you write unit tests for your Live python code?

Iain Duncan's icon

Hi, it's been a few years to be honest, these days I'm working on a new project to do my scripting in Scheme, but I haven't started adding M4L to it yet. I found sources online somewhere to allow getting into pdb from a network repl, and that was how I did my development, just loading the scripts in ableton and making about in pdb to explore the object model. It was definitely hacky, I wish Ableton officially supported it. But as far as how well it worked, it was great. I was able to make totally custom behaviour for my launchpads that made for really good workflows on how I wanted clip activation to work.

sysex's icon

Yeah maybe I will go back sometime but at the moment I am ambitious and I want to finish it in JS. Unfortunately I'm currently annoyed by transitive "require" dependencies which are not resolved in Node, because I'd like to write some unit tests in NodeJS.

To get back to the actual topic, it's unexpected that nobody has ported the _framework classes yet .

Gene Pool's icon

Is there any guide on developing with a Python control scripts? I've seen the Live Object Model, and the decompiled default scripts. I'm yet to find a guide: how to set up a development environment, how to use the framework classes etc. It all seems voodoo.

sysex's icon

Hey :-) I'd say don't expect too much - Ableton does not support it officially and its all a bit hacky ;-) I'd suggest to start a new Thread regarding the Python-API? I'd join it. Here in this one I wanted to find out if one made the JS port of it because the _Framework Classes are well designed and since they are decompiled and JS covers maybe 90% of the Python functionality this would be an option to use them as draft fo the JS implementation.

Iain Duncan's icon

I found some unofficial sites online with good tips, and there's a collection around the net of reversed live control surfaces that are really helpful (as in, reversed from python bytecode to python).

Gene Pool's icon

Sysex: I'd love it if Ableton exposed a native JS API. A control script execution model and/or a device model like M4L. People seem to be jumping through all sorts of hoops to get it. Eg via Python -> OSC -> JS api, via M4L -> Node.js, via M4L -> js.

Iain: I've come across similar. This blog seemed to be the best resource, but is now 10 years old.

sysex's icon

@GENE POOL I also think it would be great if there was a library with sources in Python, too. Python is not necessarily my favorite language, but the current API just feels better compared to the JS implementation. Unfortunately as usual users we don't get a debug port or anything like that and we can only write tests with a lot of effort and the development process consists of re-loading the liveset and parsing the log.txt.

But in the end it is up to me/you and the creativity what you do with the problem and how much energy you invest. In my case, I have musical topics too :-D activities besides these meta-musical ones, but I have been annoyed too often on the other hand :-P Currently I use Python and the JS-API together.
I use a custom Python script but only for normal session tasks - but also for everything possible as I find the Python-Implementation much quicker. Then I use certain functions of the script via the LiveAPI or get one or the other controller. For example, I am currently doing all OSC communication via Max.

I finde this is a good resource for the JS LiveAPI:
http://compusition.com/writings/js-live-api

This is an interesting inspiration Python-wise:
http://stc.wiffbi.com/

There are Python scripts that demonstrate many functions. Otherwise you can find here for example the decompiled remote script classes here:

there the Push ones are a good read too.
Stray from nativeKontrol is also a great source of information in respect of Abelton-Scripting.

How well do you know about IDEs? You could put the decompiled scripts in the path and depending on the IDE you will get code assist until a certain point. In case of JS WebStorm is fun to use.
I'd love to have a officially supported API, with an option to run Ableton Live headless. The Source-Files would be also nice and the ability to debug. That would be awesome!

Thibault Lebrun's icon

Hi, just saw this few months old thread and wanted to share my workflow with ableton API coding.

It doesn't look like there is a lot of documentation on Control Surface Scripting which seems a bit like a dark art haha. Stray's Clyphx, youtube videos and posts on forum are invaluable for a start.
I actually discovered recently clyphx pro and I think it's a sweet way to enter scripting. The documentation helps showing what's possible to do with Live

I've done a bunch of user actions and you can get quite far with them without needing to write complex object oriented and "decorated" code like in real control surface scripts. I need to say I'm not at all attracted by max or js code when python is so powerful and nice. Maybe my use case is too simple that I don't encounter midi / communication problems with python.

Like SYSEX I'm doing development in an IDE (Pycharm is rock solid) with decompyled scripts in the path so that I have some autocompletion and also "documentation" with ctrl-shift-f. You can also import functions from other surface scripts that's cool.
Having a light set that you can reload fast is tolerable, and of course debugging is done via the debug file.

I'm still working on my code but I didn't have so much trouble writing simple tests with pytest. Well I guess there is a better way but I ended up creating a __ini__.py file somewhere I needed it and cleaning after. Also doing sys.path.insert. Now I've started doing "import Live" in my scripts and everything is broken lol.

JulienBayle uncompyled code and documentation are great.

I guess now that I leant the basics of python ableton scripting I'll try to create surface scripts instead of doing it through clyphx.

I certainly back SYSEX on his last paragraph ! An Ableton Live headless for testing would be awesome as well as source files of the API.