[PD] Writing OSC applications in XUL

Stephen Sinclair radarsat1 at gmail.com
Sun Apr 29 17:07:10 CEST 2007


> Sorry for being a tad green.  Andre Schmidt has made some SVG GUI
> examples <http://osku.de/svg/gui-examples/>. Say one would like to
> use such GUI's to - via OSC - control things in a Pd patch running
> on, say, localhost. What is the obvius next step?
>
> My intuition doesn't ask for a Firefox extension, but rather some
> Java Script that can send the OSC messages to Pd. Any pointers would
> be nice.

Well, that's just the problem.  There is no way to send UDP messages
from JavaScript just like that.  (As far as I know..)

So I wrote an XPCOM component which JavaScript can talk to as per my
example.  The XPCOM component is written in C++ and uses LibLo to send
and receive OSC.

So say you wanted to get these SVG examples working with OSC.  (Thanks
for the link by the way!!)

The way my example works is that it is a XULrunner app (basically the
firefox back-end), and it has a file called "oscapp.xul".  This file
tells it what the interface should look like.  i.e., open a window and
put a browser in it.  In the <browser> tag there is an attribute which
tells it to load the file "test.xhtml" into the browser.  You could,
for example, change this to point to your SVG files.  Alternatively,
have test.xhtml include your SVG files and arrange them on the page.

Then do the same thing I did in test.xhtml -- link to a JavaScript
file, test.js, and create a function which instantiates the XPCOM
component, called OpenSoundControl, and use it to send a message.

Take a look at "test.js" for an example of how to do it.  I make no
claims that my object has the best possible API, but it works.

The advantage of doing it this way over using a PHP or Python back-end
is that it doesn't require running apache or communicating with it
using HTTP, which probably introduces unwanted latency.  The
application just sends and receives OSC directly.  (However, if you
find writing a server back-end easier and more familiar, I say go for
it!)


Cheers,
Steve




More information about the Pd-list mailing list