Home > English, Tech stuff > Leopard’s Quartz Composer and Network events

Leopard’s Quartz Composer and Network events

November 25th, 2007

Back in the Tiger days, Quartz Composer had few support for network sources. The RSS feed patch was pretty much the only way we had to read data from the net, but it was way too limited (no streaming, not event based, not extendable, no input or output triggers).

I needed a way to get data from the Network in the form of events that I could reuse in a quartz composition. So our resident mac programmer coded this custom made patch based on sparse non official documentation found on the internet. And it worked great. We have about 5 plasma screens with mac minis over at work running it for months, no problems whatsoever.

Now Leopard comes along and QC had a major upgrade and I’m drooling, but ironically 1. Apple publishes an API to develop custom patches (which is good news) but 2. Our patch for Tiger doesn’t work anymore and needs a rewrite.

Then I found 2 patches in the new “Network” category: Network Broadcaster and Network Receiver. They are meant to connect several qtz compositions across the network and exchange messages between them. But maybe I can use them for something else…

I wrote a quartz composition to broadcast messages using UDP and multicast and started debugging and I discovered that the packets are really simple non-crippled text messages, four bytes per character iso-latin encoded chunks. So if you want to broadcast the message “Apple”, you’ll send this over UDP “\0\0\0A\0\0\0p\0\0\0p\0\0\0l\0\0\0e”

So I wrote a small php script (download) to broadcast messages:

#!/usr/bin/php -q

And a sample composition to test the concept. Download here and run it on Quartz Composer. After which just type:

$ ./broadcast.php "message number 1"
$ ./broadcast.php "message number 2"
...

And happily see them scroll up your screen.

This is just a proof of concept. I rewrote all my most complex compositions to use the Network Receiver patch and they all work fine. Using UDP over TCP is also an advantage because you don’t have to worry about the producer as the connection is stateless, and using a multicast group is great for broadcast scenarios (ie: multiple compositions on multiple computers consuming the same data).

Now imagine the possibilities and have loads of fun.

English, Tech stuff

  1. November 27th, 2007 at 09:21 | #1

    This works pretty nice!

  2. February 22nd, 2008 at 00:09 | #2

    That’s really cool

  3. Anonymous
    April 15th, 2008 at 19:21 | #3

    “four bytes per character iso-latin encoded chunk”

    If you need to send characters not in latin-1 you can just encode the string to utf-32be (big endian) and write the encoded bytes to the socket.

    I haven’t tried this extensively but it worked for the €uro sign.

  4. August 9th, 2008 at 05:55 | #4

    Many thanks for this – I’ll be looking at it to support multiple Mac minis on a network of information screens. Plus just playing with it. Great work!

  5. March 16th, 2009 at 00:05 | #5

    valeu pelo post, cara! ajudou bastante!

  1. No trackbacks yet.