Experiment - Bitwig Studio 2.5 Python REPL, automation, and global scriptable hotkey

Official support for: bitwig.com
Post Reply New Topic
RELATED
PRODUCTS

Post

Hi!

edit: Github link: https://github.com/outterback/bitwig-python-bridge

Cutting to the chase, video demo

I've been interested in automatic music generation for a while, and I had the idea of trying to do it with Bitwig Studio. I've put together a demo that makes the BWS Java API accessible from Python. You might wonder why, but I'm more in the camp of why not. I thought it was a shame that the API is only accessible via MIDI controllers, and wanted to actually use it for programming, without creating a virtual MIDI interface, or doing it in a needlessly complicated way (you may argue that this is still needlessly complicated :p).

The code for this project pretty short, and uses the library Py4j, that opens a gateway between Java and Python. The Py4j library is bundled inside the controller extension, which makes it accessible to Bitwig at runtime.

Some things this enables:

* Python REPL access to the Bitwig Studio API. Tinker, automate, explore, and play with BWS API functions from your python console
* Automation. I'm demonstrating some automated functions in the video below, namely adding a major scale, minor scale, and a MIDI panic function. I've added access to cursors for Track, Clip, Remote Controls, and Device, so they are all controllable from the Python interpreter.
* Global hotkeys extending the default Bitwig ones. This uses the python package keyboard. This package unfortunately requires sudo on linux, but doesn't seem to need it on Windows. This is kind of a red flag for me, and I don't want to condone using it before I've checked it out fully, but it works as a proof of concept.
* I'd like to say that anything you can do in the API, you can do from Python, but I don't want to make that promise. It sure seems like it though.

Some things that are kind of iffy:

* Code runs too fast - Bitwig might not have time to respond to everything being sent, so I'm experimenting a bit with sleep timers. Need to work more on this.
* Method introspection - running

Code: Select all

dir(track)
or

Code: Select all

track?
in the IPython console displays the member functions of the cursor, which enables completion. This doesn't seem to work for the Clip object, and I'm not sure why right now.

Python displaying information about the track object:

Image


I'll publish the code later tonight :)
Last edited by outterback on Fri Apr 19, 2019 9:36 pm, edited 1 time in total.

Post

I use mido and keyboard Python packages to do a controllerless controller and custom commands. Well done with the full python bridge dude. Too much like hard work for me, all that. lol. I like to keep things hideously simple. A REPL might be useful though.
.................................
"Hell is other People" J.P.Sartre
.................................

Post

Thanks! The code for the controller extension took an entire 2 hours or something to write. This all is stupidly simple, the hardest part to be honest was figuring out how to bundle the library via Maven, but I hate build tools and they hate me so there's that :) In this implementation, you don't need to bind specific midi commands to specific functionality in the API. You have direct access to the API from Python.

Post

I'll certainly have a look when you release bud. I run screaming from Java/Maven myself.
.................................
"Hell is other People" J.P.Sartre
.................................

Post

Impressive work!

Post

Thank you!

I was going to do it yesterday, but I ended up playing computer games until 2 am. I've done some rework on it and uploaded it to Github now anyway, along with a readme.

You can find it all here: https://github.com/outterback/bitwig-python-bridge

Post

Wow, you are crazy for somebody who knows python very well but is not fluent with any static typed languages like Java or obscures, multi-paradigm & multi-image langs like js ;)

Post

This looks exciting! Been hoping for somebody to tackle a ClyphX-esque approach, and this looks like a good foundation for device snapshots :)
Hope to see more stuff from you in the future within the Bitwig realm. :clap:

Post

I cooked together some basic ClyphX like behavior, it seems to work pretty well but it's not optimal to do it in Python. It'd probably be easier to manage it on the Java side, but creating custom functions is dead simple in Python.

Check it out:

https://youtu.be/5VwSe2KoFcw

This is absolutely a good platform for device snapshots and triggering recall of them though.

Post

Today's silly experiment with this stuff:

Per step sequencing with a midi controller, non-intrusively. Via some nifty midi loopback, I can use any controller that's added to bitwig and get the midi data to my program. Here it's used for per step sequencing. Every time a note is registered, it inserts the note and steps forward a preset length. I could make this work with chords too I think.

One day I might make something finished and useful, but I'm just exploring what can be done right now :)

Post

you are definitely onto something that a lot of people have been wanting :D good job!

Post Reply

Return to “Bitwig”