leolabs/ableton-js

Listen to master output level

patryk-kawalarz opened this issue · 19 comments

Can your framework check the actual master volume level? But not the fader lever but real-time output level.
I want to create some simple visualization app.

That's possible. You can get the master volume like this:

const ab = new Ableton();
const master = await ab.song.get("master_track");
master.addListener("output_meter_level", console.log);

It does seem, however, that Ableton has some problems outputting a constant stream of values. I'm not sure yet if that's a problem with Ableton.js' Python script or Ableton itself. Please do report back if this works well for you :)

Thank you for your prompt reply! I will check it out today :)

Ok, it works. I get the actual value of master track. Unfortunately, the data does not refresh often enough to create real-time visualizations.

Do you also get some values all at once and then no values for about half a second?

Screen Recording 2020-03-02 at 11 10 18 PM

Yep, I had the same.

I think I found a solution. Ableton's output_meter_level listener seems to be a bit broken, but listening to output_meter_left and/or output_meter_right seems to work fine:

Screen Recording 2020-03-03 at 1 46 12 PM

:O Whoa, looks like a huge number of values per second! That's what I needed! Will check it tomorrow :) Btw. do you have sometimes timeout errors while connecting to Ableton?

I haven't experienced any errors yet in my setup. When Ableton.js connects to the Python script, it requests the current song time as a kind of check if the connection really exists. If that request takes longer than 2 seconds to respond, the connection will fail.

Could you elaborate more on what your setup looks like? Which OS do you use and when do you get those timeouts?

This is the error I often get when I try to restart node app:

(node:14148) UnhandledPromiseRejectionWarning: Error: Timeout at Timeout._onTimeout (D:\Music data\Dropbox\Workspace\visual\node_modules\ableton-js\index.js:163:77)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
(node:14148) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14148) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Hmm, that's weird. It might be due to the midi script in Ableton not being able to receive or send messages on the specified ports. Some Native Instruments apps use the same ports for example. I've updated the default ports in v1.7.0 and improved the timeout errors in v1.7.2. Could you update your ableton-js and the midi script to the latest version and report on whether it works better for you now?

Hello. Now it doesn't work at all. Windows 10 here.

(node:24724) UnhandledPromiseRejectionWarning: Error: The command internal.get_prop({"prop":"version"}) timed out after 2000 ms
at Timeout._onTimeout (D:\Music data\Dropbox\Workspace\visual\node_modules\ableton-js\index.js:175:33)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
(node:24724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:24724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:24724) UnhandledPromiseRejectionWarning: Error: The command song.get_prop({"prop":"master_track"}) timed out after 2000 ms
at Timeout._onTimeout (D:\Music data\Dropbox\Workspace\visual\node_modules\ableton-js\index.js:175:33)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
(node:24724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

Have you updated both the js library and the Python midi script?

The error "Error: Timeout at Timeout._onTimeout" can be caused because the Python script has encountered an error whilst running inside Ableton. It doesn't respond to Node and Node proclaims a timeout error.

Normally, every error encountered in the midi script should be sent back to the JS library. But I've improved the error message by adding some troubleshooting tips in v1.8.1. @patryk-kawalarz please report back if it works for you :)

You were right, I forgot to update python files :O I will check everything again as soon as I find a moment (which is very difficult lately).

One thing I know for sure - output_meter_left works like a charm :)

Thank you for your commitment! :)

Awesome! You're welcome, and I'm glad that it's useful to you :)
I'll close this issue for now, but feel free to reopen it or open a new one when you run into any problems.

Im very sorry that Im back again.. but is there any way to access any sort of frequency data from the master channel? Or any other data that could help with creating a visualizer other than the master_output_left/right. My understanding after reading the docs you have linked would be that there is not. Is that correct? Any information is appreciated, thank you.

No worries, I'm always happy to help :)

I don't think that Ableton exposes any sort of frequency data through their Python API. Maybe you can try using a M4L Audio Effect as that has access to the raw audio data and can extract frequency information.

Ahh okay. Thank you I will definitely look into it! For now the output_left/right will work just fine. Thanks again for an awesome library!