Stevebook - [ blog:communication_between_xul_and_osc ]

Communication between XUL and OSC

I've created an XPCOM component that acts as a bridge between JavaScript and the LibLo OSC library.

A XUL application communicating with PureData

This means that you can now create XUL applications that communicate with audio engines (such as PureData, in this example). You could use it to create a full-fledge audio application that manages resources over OSC (see Integra), or maybe just to enable you to take advantage of your HTML and SVG skills to create a nice front-end for a synthesizer built in Chuck or SuperCollider. I know that there are many people with greater web design skills than my own, so in the example application I haven't even tried.. :) I'll leave that up to people who know real kung fu.

Another possible use is that perhaps this could be integrated into a FireFox extension. You could install it on your local LAN and keep all your synth and controller interfaces on a server, making setting up clients for a distributed music system really easy.

Issues

At the moment it's somewhat limited, but it definitely works. Firstly, I had wanted to create a Windows and OS X binary before distributing this, but since I don't have time to work on that right now, I thought I may as well upload it as-is and see if anyone is interested in getting the ball rolling.

Secondly it doesn't support all of OSC. However, it does allow sending and receiving of floats, integers, and strings.

Details

It uses LibLo to create a server thread. When messages come in, they are announced on an Observer service. The XUL JavaScript registers an observer with the same service so that it can react to incoming messages. The threading stuff was a bit tricky and I may have added a few milliseconds of extra delay in order to transfer information from the server thread to the Mozilla thread, but I don't know if there's any getting around that. If anyone has good ideas on how this can be improved, I'm all ears. This is my first XPCOM component, so I'm far from being a Mozilla framework guru.

Download

As I said above, I haven't yet created Windows and OS X versions of this. It's been developed on Ubuntu Linux. This tar file contains the source as well as a shared object (.so) compiled on the latest 7.04 version of Ubuntu, Feisty Fawn.

Running

To compile and run it, you'll need to install the following packages:

apt-get install xulrunner firefox-dev

Type these commands in a terminal to get going:

tar -xvjf xpcom_osc-0.0.1.tar.bz2
xulrunner xpcom_osc/oscapp/application.ini &

To run the PureData patch:

pd xpcom_osc/test.pd &

Moving the slider in the XUL window, you should see the PureData slider also move. If you click the Start Listening button, you should see the XUL slider move when you drag the PureData number box. Take a look at the test.js file to see how this was set up.