TouchQlab

A python solution for bidirectional communication between TouchOSC and Qlab

This project is maintained by Drew Schmidt

Welcome to TouchQlab.

This is an application to work alongside QLab. It is written by a QLab evangelist, not by Figure53. Qlab's OSC response format is in JSON, not simple responses. This means when an application such as TouchOSC recieves a response from Qlab, it will be unable to parse the information and do anything intelligent with it. The purpose of this application is then to simplify and moderate the communication back and forth between Qlab and another OSC application; creating bidirectional communication.

Running and Customizing.

The first thing to note is that TouchQlab uses ports 54000 (Listen) and 54001 (Respond) for communication. This is meant to mirror Qlab's 53000 and 53001 ports.

Second, all device messages are sent to Qlab. Message are sent back to the device upon Qlab's "Update" reply (this occurs when anything is changed).

You'll of course need some device to converse with Qlab. I've uploaded an example of a TouchOSC layout I created. Feel free to adjust as necessary.

Currently, to run the code you'll need to open the script in IDLE and manually run the script. While you're there, feel free to visit the GitHub page or download the Zip and alter any code you want. Everything is written in python which can be edited via IDLE. After downloading the code you'll need to install one python library.

Open Applications/Utilities/Terminal and copy-paste each command one by one.

Install PyOSC

$ curl -O https://gitorious.org/pyosc/devel/archive/633c0112318a3519314aa798a552a092566c73c1.tar.gz
$ cd ~/Downloads/
$ open "633c0112318a3519314aa798a552a092566c73c1.tar.gz"
$ cd pyosc-devel
$ sudo python setup.py install
 * You'll need to enter your password here *
Edit Code

$ sudo IDLE
 * You'll need to enter your password here *
From here, you can open the python script (TouchQlab.py), alter, edit and run the code.

Functions - SendQlabMessage(message, values)

The script will detect open Qlab Workspaces and grab hold of the first one it detects. Once this is done you can use the SendQlabMessage function to send Qlab messages. Simply give it an OSC message and values. If you're unsure what OSC message Qlab will accept, visit Figure53's OSC API. Here are a few examples of sending


 #Send Qlab the GO command for the currently selected cue
SendQlabMessage("/go", None) 

 #Set the name of the currently selected cue
SendQlabMessage("/cue/selected/name", "Some New Name") 

 #Set the master fader of the currently selected cue to -20dB. Multiple values can be sent as a tuple
SendQlabMessage("/cue/selected/sliderLevel, (0, -20)) 

Functions - SendDeviceMessage(message, values)

After having found a Qlab Workspace, the script will listen for a device such as TouchOSC. To grab hold of the device IP, the script simply needs to hear a command, any command, then you can begin sending messages back to the device. Here are some examples


 #Display the name in the label with the address "/cue/selected/name"
SendDeviceMessage("/cue/selected/name", "Some New Name") 

 #Set the XY-Fader position. Multiple values can be sent as a tuple
SendQlabMessage("/cue/selected/translation", (15.4, -20))

Functions - Server_handler(addr, tags, data, source)

This is the handler that receives commands from the device (i.e. TouchOSC). Of course all this code is dependent upon what you're actually sending from your device. An application such as TouchOSC allows you define exactly what messages / addresses are being sent to Qlab. This can then assist in cleaning up some odd or unique messages. A few things to note ...

If your device address uses "{WorkspaceID}", that section will be replaced by the actual WorkspaceID that is being used.

Next there is a chunk for commands to be ignored such as the TouchOSC "/page" command which occurs when you change from one page of buttons to another.

The following section listens for value-less commands. These are often buttons which typically send two values, 1 for pressed, 0 for released; here messages with the value of 0 are ignored in order to prevent a "double tap".


This is by no means a comprehensive list of all the possible value-less commands Qlab will accept. To add another such as "/workspace/{id}/toggleFullScreen" simply add another chunk in the elif command.
elif (("/previous" in addr) or
            ("/toggleFullScreen" in addr) or
            ...
            ("/selected/stop" in addr)):

The subsequent sections are special case scenarios and simple pass throughs. Again, you can easily add code here to bridge the gap between Qlab and your specific setup.

Functions - Listener_handler(addr, tags, data, source)

This is the handler that sends commands back to your device. This is the portion that simplifies Qlab's response so that your device can understand the data being returned. Whenever an update occurs in Qlab, this script will request new data via the RequestValuesForKeys() method (found at the top of the script). The keys requested is by no means a comprehensive list. Feel free to add keys to this list as needed.

The reply is then divvied in the "/valuesForKeys" section of this function. The JSON code is decoded and parsed for each individual key. The value is then sent as a simple message back to the device. Add your own code as needed. A few things to note ...


 #Cast the value as a string which is sometimes necessary for labels
str(decodedJson['data']['{yourKey}'])

 #Python shorthand for converting a boolean value to a 0 / 1 numerical value
(1 if decodedJson['data']['{booleanKey}'] else 0)

 #These are addresses I added in TouchOSC to represent the display label for a slider or button.
SendDeviceMessage("/{whatever}/string", "Name")

 #This is a custom method to display a numerical time value as a time string that looks similar to Qlab's time string
SecondsToString(324.123)

You'll also notice that SliderLevels are in a seperate if-then block. This helps seperate the logic in the code. You'll also notice that the sliders only handle 0-8 (master and the first 8 sliders). There were performance issues where cues with audio levels would not update other basic information. Minimizing the sliders made for less traffic and fewer problems.

Support or Contact.

Remember, this code is provided for you as is. Occasionally we can add elements, features, or try to fix bugs. Please feel free to use the app, use the code, and adapt it for yourself and your own needs.