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

Official support for: bitwig.com
outterback
KVRer
12 posts since 17 Oct, 2017

Post Thu Apr 18, 2019 1:15 am

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 1:36 pm, edited 1 time in total.

Karbon L. Forms
KVRian
1208 posts since 10 Jun, 2004 from Inverness, Scotland

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

Post Thu Apr 18, 2019 2:01 am

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
.................................

outterback
KVRer
12 posts since 17 Oct, 2017

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

Post Thu Apr 18, 2019 2:06 am

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.

Karbon L. Forms
KVRian
1208 posts since 10 Jun, 2004 from Inverness, Scotland

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

Post Thu Apr 18, 2019 2:13 am

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

C-quence
KVRist
122 posts since 27 Sep, 2004

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

Post Thu Apr 18, 2019 2:42 am

Impressive work!

outterback
KVRer
12 posts since 17 Oct, 2017

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

Post Fri Apr 19, 2019 1:07 pm

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

fwsuperhero
KVRist
327 posts since 26 Jul, 2012 from Prague, czech republic

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

Post Sun Apr 21, 2019 8:42 am

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 ;)

Krooked
KVRer
14 posts since 30 Apr, 2009

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

Post Sun Apr 21, 2019 1:01 pm

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:

outterback
KVRer
12 posts since 17 Oct, 2017

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

Post Mon Apr 22, 2019 5:07 am

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.

outterback
KVRer
12 posts since 17 Oct, 2017

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

Post Tue Apr 23, 2019 6:29 am

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 :)

Krooked
KVRer
14 posts since 30 Apr, 2009

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

Post Sat Apr 27, 2019 4:46 pm

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

Return to “Bitwig”